Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-14275: The distortion in test_wcsUtils.py testDistortion is unreasonable #350

Merged
merged 2 commits into from
May 2, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 17 additions & 20 deletions tests/test_wcsUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def setUp(self):
self.scale = 1.0 * arcseconds
# position of 0,0 pixel position in focal plane
self.ccdPositionMm = afwGeom.Point2D(25.0, 10.0)
self.focalPlaneToPixel = self.makeAffineTransform(
self.pixelToFocalPlane = self.makeAffineTransform(
offset=afwGeom.Extent2D(self.ccdPositionMm),
rotation=self.ccdOrientation,
scale=self.pixelSizeMm,
Expand Down Expand Up @@ -99,25 +99,27 @@ def testNoDistortion(self):
focalPlaneToFieldAngle = self.makeAffineTransform(scale=self.radPerMm)
wcs = makeDistortedTanWcs(
tanWcs=self.tanWcs,
pixelToFocalPlane=self.focalPlaneToPixel.getInverse(),
pixelToFocalPlane=self.pixelToFocalPlane,
focalPlaneToFieldAngle=focalPlaneToFieldAngle,
)
self.assertWcsAlmostEqualOverBBox(wcs, self.tanWcs, bbox=self.bbox)

def testDistortion(self):
"""Test makeDistortedTanWcs using a non-affine transform for pixelToFocalPlane
"""
# Compute a distorted wcs that matches self.tanWcs at the center
# of the field
focalPlaneToFieldAngle = afwGeom.makeRadialTransform([0.0, self.radPerMm, 0.0, self.radPerMm])
# Compute a distorted wcs that matches self.tanWcs at the center of the field;
# the amount of distortion is 10s of pixels over the detector
fieldAngleToFocalPlane = afwGeom.makeRadialTransform([0.0, 1/self.radPerMm, 0.0, 1000/self.radPerMm])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah the joys of picking a "reasonable" fake model. This seems like a better choice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It gives much more reasonable values, and is very similar to what LSST uses (the factor of 1000 is not in the LSST model, but the LSST model only shows significant distortion at much larger focal plane radius; I tuned it to get the distortion I wanted over the range of values this test uses).

focalPlaneToFieldAngle = fieldAngleToFocalPlane.getInverse()
focalPlaneToTanFieldAngle = self.makeAffineTransform(scale=self.radPerMm)
wcs = makeDistortedTanWcs(
tanWcs=self.tanWcs,
pixelToFocalPlane=self.focalPlaneToPixel.getInverse(),
pixelToFocalPlane=self.pixelToFocalPlane,
focalPlaneToFieldAngle=focalPlaneToFieldAngle,
)

# At the center of the focal plane both WCS should give the same sky position
pixelAtCtr = self.focalPlaneToPixel.applyForward(afwGeom.Point2D(0, 0))
pixelAtCtr = self.pixelToFocalPlane.applyInverse(afwGeom.Point2D(0, 0))
tanSkyAtCtr = self.tanWcs.pixelToSky(pixelAtCtr)
skyAtCtr = wcs.pixelToSky(pixelAtCtr)
self.assertPairsAlmostEqual(tanSkyAtCtr, skyAtCtr)
Expand All @@ -130,29 +132,24 @@ def testDistortion(self):
# since for a given pointing, field angle gives position on the sky
skyPoints = self.tanWcs.pixelToSky(self.pixelPoints)

pixelToFocalPlane = self.focalPlaneToPixel.getInverse()

focalPlaneToTanFieldAngle = self.makeAffineTransform(scale=self.radPerMm)
tanFieldAnglePoints = focalPlaneToTanFieldAngle.applyForward(
pixelToFocalPlane.applyForward(self.tanWcs.skyToPixel(skyPoints)))

self.pixelToFocalPlane.applyForward(self.tanWcs.skyToPixel(skyPoints)))
fieldAnglePoints = focalPlaneToFieldAngle.applyForward(
pixelToFocalPlane.applyForward(wcs.skyToPixel(skyPoints)))

self.pixelToFocalPlane.applyForward(wcs.skyToPixel(skyPoints)))
assert_allclose(tanFieldAnglePoints, fieldAnglePoints)

# The inverse should also be true: for a set of field angle points
# the following sky positions should be almost equal:
# fieldAngle -> fieldAngleToTanFocalPlane -> focalPlaneToPixel -> tanWcs.pixelToSky
# fieldAngle -> fieldAngleToFocalPlane -> focalPlaneToPixel -> wcs.pixelToSky
focalPlaneToPixel = self.pixelToFocalPlane.getInverse()
fieldAngleToTanFocalPlane = focalPlaneToTanFieldAngle.getInverse()
tanSkyPoints2 = self.tanWcs.pixelToSky(
self.focalPlaneToPixel.applyForward(
focalPlaneToPixel.applyForward(
fieldAngleToTanFocalPlane.applyForward(fieldAnglePoints)))

fieldAngleToFocalPlane = focalPlaneToFieldAngle.getInverse()
skyPoints2 = wcs.pixelToSky(
self.focalPlaneToPixel.applyForward(
focalPlaneToPixel.applyForward(
fieldAngleToFocalPlane.applyForward(fieldAnglePoints)))

self.assertSpherePointListsAlmostEqual(tanSkyPoints2, skyPoints2)
Expand All @@ -170,7 +167,7 @@ def testNoDistortion(self):
"""
focalPlaneToFieldAngle = self.makeAffineTransform(scale=self.radPerMm)
pixelToDistortedPixel = computePixelToDistortedPixel(
pixelToFocalPlane=self.focalPlaneToPixel.getInverse(),
pixelToFocalPlane=self.pixelToFocalPlane,
focalPlaneToFieldAngle=focalPlaneToFieldAngle,
)
bboxD = afwGeom.Box2D(self.bbox)
Expand All @@ -188,7 +185,7 @@ def testDistortion(self):
"""
focalPlaneToFieldAngle = afwGeom.makeRadialTransform([0.0, self.radPerMm, 0.0, self.radPerMm])
pixelToDistortedPixel = computePixelToDistortedPixel(
pixelToFocalPlane=self.focalPlaneToPixel.getInverse(),
pixelToFocalPlane=self.pixelToFocalPlane,
focalPlaneToFieldAngle=focalPlaneToFieldAngle,
)
# Do not try to make pixelToDistortedPixel -> self.tanWcs into a WCS
Expand All @@ -198,7 +195,7 @@ def testDistortion(self):

wcs = makeDistortedTanWcs(
tanWcs=self.tanWcs,
pixelToFocalPlane=self.focalPlaneToPixel.getInverse(),
pixelToFocalPlane=self.pixelToFocalPlane,
focalPlaneToFieldAngle=focalPlaneToFieldAngle,
)

Expand Down