def testBasics(self): """Test CameraSys and CameraSysPrefix """ for sysName in ("fieldAngle", "pixels"): for detectorName in ("", "det1", "det2"): cameraSys = cameraGeom.CameraSys(sysName, detectorName) self.assertEqual(cameraSys.getSysName(), sysName) self.assertEqual(cameraSys.getDetectorName(), detectorName) self.assertEqual(cameraSys.hasDetectorName(), bool(detectorName)) noDetSys = cameraGeom.CameraSys(sysName) self.assertEqual(noDetSys.getSysName(), sysName) self.assertEqual(noDetSys.getDetectorName(), "") self.assertFalse(noDetSys.hasDetectorName()) camSysPrefix = cameraGeom.CameraSysPrefix(sysName) self.assertEqual(camSysPrefix.getSysName(), sysName) cameraSys2 = cameraGeom.CameraSys(camSysPrefix, detectorName) self.assertEqual(cameraSys2.getSysName(), sysName) self.assertEqual(cameraSys2.getDetectorName(), detectorName) self.assertEqual(cameraSys2, cameraSys) if detectorName: self.assertNotEqual(cameraSys, noDetSys) else: self.assertEqual(cameraSys, noDetSys) # The following tests are checking the functionality of the # == and != operators and should not be replaced with # assertEqual or assertNotEqual self.assertTrue(cameraSys != camSysPrefix) self.assertTrue(noDetSys != camSysPrefix) self.assertFalse(cameraSys == camSysPrefix) self.assertFalse(noDetSys == camSysPrefix) for sysName2 in ("fieldAngle", "pixels"): for detectorName2 in ("", "det1", "det2"): cameraSys2 = cameraGeom.CameraSys(sysName2, detectorName2) if sysName == sysName2 and detectorName == detectorName2: self.assertEqual(cameraSys, cameraSys2) # test __eq__ and __ne__ self.assertTrue(cameraSys == cameraSys2) self.assertFalse(cameraSys != cameraSys2) else: self.assertNotEqual(cameraSys, cameraSys2) # test __eq__ and __ne__ self.assertTrue(cameraSys != cameraSys2) self.assertFalse(cameraSys == cameraSys2) camSysPrefix2 = cameraGeom.CameraSysPrefix(sysName2) if sysName2 == sysName: self.assertEqual(camSysPrefix2, camSysPrefix) else: self.assertNotEqual(camSysPrefix2, camSysPrefix)
def testBasics(self): """Test CameraSys and CameraSysPrefix """ for sysName in ("pupil", "pixels"): for detectorName in ("", "det1", "det2"): cameraSys = cameraGeom.CameraSys(sysName, detectorName) self.assertEquals(cameraSys.getSysName(), sysName) self.assertEquals(cameraSys.getDetectorName(), detectorName) self.assertEquals(cameraSys.hasDetectorName(), bool(detectorName)) noDetSys = cameraGeom.CameraSys(sysName) self.assertEquals(noDetSys.getSysName(), sysName) self.assertEquals(noDetSys.getDetectorName(), "") self.assertFalse(noDetSys.hasDetectorName()) camSysPrefix = cameraGeom.CameraSysPrefix(sysName) self.assertEquals(camSysPrefix.getSysName(), sysName) if detectorName: self.assertFalse(cameraSys == noDetSys) self.assertTrue(cameraSys != noDetSys) else: self.assertTrue(cameraSys == noDetSys) self.assertFalse(cameraSys != noDetSys) self.assertTrue(cameraSys != camSysPrefix) self.assertTrue(noDetSys != camSysPrefix) self.assertFalse(cameraSys == camSysPrefix) self.assertFalse(noDetSys == camSysPrefix) for sysName2 in ("pupil", "pixels"): for detectorName2 in ("", "det1", "det2"): cameraSys2 = cameraGeom.CameraSys(sysName2, detectorName2) if sysName == sysName2 and detectorName == detectorName2: self.assertTrue(cameraSys == cameraSys2) self.assertFalse(cameraSys != cameraSys2) else: self.assertFalse(cameraSys == cameraSys2) self.assertTrue(cameraSys != cameraSys2) camSysPrefix2 = cameraGeom.CameraSysPrefix(sysName2) if sysName2 == sysName: self.assertTrue(camSysPrefix2 == camSysPrefix) self.assertFalse(camSysPrefix2 != camSysPrefix) else: self.assertFalse(camSysPrefix2 == camSysPrefix) self.assertTrue(camSysPrefix2 != camSysPrefix)
def testRepr(self): """Test __repr__ """ cs1 = cameraGeom.CameraSys("pixels", "det1") self.assertEqual(repr(cs1), "CameraSys(pixels, det1)") cs2 = cameraGeom.CameraSys("pixels") self.assertEqual(repr(cs2), "CameraSys(pixels)") dsp = cameraGeom.CameraSysPrefix("pixels") self.assertEqual(repr(dsp), "CameraSysPrefix(pixels)")
def testMakeCameraSys(self): """Test the makeCameraSys method """ dw = DetectorWrapper() for sysName in ("csys1", "csys2"): for detectorName in ("", dw.name, "a different detector"): inCamSys = cameraGeom.CameraSys(sysName, detectorName) outCamSys = dw.detector.makeCameraSys(inCamSys) self.assertEquals(inCamSys, outCamSys) inCamSysPrefix = cameraGeom.CameraSysPrefix(sysName) outCamSys2 = dw.detector.makeCameraSys(inCamSysPrefix) self.assertEquals(outCamSys2, cameraGeom.CameraSys(sysName, dw.name))
def testMakeCameraPoint(self): """Test the makeCameraPoint method """ dw = DetectorWrapper() for xyMM in ((25.6, -31.07), (0, 0)): point = afwGeom.Point2D(*xyMM) for sysName in ("csys1", "csys2"): for detectorName in ("", dw.name, "a different detector"): cameraSys1 = cameraGeom.CameraSys(sysName, detectorName) cameraPoint1 = dw.detector.makeCameraPoint(point, cameraSys1) self.assertEquals(cameraPoint1.getPoint(), point) self.assertEquals(cameraPoint1.getCameraSys(), cameraSys1) cameraSysPrefix = cameraGeom.CameraSysPrefix(sysName) cameraPoint2 = dw.detector.makeCameraPoint(point, cameraSysPrefix) predCameraSys2 = cameraGeom.CameraSys(sysName, dw.name) self.assertEquals(cameraPoint2.getPoint(), point) self.assertEquals(cameraPoint2.getCameraSys(), predCameraSys2)
def makeCameraFromCatalogs(cameraName, detectorConfigList, nativeSys, transformDict, amplifierDict, pupilFactoryClass=cameraGeom.pupil.PupilFactory): """Construct a Camera instance from a dictionary of detector name : `lsst.afw.cameraGeom.amplifier` Parameters ---------- cameraName : `str` The name of the camera detectorConfigList : `list` A list of `lsst.afw.cameraGeom.cameraConfig.DetectorConfig` nativeSys : `lsst.afw.cameraGeom.CameraSys` The native transformation type; must be `lsst.afw.cameraGeom.FOCAL_PLANE` transformDict : `dict` A dict of lsst.afw.cameraGeom.CameraSys : `lsst.afw.geom.TransformPoint2ToPoint2` amplifierDict : `dict` A dictionary of detector name : `lsst.afw.cameraGeom.Amplifier.Builder` pupilFactoryClass : `type`, optional Class to attach to camera; `lsst.default afw.cameraGeom.PupilFactory` Returns ------- camera : `lsst.afw.cameraGeom.Camera` New Camera instance. Notes ------ Copied from `lsst.afw.cameraGeom.cameraFactory` with permission and encouragement from Jim Bosch """ # nativeSys=FOCAL_PLANE seems to be assumed in various places in this file # (e.g. the definition of TAN_PIXELS), despite CameraConfig providing the # illusion that it's configurable. # Note that we can't actually get rid of the nativeSys config option # without breaking lots of on-disk camera configs. assert nativeSys == cameraGeom.FOCAL_PLANE, "Cameras with nativeSys != FOCAL_PLANE are not supported." focalPlaneToField = transformDict[cameraGeom.FIELD_ANGLE] cameraBuilder = Camera.Builder(cameraName) cameraBuilder.setPupilFactoryClass(pupilFactoryClass) # Ensure all transforms in the camera transform dict are included. for toSys, transform in transformDict.items(): cameraBuilder.setTransformFromFocalPlaneTo(toSys, transform) for detectorConfig in detectorConfigList: # This should build all detector pixel -> focalPlane transforms. cameraGeom.addDetectorBuilderFromConfig(cameraBuilder, detectorConfig, amplifierDict[detectorConfig.name], focalPlaneToField) # For reasons I don't understand, some obs_ packages (e.g. HSC) set # nativeSys to None for their detectors (which doesn't seem to be # permitted by the config class!), but they really mean PIXELS. For # backwards compatibility we use that as the default... detectorNativeSys = detectorConfig.transformDict.nativeSys detectorNativeSys = (cameraGeom.PIXELS if detectorNativeSys is None else cameraGeom.CameraSysPrefix(detectorNativeSys)) # ...well, actually, it seems that we've always assumed down in C++ # that the answer is always PIXELS without ever checking that it is. # So let's assert that it is, since there are hints all over this file # (e.g. the definition of TAN_PIXELS) that other parts of the codebase # have regularly made that assumption as well. Note that we can't # actually get rid of the nativeSys config option without breaking # lots of on-disk camera configs. assert detectorNativeSys == cameraGeom.PIXELS, \ "Detectors with nativeSys != PIXELS are not supported." detectorNativeSys = cameraGeom.CameraSys(detectorNativeSys, detectorConfig.name) return cameraBuilder.finish()