MatchBackgroundsTask¶
- class lsst.pipe.tasks.matchBackgrounds.MatchBackgroundsTask(*args, **kwargs)¶
Bases:
Task
Methods Summary
Empty (clear) the metadata for this Task and all sub-Tasks.
Get metadata for all tasks.
Get the task name as a hierarchical name including parent task names.
getName
()Get the name of the task.
Get a dictionary of all tasks as a shallow copy.
makeField
(doc)Make a
lsst.pex.config.ConfigurableField
for this task.makeSubtask
(name, **keyArgs)Create a subtask as a new instance as the
name
attribute of this task.matchBackgrounds
(refExposure, sciExposure)Match science exposure's background level to that of reference exposure.
run
(expRefList, expDatasetType[, ...])Match the backgrounds of a list of coadd temp exposures to a reference coadd temp exposure.
selectRefExposure
(expRefList, ...)Find best exposure to use as the reference exposure.
timer
(name[, logLevel])Context manager to log performance data for an arbitrary block of code.
Methods Documentation
- getFullMetadata() TaskMetadata ¶
Get metadata for all tasks.
- Returns:
- metadata
TaskMetadata
The keys are the full task name. Values are metadata for the top-level task and all subtasks, sub-subtasks, etc.
- metadata
Notes
The returned metadata includes timing information (if
@timer.timeMethod
is used) and any metadata set by the task. The name of each item consists of the full task name with.
replaced by:
, followed by.
and the name of the item, e.g.:topLevelTaskName:subtaskName:subsubtaskName.itemName
using
:
in the full task name disambiguates the rare situation that a task has a subtask and a metadata item with the same name.
- getFullName() str ¶
Get the task name as a hierarchical name including parent task names.
- Returns:
- fullName
str
The full name consists of the name of the parent task and each subtask separated by periods. For example:
The full name of top-level task “top” is simply “top”.
The full name of subtask “sub” of top-level task “top” is “top.sub”.
The full name of subtask “sub2” of subtask “sub” of top-level task “top” is “top.sub.sub2”.
- fullName
- getTaskDict() dict[str, weakref.ReferenceType[lsst.pipe.base.task.Task]] ¶
Get a dictionary of all tasks as a shallow copy.
- Returns:
- taskDict
dict
Dictionary containing full task name: task object for the top-level task and all subtasks, sub-subtasks, etc.
- taskDict
- classmethod makeField(doc: str) ConfigurableField ¶
Make a
lsst.pex.config.ConfigurableField
for this task.- Parameters:
- doc
str
Help text for the field.
- doc
- Returns:
- configurableField
lsst.pex.config.ConfigurableField
A
ConfigurableField
for this task.
- configurableField
Examples
Provides a convenient way to specify this task is a subtask of another task.
Here is an example of use:
class OtherTaskConfig(lsst.pex.config.Config): aSubtask = ATaskClass.makeField("brief description of task")
- makeSubtask(name: str, **keyArgs: Any) None ¶
Create a subtask as a new instance as the
name
attribute of this task.- Parameters:
- name
str
Brief name of the subtask.
- **keyArgs
Extra keyword arguments used to construct the task. The following arguments are automatically provided and cannot be overridden:
config
.parentTask
.
- name
Notes
The subtask must be defined by
Task.config.name
, an instance ofConfigurableField
orRegistryField
.
- matchBackgrounds(refExposure, sciExposure)¶
Match science exposure’s background level to that of reference exposure.
Process creates a difference image of the reference exposure minus the science exposure, and then generates an afw.math.Background object. It assumes (but does not require/check) that the mask plane already has detections set. If detections have not been set/masked, sources will bias the background estimation.
The ‘background’ of the difference image is smoothed by spline interpolation (by the Background class) or by polynomial interpolation by the Approximate class. This model of difference image is added to the science exposure in memory.
Fit diagnostics are also calculated and returned.
- Parameters:
- refExposure
lsst.afw.image.Exposure
Reference exposure.
- sciExposure
lsst.afw.image.Exposure
Science exposure; modified by changing the background level to match that of the reference exposure.
- refExposure
- Returns:
- model
lsst.pipe.base.Struct
Background model as a struct with attributes:
backgroundModel
An afw.math.Approximate or an afw.math.Background.
fitRMS
RMS of the fit. This is the sqrt(mean(residuals**2)), (
float
).matchedMSE
The MSE of the reference and matched images: mean((refImage - matchedSciImage)**2); should be comparable to difference image’s mean variance (
float
).diffImVar
The mean variance of the difference image (
float
).
- model
- run(expRefList, expDatasetType, imageScalerList=None, refExpDataRef=None, refImageScaler=None)¶
Match the backgrounds of a list of coadd temp exposures to a reference coadd temp exposure.
Choose a refExpDataRef automatically if none supplied.
- Parameters:
- expRefList
list
List of data references to science exposures to be background-matched; all exposures must exist.
- expDatasetType
str
Dataset type of exposures, e.g. ‘goodSeeingCoadd_tempExp’.
- imageScalerList
list
, optional List of image scalers (coaddUtils.ImageScaler); if None then the images are not scaled.
- refExpDataRef
Unknown
, optional Data reference for the reference exposure. If None, then this task selects the best exposures from expRefList. If not None then must be one of the exposures in expRefList.
- refImageScaler
Unknown
, optional Image scaler for reference image; ignored if refExpDataRef is None, else scaling is not performed if None.
- expRefList
- Returns:
- result
lsst.pipe.base.Struct
Results as a struct with attributes:
backgroundInfoList
A
list
ofpipeBase.Struct
, one per exposure in expRefList, each of which contains these fields: -isReference
: This is the reference exposure (only onereturned Struct will contain True for this value, unless the ref exposure is listed multiple times).
backgroundModel
: Differential background model(afw.Math.Background or afw.Math.Approximate). Add this to the science exposure to match the reference exposure.
fitRMS
: The RMS of the fit. This is the sqrt(mean(residuals**2)).matchedMSE
: The MSE of the reference and matched images:mean((refImage - matchedSciImage)**2);
should be comparable to difference image’s mean variance.
diffImVar
: The mean variance of the difference image.
All fields except isReference will be None if isReference True or the fit failed.
- result
- Raises:
- RuntimeError
Raised if an exposure does not exist on disk.
- selectRefExposure(expRefList, imageScalerList, expDatasetType)¶
Find best exposure to use as the reference exposure.
Calculate an appropriate reference exposure by minimizing a cost function that penalizes high variance, high background level, and low coverage. Use the following config parameters: - bestRefWeightCoverage - bestRefWeightVariance - bestRefWeightLevel
- Parameters:
- expRefList
list
List of data references to exposures. Retrieves dataset type specified by expDatasetType. If an exposure is not found, it is skipped with a warning.
- imageScalerList
list
List of image scalers (coaddUtils.ImageScaler); must be the same length as expRefList.
- expDatasetType
str
Dataset type of exposure: e.g. ‘goodSeeingCoadd_tempExp’.
- expRefList
- Returns:
- bestIdx
int
Index of best exposure.
- bestIdx
- Raises:
- RuntimeError
Raised if none of the exposures in expRefList are found.