def testBadCentroid(self): """The flag from the centroid slot should propagate to the badCentroid flag on the variance plugin.""" schema = afwTable.SourceTable.makeMinimalSchema() measBase.SingleFramePeakCentroidPlugin( measBase.SingleFramePeakCentroidConfig(), "centroid", schema, None) schema.getAliasMap().set("slot_Centroid", "centroid") variance = measBase.SingleFrameVariancePlugin( measBase.VarianceConfig(), "variance", schema, None) catalog = afwTable.SourceCatalog(schema) # The centroid is not flagged as bad, but there's no way the algorithm can run without # valid data in the SourceRecord and Exposure: this should throw a logic error. record = catalog.addNew() record.set("centroid_flag", False) with self.assertRaises(measBase.MeasurementError) as measErr: variance.measure(record, None) variance.fail(record, measErr.exception) self.assertTrue(record.get("variance_flag")) self.assertFalse(record.get("variance_flag_badCentroid")) # The centroid is flagged as bad, so we should get a MeasurementError # indicating an expected failure. record = catalog.addNew() record.set("centroid_flag", True) with self.assertRaises(measBase.MeasurementError) as measErr: variance.measure(record, None) variance.fail(record, measErr.exception) self.assertTrue(record.get("variance_flag")) self.assertTrue(record.get("variance_flag_badCentroid"))
def _preparePlugin(self, numCoaddInputs): """ Prepare a SingleFrameInputCountPlugin for running. Sets up an InputCount plugin to run on an empty catalog together with a synthetic, content-free Exposure. @param[in] numCoaddInputs Number of coadd inputs for use in synthetic exposure. @returns tuple of (initialized plugin, empty catalog, synthetic exposure) """ exp = afwImage.ExposureF() if numCoaddInputs > 0: exp.getInfo().setCoaddInputs( afwImage.CoaddInputs(*[ afwTable.ExposureTable.makeMinimalSchema() for _ in range(numCoaddInputs) ])) schema = afwTable.SourceTable.makeMinimalSchema() measBase.SingleFramePeakCentroidPlugin( measBase.SingleFramePeakCentroidConfig(), "centroid", schema, None) schema.getAliasMap().set("slot_Centroid", "centroid") inputCount = measBase.SingleFrameInputCountPlugin( measBase.SingleFrameInputCountConfig(), "inputCount", schema, None) catalog = afwTable.SourceCatalog(schema) return inputCount, catalog, exp
def _preparePlugin(self, addCoaddInputs): """Prepare a `SingleFrameInputCountPlugin` for running. Sets up the plugin to run on an empty catalog together with a synthetic, content-free `~lsst.afw.image.ExposureF`. Parameters ---------- addCoaddInputs : `bool` Should we add the coadd inputs? Returns ------- inputCount : `SingleFrameInputCountPlugin` Initialized measurement plugin. catalog : `lsst.afw.table.SourceCatalog` Empty Catalog. exp : `lsst.afw.image.ExposureF` Synthetic exposure. """ exp = afwImage.ExposureF(20, 20) scale = 1.0e-5 * lsst.geom.degrees wcs = afwGeom.makeSkyWcs(crpix=lsst.geom.Point2D(0, 0), crval=lsst.geom.SpherePoint( 0.0, 0.0, lsst.geom.degrees), cdMatrix=afwGeom.makeCdMatrix(scale=scale)) exp.setWcs(wcs) if addCoaddInputs: exp.getInfo().setCoaddInputs( afwImage.CoaddInputs( afwTable.ExposureTable.makeMinimalSchema(), afwTable.ExposureTable.makeMinimalSchema())) ccds = exp.getInfo().getCoaddInputs().ccds record = ccds.addNew() record.setWcs(wcs) record.setBBox(exp.getBBox()) record.setValidPolygon( afwGeom.Polygon(lsst.geom.Box2D(exp.getBBox()))) schema = afwTable.SourceTable.makeMinimalSchema() measBase.SingleFramePeakCentroidPlugin( measBase.SingleFramePeakCentroidConfig(), "centroid", schema, None) schema.getAliasMap().set("slot_Centroid", "centroid") inputCount = measBase.SingleFrameInputCountPlugin( measBase.InputCountConfig(), "inputCount", schema, None) catalog = afwTable.SourceCatalog(schema) return inputCount, catalog, exp
def _preparePlugin(self, addCoaddInputs): """ Prepare a SingleFrameInputCountPlugin for running. Sets up an InputCount plugin to run on an empty catalog together with a synthetic, content-free Exposure. @param[in] addCoaddInputs Should we add the coadd inputs? @returns tuple of (initialized plugin, empty catalog, synthetic exposure) """ exp = afwImage.ExposureF(20, 20) scale = 1.0e-5 * afwGeom.degrees wcs = afwGeom.makeSkyWcs(crpix=afwGeom.Point2D(0, 0), crval=afwGeom.SpherePoint( 0.0, 0.0, afwGeom.degrees), cdMatrix=afwGeom.makeCdMatrix(scale=scale)) exp.setWcs(wcs) if addCoaddInputs: exp.getInfo().setCoaddInputs( afwImage.CoaddInputs( afwTable.ExposureTable.makeMinimalSchema(), afwTable.ExposureTable.makeMinimalSchema())) ccds = exp.getInfo().getCoaddInputs().ccds record = ccds.addNew() record.setWcs(wcs) record.setBBox(exp.getBBox()) record.setValidPolygon( afwGeom.Polygon(afwGeom.Box2D(exp.getBBox()))) schema = afwTable.SourceTable.makeMinimalSchema() measBase.SingleFramePeakCentroidPlugin( measBase.SingleFramePeakCentroidConfig(), "centroid", schema, None) schema.getAliasMap().set("slot_Centroid", "centroid") inputCount = measBase.SingleFrameInputCountPlugin( measBase.InputCountConfig(), "inputCount", schema, None) catalog = afwTable.SourceCatalog(schema) return inputCount, catalog, exp