LSSTApplications  11.0-13-gbb96280,12.1.rc1,12.1.rc1+1,12.1.rc1+2,12.1.rc1+5,12.1.rc1+8,12.1.rc1-1-g06d7636+1,12.1.rc1-1-g253890b+5,12.1.rc1-1-g3d31b68+7,12.1.rc1-1-g3db6b75+1,12.1.rc1-1-g5c1385a+3,12.1.rc1-1-g83b2247,12.1.rc1-1-g90cb4cf+6,12.1.rc1-1-g91da24b+3,12.1.rc1-2-g3521f8a,12.1.rc1-2-g39433dd+4,12.1.rc1-2-g486411b+2,12.1.rc1-2-g4c2be76,12.1.rc1-2-gc9c0491,12.1.rc1-2-gda2cd4f+6,12.1.rc1-3-g3391c73+2,12.1.rc1-3-g8c1bd6c+1,12.1.rc1-3-gcf4b6cb+2,12.1.rc1-4-g057223e+1,12.1.rc1-4-g19ed13b+2,12.1.rc1-4-g30492a7
LSSTDataManagementBasePackage
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):
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 
91  def fail(self, measRecord, error=None):
92  """!
93  Record a failure of the measure or measureN() method.
94 
95  When the plugin raises an exception, framework will call
96  fail() to allow the plugin to set its failure flag
97  field(s). When measureN() raises an exception, fail() will be
98  called repeatedly with all the records that were being
99  measured.
100 
101  If the exception is a MeasurementError, it will be passed as
102  the error argument; in all other cases the error argument will
103  be None, and the failure will be logged by the measurement
104  framework as a warning.
105  """
106  traceback.print_exc()
107  message = ("The algorithm '%s' thinks it cannot fail, but it did; "
108  "please report this as a bug (the full traceback is above)."
109  % (self.__class__.__name__,))
110  raise NotImplementedError(message)
111 
112  @staticmethod
114  """!
115  Get the measurement transformation appropriate to this plugin.
116 
117  This returns a subclass of MeasurementTransform, which may be
118  instantiated with details of the algorithm configuration and then
119  called with information about calibration and WCS to convert from raw
120  measurement quantities to calibrated units. Calibrated data is then
121  provided in a separate output table.
122 
123  By default, we copy everything from the input to the output without
124  transformation.
125  """
126  return PassThroughTransform
def getTransformClass
Get the measurement transformation appropriate to this plugin.
Definition: pluginsBase.py:113
Base class for measurement plugins.
Definition: pluginsBase.py:42
def __init__
Initialize the plugin object.
Definition: pluginsBase.py:80
Base class measurement Plugin config classes.
Definition: pluginsBase.py:33
def fail
Record a failure of the measure or measureN() method.
Definition: pluginsBase.py:91