Coverage for python/lsst/meas/base/baseMeasurement.py : 75%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
#!/usr/bin/env python # # LSST Data Management System # Copyright 2008-2016 AURA/LSST. # # This product includes software developed by the # LSST Project (http://www.lsst.org/). # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the LSST License Statement and # the GNU General Public License along with this program. If not, # see <https://www.lsstcorp.org/LegalNotices/>. # """
"BaseMeasurementConfig", "BaseMeasurementTask")
# Exceptions that the measurement tasks should always propagate up to their callers
"""! Base config class for all measurement plugins
Most derived classes will want to override setDefaults() in order to customize the default exceutionOrder.
A derived class whose corresponding Plugin class implements measureN() should additionally add a bool doMeasureN field to replace the bool class attribute defined here. """
doc="whether to run this plugin in single-object mode")
''' Base class for all measurement plugins
This is class is a placeholder for future behavior which will be shared only between measurement plugins and is implemented for symmetry with the measurement base plugin configuration class '''
"""! Slot configuration which assigns a particular named plugin to each of a set of slots. Each slot allows a type of measurement to be fetched from the SourceTable without knowing which algorithm was used to produced the data.
NOTE: the default algorithm for each slot must be registered, even if the default is not used. """
doc="the name of the centroiding algorithm used to set source x,y") doc="the name of the algorithm used to set source moments parameters") doc="the name of the algorithm used to set PSF moments parameters") doc="the name of the algorithm used to set the source aperture instFlux slot") doc="the name of the algorithm used to set the source model instFlux slot") doc="the name of the algorithm used to set the source psf instFlux slot") doc="the name of the algorithm used to set the source Gaussian instFlux slot") doc="the name of the instFlux measurement algorithm used for calibration")
"""Convenience method to setup a Schema's slots according to the config definition.
This is defined in the Config class to support use in unit tests without needing to construct a Task object. """
"""! Base config class for all measurement driver tasks.
Subclasses should define the 'plugins' and 'undeblended' registries, e.g.:
plugins = PluginBaseClass.registry.makeField( multi=True, default=[], doc="Plugins to be run and their configuration" ) undeblended = PluginBaseClass.registry.makeField( multi=True, default=[], doc="Plugins to run on undeblended image" )
where PluginBaseClass is the appropriate base class of the plugin (e.g., SingleFramePlugin or ForcedPlugin). """
dtype=SourceSlotConfig, doc="Mapping from algorithms to special aliases in Source." )
dtype=bool, default=True, optional=False, doc='When measuring, replace other detected footprints with noise?')
dtype=NoiseReplacerConfig, doc="configuration that sets how to replace neighboring sources with noise" ) dtype=str, default="undeblended_", doc="Prefix to give undeblended plugins" )
raise ValueError("source centroid slot algorithm is not being run.") raise ValueError("source shape slot algorithm '%s' is not being run." % self.slots.shape) self.slots.gaussianFlux, self.slots.calibFlux): for name in self.plugins.names: if len(name) <= len(slot) and name == slot[:len(name)]: break else: raise ValueError("source instFlux slot algorithm '%s' is not being run." % slot)
## @addtogroup LSST_task_documentation ## @{ ## @page baseMeasurementTask ## BaseMeasurementTask @copybrief BaseMeasurementTask ## @}
"""! Ultimate base class for all measurement tasks.
This base class for SingleFrameMeasurementTask and ForcedMeasurementTask mostly exists to share code between the two, and generally should not be used directly. """
"""! Constructor; only called by derived classes.
@param[in] algMetadata An lsst.daf.base.PropertyList that will be filled with metadata about the plugins being run. If None, an empty PropertyList will be created. @param[in] **kwds Additional arguments passed to lsst.pipe.base.Task.__init__.
This attaches two public attributes to the class for use by derived classes and parent tasks: - plugins: an empty PluginMap, which will eventually contain all active plugins that will by invoked by the run() method (to be filled by subclasses). This should be considered read-only. - algMetadata: a lsst.daf.base.PropertyList that will contain additional information about the active plugins to be saved with the output catalog (to be filled by subclasses). """
"""Initialize the plugins (and slots) according to the configuration.
Derived class constructors should call this method to fill the self.plugins attribute and add correspond output fields and slot aliases to the output schema.
In addition to the attributes added by BaseMeasurementTask.__init__, a self.schema attribute holding the output schema must also be present before this method is called, .
Keyword arguments are forwarded directly to plugin constructors, allowing derived classes to use plugins with different signatures. """ # Make a place at the beginning for the centroid plugin to run first (because it's an OrderedDict, # adding an empty element in advance means it will get run first when it's reassigned to the # actual Plugin). # Init the plugins, sorted by execution order. At the same time add to the schema # Pass logName to the plugin if the plugin is marked as using it # The task will use this name to log plugin errors, regardless. logName=self.getPluginLogName(name), **kwds) else:
# In rare circumstances (usually tests), the centroid slot not be coming from an algorithm, # which means we'll have added something we don't want to the plugins map, and we should # remove it. # Initialize the plugins to run on the undeblended image **kwds)
"""! Call the measure() method on all plugins, handling exceptions in a consistent way.
@param[in,out] measRecord lsst.afw.table.SourceRecord that corresponds to the object being measured, and where outputs should be written. @param[in] *args Positional arguments forwarded to Plugin.measure() @param[in] **kwds Keyword arguments. Two are handled locally: - beginOrder: beginning execution order (inclusive): measurements with executionOrder < beginOrder are not executed. None for no limit. - endOrder: ending execution order (exclusive): measurements with executionOrder >= endOrder are not executed. None for no limit. the rest are forwarded to Plugin.measure()
This method can be used with plugins that have different signatures; the only requirement is that 'measRecord' be the first argument. Subsequent positional arguments and keyword arguments are forwarded directly to the plugin.
This method should be considered "protected"; it is intended for use by derived classes, not users. """ continue break
"""! Call the measure() method on the nominated plugin, handling exceptions in a consistent way.
@param[in] plugin Plugin that will measure @param[in,out] measRecord lsst.afw.table.SourceRecord that corresponds to the object being measured, and where outputs should be written. @param[in] *args Positional arguments forwarded to plugin.measure() @param[in] **kwds Keyword arguments forwarded to plugin.measure()
This method can be used with plugins that have different signatures; the only requirement is that the 'plugin' and 'measRecord' be the first two arguments. Subsequent positional arguments and keyword arguments are forwarded directly to the plugin.
This method should be considered "protected"; it is intended for use by derived classes, not users. """ "MeasurementError in %s.measure on record %s: %s" % (plugin.name, measRecord.getId(), error)) "Exception in %s.measure on record %s: %s" % (plugin.name, measRecord.getId(), error))
"""! Call the measureN() method on all plugins, handling exceptions in a consistent way.
@param[in,out] measCat lsst.afw.table.SourceCatalog containing records for just the source family to be measured, and where outputs should be written. @param[in] beginOrder beginning execution order (inclusive): measurements with executionOrder < beginOrder are not executed. None for no limit. @param[in] endOrder ending execution order (exclusive): measurements with executionOrder >= endOrder are not executed. None for no limit. @param[in] *args Positional arguments forwarded to Plugin.measure() @param[in] **kwds Keyword arguments. Two are handled locally: - beginOrder: beginning execution order (inclusive): measurements with executionOrder < beginOrder are not executed. None for no limit. - endOrder: ending execution order (exclusive): measurements with executionOrder >= endOrder are not executed. None for no limit. the rest are forwarded to Plugin.measure()
This method can be used with plugins that have different signatures; the only requirement is that 'measRecord' be the first argument. Subsequent positional arguments and keyword arguments are forwarded directly to the plugin.
This method should be considered "protected"; it is intended for use by derived classes, not users. """ if beginOrder is not None and plugin.getExecutionOrder() < beginOrder: continue if endOrder is not None and plugin.getExecutionOrder() >= endOrder: break self.doMeasurementN(plugin, measCat, *args, **kwds)
"""! Call the measureN() method on the nominated plugin, handling exceptions in a consistent way.
@param[in] plugin Plugin that will measure @param[in,out] measCat lsst.afw.table.SourceCatalog containing records for just the source family to be measured, and where outputs should be written. @param[in] *args Positional arguments forwarded to plugin.measureN() @param[in] **kwds Keyword arguments forwarded to plugin.measureN()
This method can be used with plugins that have different signatures; the only requirement is that the 'plugin' and 'measCat' be the first two arguments. Subsequent positional arguments and keyword arguments are forwarded directly to the plugin.
This method should be considered "protected"; it is intended for use by derived classes, not users. """ try: plugin.measureN(measCat, *args, **kwds) except FATAL_EXCEPTIONS: raise
except MeasurementError as error: for measRecord in measCat: lsst.log.Log.getLogger(self.getPluginLogName(plugin.name)).debug( "MeasurementError in %s.measureN on records %s-%s: %s" % (plugin.name, measCat[0].getId(), measCat[-1].getId(), error)) plugin.fail(measRecord, error) except Exception as error: for measRecord in measCat: plugin.fail(measRecord) lsst.log.Log.getLogger(self.getPluginLogName(plugin.name)).debug( "Exception in %s.measureN on records %s-%s: %s" % (plugin.name, measCat[0].getId(), measCat[-1].getId(), error)) |