def testDefaultNames(self): mi = MaskInfo( name="test", defaultHole=1, holePositions=self.holePositions, ) self.assertEqual(mi.numHoles, len(self.holePositions)) self.assertEqual(list(mi.holeNames), [str(i) for i in range(len(self.holePositions))])
def testOneDetector(self): detectorPositions = ((100, 250), (250, 100), (500, 1500)) for detector in self.cco.cameraGeom: detectorName = detector.getName() holePositions = computeHolePositions( detectorNames=[detectorName], detectorPositions=detectorPositions, cameraGeom=self.cco.cameraGeom, cbpFlipX=self.cco.config.cbpFlipX, cbpFocalLength=self.cco.config.cbpFocalLength, ) self.assertEqual(len(holePositions), len(detectorPositions)) self.cco.maskInfo = MaskInfo( name="OneDetector", holePositions=holePositions, defaultHole=0, ) self.assertEqual(len(self.cco), len(detectorPositions)) for i, beamInfo in enumerate(self.cco): self.assertTrue(beamInfo.isOnDetector) self.assertEqual(beamInfo.detectorName, detectorName) self.assertPairsAlmostEqual(beamInfo.detectorPos, detectorPositions[i])
def testOneHoleAllDetectors(self): detectorPosition = (449.2, 732.1) detectorNames = set(self.cco.cameraGeom.getNameIter()) numDetectors = len(self.cco.cameraGeom) flippedHolePositions = None # garbage value; compute correct value the first time through the loop for cbpFlipX in (False, True): # Note: test False first so flippedHolePositions # can be computed before it is needed. self.cco.config.cbpFlipX = cbpFlipX holePositions = computeHolePositions( detectorNames=None, detectorPositions=[detectorPosition], cameraGeom=self.cco.cameraGeom, cbpFlipX=self.cco.config.cbpFlipX, cbpFocalLength=self.cco.config.cbpFocalLength, ) if not cbpFlipX: # hopePositions are not flipped; compute flipped hole positions # so they can be compared to holePositions # when cbpFlipX is True. flippedHolePositions = [(-val[0], val[1]) for val in holePositions] else: self.assertPairListsAlmostEqual(holePositions, flippedHolePositions) self.assertEqual(len(holePositions), numDetectors) self.cco.maskInfo = MaskInfo( name="AllDetectors", holePositions=holePositions, defaultHole=0, ) self.assertEqual(len(self.cco), numDetectors) for beamInfo in self.cco: self.assertTrue(beamInfo.isOnDetector) self.assertIn(beamInfo.detectorName, detectorNames) self.assertPairsAlmostEqual(beamInfo.detectorPos, detectorPosition)
def testConstructorErrors(self): # defaultHole must not be None with self.assertRaises(ValueError): MaskInfo(name="test", defaultHole=None, holePositions=self.holePositions) with self.assertRaises(ValueError): MaskInfo(name="test", defaultHole=None, holePositions=self.holePositions, holeNames=self.holeNames) # defaultHole must be a valid name or index, # but unlike None, this raises LookupError # so it has to be a separate test. for invalidHole in (len(self.holePositions), "bad"): with self.assertRaises(LookupError): MaskInfo(name="test", defaultHole=invalidHole, holePositions=self.holePositions) with self.assertRaises(LookupError): MaskInfo(name="test", defaultHole=invalidHole, holePositions=self.holePositions, holeNames=self.holeNames) # The number of hole names must match the number of hole positions. holeNamesTooShort = self.holeNames[0:-1] with self.assertRaises(ValueError): MaskInfo(name="test", defaultHole=0, holePositions=self.holePositions, holeNames=holeNamesTooShort) holeNamesTooLong = self.holeNames + ["extra"] with self.assertRaises(ValueError): MaskInfo(name="test", defaultHole=0, holePositions=self.holePositions, holeNames=holeNamesTooLong)
def testBasics(self): name = "test mask" defaultHole = 2 self.assertEqual(len(self.holeNames), len(self.holePositions)) mi = MaskInfo( name=name, defaultHole=defaultHole, holePositions=self.holePositions, holeNames=self.holeNames, ) self.assertEqual(mi.name, name) self.assertEqual(mi.numHoles, len(self.holePositions)) self.assertEqual(list(mi.holeNames), self.holeNames) self.assertEqual(mi.asHoleName(None), self.holeNames[defaultHole]) self.assertEqual(mi.getHolePos(None), lsst.geom.Point2D(*self.holePositions[defaultHole])) for i in range(-mi.numHoles, mi.numHoles): holeName = mi.asHoleName(i) desiredHoleName = self.holeNames[i] self.assertEqual(holeName, desiredHoleName) desiredHolePosition = lsst.geom.Point2D(*self.holePositions[i]) self.assertEqual(mi.getHolePos(holeName), desiredHolePosition) self.assertEqual(mi.getHolePos(i), desiredHolePosition) with self.assertRaises(LookupError): mi.asHoleName("invalidName") with self.assertRaises(LookupError): mi.asHoleName(len(self.holePositions)) with self.assertRaises(LookupError): mi.asHoleName(-len(self.holePositions) - 1)