def testNoFailureFlag(self): """Test with no failure flag. """ schema = lsst.afw.table.SourceTable.makeMinimalSchema() # This is a FlagDefinition structure like a plugin might have flagDefs = FlagDefinitionList() FIRST = flagDefs.add("1st error", "this is the first failure type") SECOND = flagDefs.add("2nd error", "this is the second failure type") fh = FlagHandler.addFields(schema, "test", flagDefs) # Check to be sure that the FlagHandler was correctly initialized for index in range(len(flagDefs)): self.assertEqual(flagDefs.getDefinition(index).name, fh.getFlagName(index)) catalog = lsst.afw.table.SourceCatalog(schema) # Now check to be sure that all of the known failures set the bits # correctly record = catalog.addNew() fh.handleFailure(record) self.assertFalse(fh.getValue(record, FIRST.number)) self.assertFalse(fh.getValue(record, SECOND.number)) record = catalog.addNew() record = catalog.addNew() error = MeasurementError(FIRST.doc, FIRST.number) fh.handleFailure(record, error.cpp) self.assertTrue(fh.getValue(record, FIRST.number)) self.assertFalse(fh.getValue(record, SECOND.number)) record = catalog.addNew() error = MeasurementError(SECOND.doc, SECOND.number) fh.handleFailure(record, error.cpp) self.assertFalse(fh.getValue(record, FIRST.number)) self.assertTrue(fh.getValue(record, SECOND.number))
def __init__(self, config, name, schema, metadata, logName=None): SingleFramePlugin.__init__(self, config, name, schema, metadata, logName=logName) flagDefs = FlagDefinitionList() self.FAILURE = flagDefs.addFailureFlag() self.CONTAINS_NAN = flagDefs.add("flag_containsNan", "Measurement area contains a nan") self.flagHandler = FlagHandler.addFields(schema, name, flagDefs) self.instFluxKey = schema.addField(name + "_instFlux", "F", doc="flux")
def __init__(self, config, name, schema, metadata): super().__init__(config, name, schema, metadata) # Measurement Keys self.keyX0 = schema.addField(name + "_x0", type="D", doc="Trail head X coordinate.", units="pixel") self.keyY0 = schema.addField(name + "_y0", type="D", doc="Trail head Y coordinate.", units="pixel") self.keyX1 = schema.addField(name + "_x1", type="D", doc="Trail tail X coordinate.", units="pixel") self.keyY1 = schema.addField(name + "_y1", type="D", doc="Trail tail Y coordinate.", units="pixel") self.keyFlux = schema.addField(name + "_flux", type="D", doc="Trailed source flux.", units="count") self.keyL = schema.addField(name + "_length", type="D", doc="Trail length.", units="pixel") self.keyAngle = schema.addField(name + "_angle", type="D", doc="Angle measured from +x-axis.") # Measurement Error Keys self.keyX0Err = schema.addField(name + "_x0Err", type="D", doc="Trail head X coordinate error.", units="pixel") self.keyY0Err = schema.addField(name + "_y0Err", type="D", doc="Trail head Y coordinate error.", units="pixel") self.keyX1Err = schema.addField(name + "_x1Err", type="D", doc="Trail tail X coordinate error.", units="pixel") self.keyY1Err = schema.addField(name + "_y1Err", type="D", doc="Trail tail Y coordinate error.", units="pixel") flagDefs = FlagDefinitionList() flagDefs.addFailureFlag("No trailed-source measured") self.NO_FLUX = flagDefs.add("flag_noFlux", "No suitable prior flux measurement") self.flagHandler = FlagHandler.addFields(schema, name, flagDefs) self.centriodExtractor = SafeCentroidExtractor(schema, name)
def __init__(self, config, name, schema, metadata): SingleFramePlugin.__init__(self, config, name, schema, metadata) flagDefs = FlagDefinitionList() self.FAILURE = flagDefs.addFailureFlag() self.CONTAINS_NAN = flagDefs.add("flag_containsNan", "Measurement area contains a nan") self.EDGE = flagDefs.add("flag_edge", "Measurement area over edge") self.flagHandler = FlagHandler.addFields(schema, name, flagDefs) self.centroidExtractor = lsst.meas.base.SafeCentroidExtractor(schema, name) self.instFluxKey = schema.addField(name + "_instFlux", "F", doc="flux") self.magKey = schema.addField(name + "_mag", "F", doc="mag")
def __init__(self, config, name, schema, metadata): SingleFramePlugin.__init__(self, config, name, schema, metadata) flagDefs = FlagDefinitionList() self.FAILURE = flagDefs.addFailureFlag() self.CONTAINS_NAN = flagDefs.add("flag_containsNan", "Measurement area contains a nan") self.EDGE = flagDefs.add("flag_edge", "Measurement area over edge") self.flagHandler = FlagHandler.addFields(schema, name, flagDefs) self.centroidExtractor = lsst.meas.base.SafeCentroidExtractor( schema, name) self.fluxKey = schema.addField(name + "_flux", "F", doc="flux") self.magKey = schema.addField(name + "_mag", "F", doc="mag")
def __init__(self, config, name, schema, metadata, logName=None): SingleFramePlugin.__init__(self, config, name, schema, metadata, logName=logName) flagDefs = FlagDefinitionList() self.FAILURE = flagDefs.addFailureFlag() self.CONTAINS_NAN = flagDefs.add("flag_containsNan", "Measurement area contains a nan") self.flagHandler = FlagHandler.addFields(schema, name, flagDefs) self.fluxKey = schema.addField(name + "_flux", "F", doc="flux")
def __init__(self, config, name, schema, metadata): super().__init__(config, name, schema, metadata) self.keyXC = schema.addField(name + "_centroid_x", type="D", doc="Trail centroid X coordinate.", units="pixel") self.keyYC = schema.addField(name + "_centroid_y", type="D", doc="Trail centroid Y coordinate.", units="pixel") self.keyX0 = schema.addField(name + "_x0", type="D", doc="Trail head X coordinate.", units="pixel") self.keyY0 = schema.addField(name + "_y0", type="D", doc="Trail head Y coordinate.", units="pixel") self.keyX1 = schema.addField(name + "_x1", type="D", doc="Trail tail X coordinate.", units="pixel") self.keyY1 = schema.addField(name + "_y1", type="D", doc="Trail tail Y coordinate.", units="pixel") self.keyL = schema.addField(name + "_length", type="D", doc="Length of trail.", units="pixel") self.keyTheta = schema.addField(name + "_angle", type="D", doc="Angle of trail from +x-axis.") self.keyFlux = schema.addField(name + "_flux", type="D", doc="Trailed source flux.", units="count") self.keyRChiSq = schema.addField(name + "_rChiSq", type="D", doc="Reduced chi-squared of fit") flagDefs = FlagDefinitionList() flagDefs.addFailureFlag("No trailed-sources measured") self.NON_CONVERGE = flagDefs.add("flag_nonConvergence", "Optimizer did not converge") self.NO_NAIVE = flagDefs.add("flag_noNaive", "Naive measurement contains NaNs") self.flagHandler = FlagHandler.addFields(schema, name, flagDefs) self.centroidExtractor = SafeCentroidExtractor(schema, name)
def __init__(self, config, name, schema, metadata): SingleFramePlugin.__init__(self, config, name, schema, metadata) flagDefs = FlagDefinitionList() flagDefs.add("flag", "General Failure error") flagDefs.add("test_flag", "second flag") self.flagHandler = FlagHandler.addFields(schema, name, flagDefs) self.xKey = schema.addField(schema.join(name, "x"), type=np.float64) self.yKey = schema.addField(schema.join(name, "y"), type=np.float64) if self.config.dist is None: self.centroidChecker = lsst.meas.base.CentroidChecker(schema, name) else: self.centroidChecker = lsst.meas.base.CentroidChecker( schema, name, True, self.config.dist)
def testFlagHandler(self): """ Standalone test to create a flaghandler and call it This is not a real world example, just a simple unit test """ schema = lsst.afw.table.SourceTable.makeMinimalSchema() # This is a FlagDefinition structure like a plugin might have flagDefs = FlagDefinitionList() FAILURE = flagDefs.addFailureFlag() FIRST = flagDefs.add("1st error", "this is the first failure type") SECOND = flagDefs.add("2nd error", "this is the second failure type") fh = FlagHandler.addFields(schema, "test", flagDefs) # Check to be sure that the FlagHandler was correctly initialized for index in range(len(flagDefs)): self.assertEqual( flagDefs.getDefinition(index).name, fh.getFlagName(index)) catalog = lsst.afw.table.SourceCatalog(schema) # Now check to be sure that all of the known failures set the bits correctly record = catalog.addNew() fh.handleFailure(record) self.assertTrue(fh.getValue(record, FAILURE.number)) self.assertFalse(fh.getValue(record, FIRST.number)) self.assertFalse(fh.getValue(record, SECOND.number)) record = catalog.addNew() error = MeasurementError(FAILURE.doc, FAILURE.number) fh.handleFailure(record, error.cpp) self.assertTrue(fh.getValue(record, FAILURE.number)) self.assertFalse(fh.getValue(record, FIRST.number)) self.assertFalse(fh.getValue(record, SECOND.number)) record = catalog.addNew() error = MeasurementError(FIRST.doc, FIRST.number) fh.handleFailure(record, error.cpp) self.assertTrue(fh.getValue(record, FAILURE.number)) self.assertTrue(fh.getValue(record, FIRST.number)) self.assertFalse(fh.getValue(record, SECOND.number)) record = catalog.addNew() error = MeasurementError(SECOND.doc, SECOND.number) fh.handleFailure(record, error.cpp) self.assertTrue(fh.getValue(record, FAILURE.number)) self.assertFalse(fh.getValue(record, FIRST.number)) self.assertTrue(fh.getValue(record, SECOND.number))
def __init__(self, config, name, schema, metadata): SingleFramePlugin.__init__(self, config, name, schema, metadata) flagDefs = FlagDefinitionList() flagDefs.add("flag", "General Failure error") flagDefs.add("test_flag", "second flag") self.flagHandler = FlagHandler.addFields(schema, name, flagDefs) if self.config.setErrors: uncertainty = lsst.meas.base.UncertaintyEnum.SIGMA_ONLY else: uncertainty = lsst.meas.base.UncertaintyEnum.NO_UNCERTAINTY self.centroidKey = lsst.meas.base.CentroidResultKey.addFields(schema, name, name, uncertainty) if self.config.dist is None: self.centroidChecker = lsst.meas.base.CentroidChecker(schema, name) else: self.centroidChecker = lsst.meas.base.CentroidChecker(schema, name, True, self.config.dist)