def testApplyCppTransform(self): """Test that we can apply a simple C++ transform""" inCat = self._generateCatalog() sillyControl = testLib.SillyCentroidControl() mapper = afwTable.SchemaMapper(inCat.schema) sillyTransform = testLib.SillyTransform(sillyControl, self.pluginName, mapper) outCat = afwTable.BaseCatalog(mapper.getOutputSchema()) outCat.extend(inCat, mapper=mapper) self.assertEqual(len(inCat), len(outCat)) sillyTransform(inCat, outCat, makeWcs(), afwImage.Calib()) self._checkSillyOutputs(inCat, outCat)
def testMeasureCentroid(self): """Test that we can instantiate and play with SillyMeasureCentroid""" for imageFactory in ( afwImage.MaskedImageF, afwImage.MaskedImageD, ): im = imageFactory(afwGeom.ExtentI(100, 100)) exp = afwImage.makeExposure(im) control1 = testLib.SillyCentroidControl() control1.name = "silly1" control1.priority = 0.0 control1.param = 0 control2 = testLib.SillyCentroidControl() control2.name = "silly2" control2.priority = 1.0 control2.param = 1 control3 = testLib.SillyCentroidControl() control3.name = "silly3" control3.priority = 2.0 control3.param = 2 schema = afwTable.SourceTable.makeMinimalSchema() builder = algorithms.MeasureSourcesBuilder() builder.addAlgorithm(control1) builder.addAlgorithm(control2) builder.addAlgorithm(control3) centroider = builder.build(schema) table = afwTable.SourceTable.make(schema) source = table.makeRecord() x, y = 10, 20 centroider.apply(source, exp, afwGeom.Point2D(x, y)) table.defineCentroid(control1.name) self.assertEqual(x, source.getX() - 0) self.assertEqual(y, source.getY() - 0) table.defineCentroid(control2.name) self.assertEqual(x, source.getX() - 1) self.assertEqual(y, source.getY() - 1) table.defineCentroid(control3.name) self.assertEqual(x, source.getX() - 2) self.assertEqual(y, source.getY() - 2)
def testMeasureCentroid(self): """Test that we can use our silly centroid through the usual Tasks. """ testLib.SillyCentroidControl() x, y = 10, 20 im = afwImage.MaskedImageF(lsst.geom.ExtentI(512, 512)) im.set(0) arr = im.getImage().getArray() arr[y, x] = 1000 exp = afwImage.makeExposure(im) schema = afwTable.SourceTable.makeMinimalSchema() schema.addField( "flags_negative", type="Flag", doc="set if source was detected as significantly negative") sfm_config = lsst.meas.base.sfm.SingleFrameMeasurementConfig() sfm_config.plugins = ["testLib_SillyCentroid"] sfm_config.plugins["testLib_SillyCentroid"].param = 5 sfm_config.slots.centroid = "testLib_SillyCentroid" sfm_config.slots.shape = None sfm_config.slots.psfShape = None sfm_config.slots.psfFlux = None sfm_config.slots.gaussianFlux = None sfm_config.slots.calibFlux = None sfm_config.slots.apFlux = None sfm_config.slots.modelFlux = None sfm_config.doReplaceWithNoise = False task = lsst.meas.base.SingleFrameMeasurementTask(schema, config=sfm_config) measCat = afwTable.SourceCatalog(schema) measCat.defineCentroid("testLib_SillyCentroid") source = measCat.addNew() source.set("testLib_SillyCentroid_x", x) source.set("testLib_SillyCentroid_y", y) source.set("parent", 0) source.set("flags_negative", False) # now run the SFM task with the test plugin task.run(measCat, exp) self.assertEqual(len(measCat), 1) self.assertEqual(measCat[0].getY(), y + 5) self.assertEqual(measCat[0].getX(), x + 5)
def testApplyCentroid(self): """Test that we can instantiate and play with SillyMeasureCentroid""" for imageFactory in (afwImage.MaskedImageF, ): im = imageFactory(afwGeom.ExtentI(100, 100)) exp = afwImage.makeExposure(im) for offset in (0, 1, 2): control = testLib.SillyCentroidControl() control.param = offset x, y = 10, 20 schema = afwTable.SourceTable.makeMinimalSchema() schema.addField("centroid_x", type=np.float64) schema.addField("centroid_y", type=np.float64) schema.getAliasMap().set("slot_Centroid", "centroid") plugin = testLib.SillyCentroidAlgorithm( control, "test", schema) measCat = afwTable.SourceCatalog(schema) source = measCat.makeRecord() source.set("centroid_x", x) source.set("centroid_y", y) plugin.measure(source, exp) self.assertEqual(x, source.get("test_x") - offset) self.assertEqual(y, source.get("test_y") - offset)