LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
Public Member Functions | Public Attributes | Static Public Attributes | Static Private Attributes | List of all members
lsst.meas.base.measureApCorr.MeasureApCorrTask Class Reference

Task to measure aperture correction. More...

Inheritance diagram for lsst.meas.base.measureApCorr.MeasureApCorrTask:

Public Member Functions

def __init__
 Construct a MeasureApCorrTask. More...
 
def run
 Measure aperture correction. More...
 

Public Attributes

 refFluxKeys
 
 toCorrect
 
 inputFilterFlag
 

Static Public Attributes

 ConfigClass = MeasureApCorrConfig
 

Static Private Attributes

string _DefaultName = "measureApCorr"
 

Detailed Description

Task to measure aperture correction.

Contents

Description

Task to measure aperture correction.

This task measures aperture correction for the flux fields returned by lsst.meas.base.getApCorrNameSet()

The main method is run.

Configuration parameters

See MeasureApCorrConfig

Debug variables

This task has no debug variables.

Definition at line 98 of file measureApCorr.py.

Constructor & Destructor Documentation

def lsst.meas.base.measureApCorr.MeasureApCorrTask.__init__ (   self,
  schema,
  kwds 
)

Construct a MeasureApCorrTask.

For every name in lsst.meas.base.getApCorrNameSet():

  • If the corresponding flux fields exist in the schema:
    • Add a new field apcorr_{name}_used
    • Add an entry to the self.toCorrect dict
  • Otherwise silently skip the name

Definition at line 127 of file measureApCorr.py.

128  def __init__(self, schema, **kwds):
129  """!Construct a MeasureApCorrTask
130 
131  For every name in lsst.meas.base.getApCorrNameSet():
132  - If the corresponding flux fields exist in the schema:
133  - Add a new field apcorr_{name}_used
134  - Add an entry to the self.toCorrect dict
135  - Otherwise silently skip the name
136  """
137  Task.__init__(self, **kwds)
138  self.refFluxKeys = FluxKeys(self.config.refFluxName, schema)
139  self.toCorrect = {} # dict of flux field name prefix: FluxKeys instance
140  for name in getApCorrNameSet():
141  try:
142  self.toCorrect[name] = FluxKeys(name, schema)
143  except KeyError:
144  # if a field in the registry is missing, just ignore it.
145  pass
146  self.inputFilterFlag = schema.find(self.config.inputFilterFlag).key
def getApCorrNameSet
Return a copy of the set of field name prefixes for fluxes that should be aperture corrected...
def __init__
Construct a MeasureApCorrTask.

Member Function Documentation

def lsst.meas.base.measureApCorr.MeasureApCorrTask.run (   self,
  bbox,
  catalog 
)

Measure aperture correction.

Returns
an lsst.pipe.base.Struct containing:
  • apCorrMap: an aperture correction map (lsst.afw.image.ApCorrMap) that contains two entries for each flux field:
    • flux field (e.g. base_PsfFlux_flux): 2d model
    • flux sigma field (e.g. base_PsfFlux_fluxSigma): 2d model of error

Definition at line 147 of file measureApCorr.py.

