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-11594: test_distortion fails when run from pytest #88

Merged
merged 4 commits into from
Aug 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ _build.*
*.os
*.pyc
*.so
.cache
*~
#*
*#
Expand Down
Binary file modified tests/data/distortionData.pickle
Binary file not shown.
49 changes: 32 additions & 17 deletions tests/test_distortion.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,16 @@
import os.path
import unittest
import pickle
from collections import namedtuple

import lsst.utils.tests
from lsst.obs.hsc import HscMapper
from lsst.pipe.base import Struct
from lsst.afw.cameraGeom import FOCAL_PLANE, PUPIL, PIXELS

# Set SAVE_DATA True to save new distortion data; this will make the test fail,
# to remind you to set it False before committing the code.
SAVE_DATA = False

CcdData = namedtuple("CcdData", ['serial', 'cornerDict'])
CornerData = namedtuple("CornerData", ['focalPlane', "pupil", "focalPlaneRoundTrip", "pixPosRoundTrip"])
DataFileName = "data/distortionData.pickle" # path relative to the tests directory


Expand Down Expand Up @@ -68,19 +66,32 @@ def testDistortion(self):
for detectorName, ccdData in newData.items():
savedCcdData = savedData[detectorName]
self.assertEqual(ccdData.serial, savedCcdData.serial)
for pixPos, cornerData in ccdData.cornerDict.items():
savedCornerData = savedCcdData.cornerDict[pixPos]
for pixPosKey, cornerData in ccdData.cornerDict.items():
savedCornerData = savedCcdData.cornerDict[pixPosKey]
self.assertEqual(cornerData.pixPos, savedCornerData.pixPos)
self.assertPairsAlmostEqual(cornerData.focalPlane, savedCornerData.focalPlane)
self.assertPairsAlmostEqual(cornerData.pupil, savedCornerData.pupil)
self.assertPairsAlmostEqual(cornerData.focalPlaneRoundTrip,
savedCornerData.focalPlaneRoundTrip)
self.assertPairsAlmostEqual(cornerData.pixPosRoundTrip, savedCornerData.pixPosRoundTrip)
self.assertPairsAlmostEqual(cornerData.fieldAngle, savedCornerData.fieldAngle)
self.assertPairsAlmostEqual(cornerData.focalPlaneRoundTrip, cornerData.focalPlane,
maxDiff=0.01)
self.assertPairsAlmostEqual(cornerData.pixPosRoundTrip, cornerData.pixPos, maxDiff=0.01)

def makeDistortionData(self):
"""Make distortion data

The data format is a dict of detector name: ccdData, where
ccdData is a Struct containing these fields:
- serial: detector.getSerial
- cornerDict: a dict of pixPosKey, cornerData, where:
- pixPosKey: self.asKey(pixPos) where pixPos is pixel position
- cornerData is Struct contains these fields (all of type lsst.afw.geom.Point2D):
- pixPos: pixel position
- focalPlane: focal plane position computed from pixPos
- fieldAngle: fieldAngle position computed from focalPlane
- focalPlaneRoundTrip: focal plane position computed from fieldAngle
- pixPosRoundTrip: pixel position computed from focalPlane
"""
camera = HscMapper(root=".").camera
focalPlaneToPupil = camera.getTransformMap().get(PUPIL)
focalPlaneToFieldAngle = camera.getTransformMap().get(PUPIL)
data = {} # dict of detector name: CcdData
for detector in camera:
# for each corner of each CCD:
Expand All @@ -93,22 +104,26 @@ def makeDistortionData(self):
pixelsToFocalPlane = detector.getTransform(FOCAL_PLANE)
cornerDict = {}
for pixPos in detector.getCorners(PIXELS):
pixPos = pixPos
focalPlane = pixelsToFocalPlane.forwardTransform(pixPos)
pupil = focalPlaneToPupil.forwardTransform(focalPlane)
focalPlaneRoundTrip = focalPlaneToPupil.reverseTransform(pupil)
pixPosRoundTrip = pixelsToFocalPlane.reverseTransform(focalPlaneRoundTrip)
# Use a tuple (x, y) as a the key instead of a Point2D, for assured reasonable hashability
cornerDict[(pixPos[0], pixPos[1])] = CornerData(
fieldAngle = focalPlaneToFieldAngle.forwardTransform(focalPlane)
focalPlaneRoundTrip = focalPlaneToFieldAngle.reverseTransform(fieldAngle)
pixPosRoundTrip = pixelsToFocalPlane.reverseTransform(focalPlane)
cornerDict[self.toKey(pixPos)] = Struct(
pixPos = pixPos,
focalPlane = focalPlane,
pupil = pupil,
fieldAngle = fieldAngle,
focalPlaneRoundTrip = focalPlaneRoundTrip,
pixPosRoundTrip = pixPosRoundTrip,
)

data[detector.getName()] = CcdData(serial=detector.getSerial(), cornerDict=cornerDict)
data[detector.getName()] = Struct(serial=detector.getSerial(), cornerDict=cornerDict)

return data

def toKey(self, pixPos):
return "(%0.1f, %0.1f)" % tuple(pixPos)


class TestMemory(lsst.utils.tests.MemoryTestCase):
def setUp(self):
Expand Down