lsst.meas.base  14.0-22-gcfb0d17+2
pluginsBase.py
Go to the documentation of this file.
1 #
2 # LSST Data Management System
3 #
4 # Copyright 2008-2016 AURA/LSST.
5 #
6 # This product includes software developed by the
7 # LSST Project (http://www.lsst.org/).
8 #
9 # This program is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
13 #
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the LSST License Statement and
20 # the GNU General Public License along with this program. If not,
21 # see <https://www.lsstcorp.org/LegalNotices/>.
22 #
23 import traceback
24 
25 from builtins import object
26 
27 import lsst.pex.config
28 from .transforms import PassThroughTransform
29 
30 __all__ = ("BasePluginConfig", "BasePlugin")
31 
32 
33 class BasePluginConfig(lsst.pex.config.Config):
34  """!
35  Base class measurement Plugin config classes.
36 
37  Most derived classes will want to set defaults that make sense for the plugin type
38  """
39  pass
40 
41 
42 class BasePlugin(object):
43  """!
44  Base class for measurement plugins.
45 
46  This is the base class for SingleFramePlugin and ForcedPlugin; derived classes should inherit
47  from one of those.
48  """
49  # named class constants for execution order
50  CENTROID_ORDER = 0.0
51  SHAPE_ORDER = 1.0
52  FLUX_ORDER = 2.0
53  APCORR_ORDER = 3.0
54  DEFAULT_CATALOGCALCULATION = 4.0
55 
56  @classmethod
58  """Sets the relative order of plugins (smaller numbers run first).
59 
60  In general, the following class constants should be used (other values
61  are also allowed, but should be avoided unless they are needed):
62  CENTROID_ORDER centroids and other algorithms that require only a Footprint
63  and its Peaks as input
64  SHAPE_ORDER shape measurements and other algorithms that require getCentroid() to return
65  a good centroid (in addition to a Footprint and its Peaks).
66  FLUX_ORDER flux algorithms that require both getShape() and getCentroid(),
67  in addition to a Footprint and its Peaks
68  DEFAULT_CATALOGCALCULATION plugins that only operate on the catalog
69 
70  Must be reimplemented as a class method by concrete derived classes.
71 
72  This approach was chosen instead of a full graph-based analysis of dependencies
73  because algorithm dependencies are usually both quite simple and entirely substitutable:
74  an algorithm that requires a centroid can typically make use of any centroid algorithms
75  outputs. That makes it relatively easy to figure out the correct value to use for any
76  particular algorithm.
77  """
78  raise NotImplementedError("All plugins must implement getExecutionOrder()")
79 
80  def __init__(self, config, name, logName=None):
81  """!
82  Initialize the plugin object.
83 
84  @param[in] config An instance of this class's ConfigClass.
85  @param[in] name The string the plugin was registered with.
86  """
87  object.__init__(self)
88  self.config = config
89  self.name = name
90  self.logName = logName
91 
92  def getLogName(self):
93  return self.logName
94 
95  def fail(self, measRecord, error=None):
96  """!
97  Record a failure of the measure or measureN() method.
98 
99  When the plugin raises an exception, framework will call
100  fail() to allow the plugin to set its failure flag
101  field(s). When measureN() raises an exception, fail() will be
102  called repeatedly with all the records that were being
103  measured.
104 
105  If the exception is a MeasurementError, it will be passed as
106  the error argument; in all other cases the error argument will
107  be None, and the failure will be logged by the measurement
108  framework as a warning.
109  """
110  traceback.print_exc()
111  message = ("The algorithm '%s' thinks it cannot fail, but it did; "
112  "please report this as a bug (the full traceback is above)."
113  % (self.__class__.__name__,))
114  raise NotImplementedError(message)
115 
116  @staticmethod
118  """!
119  Get the measurement transformation appropriate to this plugin.
120 
121  This returns a subclass of MeasurementTransform, which may be
122  instantiated with details of the algorithm configuration and then
123  called with information about calibration and WCS to convert from raw
124  measurement quantities to calibrated units. Calibrated data is then
125  provided in a separate output table.
126 
127  By default, we copy everything from the input to the output without
128  transformation.
129  """
130  return PassThroughTransform
def __init__(self, config, name, logName=None)
Initialize the plugin object.
Definition: pluginsBase.py:80
Base class for measurement plugins.
Definition: pluginsBase.py:42
Base class measurement Plugin config classes.
Definition: pluginsBase.py:33
def getTransformClass()
Get the measurement transformation appropriate to this plugin.
Definition: pluginsBase.py:117
def fail(self, measRecord, error=None)
Record a failure of the measure or measureN() method.
Definition: pluginsBase.py:95