148  def run(self, bbox, catalog):
149  """!Measure aperture correction
150 
151  @return an lsst.pipe.base.Struct containing:
152  - apCorrMap: an aperture correction map (lsst.afw.image.ApCorrMap) that contains two entries
153  for each flux field:
154  - flux field (e.g. base_PsfFlux_flux): 2d model
155  - flux sigma field (e.g. base_PsfFlux_fluxSigma): 2d model of error
156  """
157  self.log.info("Measuring aperture corrections for %d flux fields" % (len(self.toCorrect),))
158  # First, create a subset of the catalog that contains only objects with inputFilterFlag set
159  # and non-flagged reference fluxes.
160  subset1 = [record for record in catalog
161  if record.get(self.inputFilterFlag) and not record.get(self.refFluxKeys.flag)]
162 
163  apCorrMap = ApCorrMap()
164 
165  # Outer loop over the fields we want to correct
166  for name, keys in self.toCorrect.iteritems():
167  fluxName = name + "_flux"
168  fluxSigmaName = name + "_fluxSigma"
169 
170  # Create a more restricted subset with only the objects where the to-be-correct flux
171  # is not flagged.
172  subset2 = [record for record in subset1 if not record.get(keys.flag)]
173 
174  # Check that we have enough data points that we have at least the minimum of degrees of
175  # freedom specified in the config.
176  if len(subset2) - 1 < self.config.minDegreesOfFreedom:
177  self.log.warn("Only %d sources for calculation of aperture correction for '%s'; "
178  "setting to 1.0" % (len(subset2), name,))
179  apCorrMap[fluxName] = ChebyshevBoundedField(bbox, numpy.ones((1,1), dtype=float))
180  apCorrMap[fluxSigmaName] = ChebyshevBoundedField(bbox, numpy.zeros((1,1), dtype=float))
181  continue
182 
183  # If we don't have enough data points to constrain the fit, reduce the order until we do
184  ctrl = self.config.fitConfig.makeControl()
185  while len(subset2) - ctrl.computeSize() < self.config.minDegreesOfFreedom:
186  if ctrl.orderX > 0:
187  ctrl.orderX -= 1
188  if ctrl.orderY > 0:
189  ctrl.orderY -= 1
190 
191  # Fill numpy arrays with positions and the ratio of the reference flux to the to-correct flux
192  x = numpy.zeros(len(subset2), dtype=float)
193  y = numpy.zeros(len(subset2), dtype=float)
194  apCorrData = numpy.zeros(len(subset2), dtype=float)
195  indices = numpy.arange(len(subset2), dtype=int)
196  for n, record in enumerate(subset2):
197  x[n] = record.getX()
198  y[n] = record.getY()
199  apCorrData[n] = record.get(self.refFluxKeys.flux)/record.get(keys.flux)
200 
201  for _i in range(self.config.numIter):
202 
203  # Do the fit, save it in the output map
204  apCorrField = ChebyshevBoundedField.fit(bbox, x, y, apCorrData, ctrl)
205 
206  # Compute errors empirically, using the RMS difference between the true reference flux and the
207  # corrected to-be-corrected flux.
208  apCorrDiffs = apCorrField.evaluate(x, y)
209  apCorrDiffs -= apCorrData
210  apCorrErr = numpy.mean(apCorrDiffs**2)**0.5
211 
212  # Clip bad data points
213  apCorrDiffLim = self.config.numSigmaClip * apCorrErr
214  keep = numpy.fabs(apCorrDiffs) < apCorrDiffLim
215  x = x[keep]
216  y = y[keep]
217  apCorrData = apCorrData[keep]
218  indices = indices[keep]
219 
220  # Final fit after clipping
221  apCorrField = ChebyshevBoundedField.fit(bbox, x, y, apCorrData, ctrl)
222 
223  self.log.info("Aperture correction for %s: RMS %f from %d" %
224  (name, numpy.mean((apCorrField.evaluate(x, y) - apCorrData)**2)**0.5, len(indices)))
225 
226  # Save the result in the output map
227  # The error is constant spatially (we could imagine being
228  # more clever, but we're not yet sure if it's worth the effort).
229  # We save the errors as a 0th-order ChebyshevBoundedField
230  apCorrMap[fluxName] = apCorrField
231  apCorrErrCoefficients = numpy.array([[apCorrErr]], dtype=float)
232  apCorrMap[fluxSigmaName] = ChebyshevBoundedField(bbox, apCorrErrCoefficients)
233 
234  # Record which sources were used
235  for i in indices:
236  subset2[i].set(keys.used, True)
237 
238  return Struct(
239  apCorrMap = apCorrMap,
240  )
A thin wrapper around std::map to allow aperture corrections to be attached to Exposures.
Definition: ApCorrMap.h:42
def run
Measure aperture correction.
A BoundedField based on 2-d Chebyshev polynomials of the first kind.

Member Data Documentation

string lsst.meas.base.measureApCorr.MeasureApCorrTask._DefaultName = "measureApCorr"
staticprivate

Definition at line 125 of file measureApCorr.py.

lsst.meas.base.measureApCorr.MeasureApCorrTask.ConfigClass = MeasureApCorrConfig
static

Definition at line 124 of file measureApCorr.py.

lsst.meas.base.measureApCorr.MeasureApCorrTask.inputFilterFlag

Definition at line 145 of file measureApCorr.py.

lsst.meas.base.measureApCorr.MeasureApCorrTask.refFluxKeys

Definition at line 137 of file measureApCorr.py.

lsst.meas.base.measureApCorr.MeasureApCorrTask.toCorrect

Definition at line 138 of file measureApCorr.py.


The documentation for this class was generated from the following file: