Skip to content

Commit

Permalink
Remove aperture corrections from measurements
Browse files Browse the repository at this point in the history
Remove all the logic of aperture corrections from the measurement plugins.
In the future MeasureApCorr and ApplyApCorr tasks should be called directly
when that functionality is required.
  • Loading branch information
natelust committed Jun 23, 2016
1 parent 4f6601e commit c1e5048
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 99 deletions.
64 changes: 0 additions & 64 deletions python/lsst/meas/base/baseMeasurement.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import lsst.pipe.base
import lsst.pex.config

from .applyApCorr import ApplyApCorrTask
from .pluginRegistry import PluginMap
from .baseLib import FatalAlgorithmError, MeasurementError
from .pluginsBase import BasePluginConfig, BasePlugin
Expand Down Expand Up @@ -122,25 +121,6 @@ class BaseMeasurementConfig(lsst.pex.config.Config):
doc="configuration that sets how to replace neighboring sources with noise"
)

doApplyApCorr = lsst.pex.config.ChoiceField(
dtype = str,
doc = "Apply aperture corrections? Silently ignored if endOrder <= lsst.meas.base.APCORR_ORDER"
" when calling run",
default = "noButWarn",
allowed = {
"yes": "apply aperture corrections; fail if data not available",
"yesOrWarn": "apply aperture corrections if data available, else warn",
"noButWarn": "do not apply aperture corrections, but warn if data available"
" (since aperture corrections could have been applied)",
"no": "do not apply aperture corrections",
},
)

applyApCorr = lsst.pex.config.ConfigurableField(
target = ApplyApCorrTask,
doc = "subtask to apply aperture corrections",
)

def validate(self):
lsst.pex.config.Config.validate(self)
if self.slots.centroid is not None and self.slots.centroid not in self.plugins.names:
Expand Down Expand Up @@ -168,11 +148,6 @@ class BaseMeasurementTask(lsst.pipe.base.Task):
This base class for SingleFrameMeasurementTask and ForcedMeasurementTask mostly exists to share
code between the two, and generally should not be used directly.
@note Tasks that use this task should usually set the default value of config parameter doApplyApCorr
to "yes" or "no", depending if aperture corrections are wanted. The default value of "noButWarn"
is intended to alert users who forget, and is appropriate for unit tests and temporary scripts
that do not need aperture corrections.
"""

ConfigClass = BaseMeasurementConfig
Expand Down Expand Up @@ -307,42 +282,3 @@ def callMeasureN(self, measCat, *args, **kwds):
plugin.fail(measRecord)
self.log.warn("Error in %s.measureN on records %s-%s: %s"
% (plugin.name, measCat[0].getId(), measCat[-1].getId(), error))

def _applyApCorrIfWanted(self, sources, apCorrMap, endOrder):
"""!Apply aperture corrections to a catalog, if wanted
This method is intended to be called at the end of every subclass's run method or other
measurement sequence. This is a thin wrapper around self.applyApCorr.run.
@param[in,out] sources catalog of sources to which to apply aperture corrections
@param[in] apCorrMap aperture correction map (lsst.afw.image.ApCorrMap) or None;
typically found in an lsst.afw.image.ExposureInfo
if provided then it must contain 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
@param[in] endOrder ending execution order, or None; if provided then aperture corrections
are only wanted if endOrder > lsst.meas.base.BasePlugin.APCORR_ORDER
@return the results from applyApCorr if run, else None
@throw lsst.pipe.base.TaskError if aperture corrections are wanted and the exposure does not contain
an aperture correction map.
"""
if endOrder is not None and endOrder <= BasePlugin.APCORR_ORDER:
# it is not appropriate to apply aperture corrections
return

if self.config.doApplyApCorr.startswith("yes"):
if apCorrMap is not None:
self.applyApCorr.run(catalog=sources, apCorrMap=apCorrMap)
else:
errMsg = "Cannot apply aperture corrections; apCorrMap is None"
if self.config.doApplyApCorr == "yesOrWarn":
self.log.warn(errMsg)
else:
raise lsst.pipe.base.TaskError(errMsg)
elif self.config.doApplyApCorr == "noButWarn":
if apCorrMap is not None:
self.log.warn("Aperture corrections are disabled but the data to apply them is available;"
" change doApplyApCorr to suppress this warning")


11 changes: 1 addition & 10 deletions python/lsst/meas/base/forcedMeasurement.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,9 @@ def __init__(self, refSchema, algMetadata=None, **kwds):
self.config.slots.setupSchema(self.mapper.editOutputSchema())
self.initializePlugins(schemaMapper=self.mapper)
self.schema = self.mapper.getOutputSchema()
self.makeSubtask("applyApCorr", schema=self.schema)
self.schema.checkUnits(parse_strict=self.config.checkUnitsParseStrict)

def run(self, measCat, exposure, refCat, refWcs, exposureId=None, beginOrder=None, endOrder=None,
allowApCorr=True):
def run(self, measCat, exposure, refCat, refWcs, exposureId=None, beginOrder=None, endOrder=None):
"""!
Perform forced measurement.
Expand All @@ -257,7 +255,6 @@ def run(self, measCat, exposure, refCat, refWcs, exposureId=None, beginOrder=Non
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] allowApCorr allow application of aperture correction?
Fills the initial empty SourceCatalog with forced measurement results. Two steps must occur
before run() can be called:
Expand Down Expand Up @@ -335,12 +332,6 @@ def run(self, measCat, exposure, refCat, refWcs, exposureId=None, beginOrder=Non
noiseReplacer.removeSource(refParentRecord.getId())
noiseReplacer.end()

if allowApCorr:
self._applyApCorrIfWanted(
sources = measCat,
apCorrMap = exposure.getInfo().getApCorrMap(),
endOrder = endOrder,
)

def generateMeasCat(self, exposure, refCat, refWcs, idFactory=None):
"""!Initialize an output SourceCatalog using information from the reference catalog.
Expand Down
13 changes: 1 addition & 12 deletions python/lsst/meas/base/forcedPhotImage.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ class ProcessImageForcedConfig(lsst.pex.config.Config):
default={"id": "objectId", "parent": "parentObjectId", "deblend_nChild": "deblend_nChild"}
)

def setDefaults(self):
self.measurement.doApplyApCorr = "yes"

## @addtogroup LSST_task_documentation
## @{
## @page ProcessImageForcedTask
Expand Down Expand Up @@ -125,15 +122,7 @@ def run(self, dataRef):
self.log.info("Performing forced measurement on %s" % dataRef.dataId)
self.attachFootprints(measCat, refCat, exposure, refWcs, dataRef)

# First run plugins with order up to and including APCORR_ORDER to measure all fluxes
# and apply the aperture correction (using the apCorrMap measured in the calibration
# task) to the measured fluxes whose plugins were registered with shouldApCorr=True
self.measurement.run(measCat, exposure, refCat, refWcs, exposureId=self.getExposureId(dataRef),
endOrder=BasePlugin.APCORR_ORDER+1)
# Now run the remaining APCORR_ORDER+1 plugins (whose measurements should be performed on
# aperture corrected fluxes) disallowing apCorr (to avoid applying it more than once)
self.measurement.run(measCat, exposure, refCat, refWcs, exposureId=self.getExposureId(dataRef),
beginOrder=BasePlugin.APCORR_ORDER+1, allowApCorr=False)
self.measurement.run(measCat, exposure, refCat, refWcs, exposureId=self.getExposureId(dataRef))

self.writeOutput(dataRef, measCat)

Expand Down
14 changes: 1 addition & 13 deletions python/lsst/meas/base/sfm.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ class SingleFrameMeasurementConfig(BaseMeasurementConfig):
"base_GaussianFlux",
"base_PsfFlux",
"base_CircularApertureFlux",
"base_ClassificationExtendedness",
"base_SkyCoord",
"base_Variance",
],
Expand Down Expand Up @@ -247,7 +246,6 @@ def __init__(self, schema, algMetadata=None, **kwds):
self.schema = schema
self.config.slots.setupSchema(self.schema)
self.initializePlugins(schema=self.schema)
self.makeSubtask("applyApCorr", schema=self.schema)

# Check to see if blendedness is one of the plugins
if 'base_Blendedness' in self.plugins:
Expand All @@ -256,8 +254,7 @@ def __init__(self, schema, algMetadata=None, **kwds):
else:
self.doBlendedness = False

def run(self, measCat, exposure, noiseImage=None, exposureId=None, beginOrder=None, endOrder=None,
allowApCorr=True):
def run(self, measCat, exposure, noiseImage=None, exposureId=None, beginOrder=None, endOrder=None):
"""!
Run single frame measurement over an exposure and source catalog
Expand All @@ -275,7 +272,6 @@ def run(self, measCat, exposure, noiseImage=None, exposureId=None, beginOrder=No
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] allowApCorr allow application of aperture correction?
"""
# Temporary workaround for change in order of arguments; will be removed when transition
# from meas_algorithms to meas_base is complete.
Expand Down Expand Up @@ -345,14 +341,6 @@ def run(self, measCat, exposure, noiseImage=None, exposureId=None, beginOrder=No
if self.doBlendedness:
self.blendPlugin.cpp.measureParentPixels(exposure.getMaskedImage(), source)


if allowApCorr:
self._applyApCorrIfWanted(
sources = measCat,
apCorrMap = exposure.getInfo().getApCorrMap(),
endOrder = endOrder,
)

def measure(self, measCat, exposure):
"""!
Backwards-compatibility alias for run()
Expand Down

0 comments on commit c1e5048

Please sign in to comment.