AssembleCoaddTask

class lsst.pipe.tasks.assembleCoadd.AssembleCoaddTask(*args, **kwargs)

Bases: lsst.pipe.tasks.coaddBase.CoaddBaseTask, lsst.pipe.base.PipelineTask

Assemble a coadded image from a set of warps.

Each Warp that goes into a coadd will typically have an independent photometric zero-point. Therefore, we must scale each Warp to set it to a common photometric zeropoint. WarpType may be one of ‘direct’ or ‘psfMatched’, and the boolean configs config.makeDirect and config.makePsfMatched set which of the warp types will be coadded. The coadd is computed as a mean with optional outlier rejection. Criteria for outlier rejection are set in AssembleCoaddConfig. Finally, Warps can have bad ‘NaN’ pixels which received no input from the source calExps. We interpolate over these bad (NaN) pixels.

AssembleCoaddTask uses several sub-tasks. These are

  • ScaleZeroPointTask
  • create and use an imageScaler object to scale the photometric zeropoint for each Warp
  • InterpImageTask
  • interpolate across bad pixels (NaN) in the final coadd

You can retarget these subtasks if you wish.

Raises:
RuntimeError

Raised if unable to define mask plane for bright objects.

Notes

Debugging: AssembleCoaddTask has no debug variables of its own. Some of the subtasks may support lsstDebug variables. See the documentation for the subtasks for further information.

Examples

AssembleCoaddTask assembles a set of warped images into a coadded image. The AssembleCoaddTask can be invoked by running assembleCoadd.py with the flag ‘–legacyCoadd’. Usage of assembleCoadd.py expects two inputs: a data reference to the tract patch and filter to be coadded, and a list of Warps to attempt to coadd. These are specified using --id and --selectId, respectively:

--id = [KEY=VALUE1[^VALUE2[^VALUE3...] [KEY=VALUE1[^VALUE2[^VALUE3...] ...]]
--selectId [KEY=VALUE1[^VALUE2[^VALUE3...] [KEY=VALUE1[^VALUE2[^VALUE3...] ...]]

Only the Warps that cover the specified tract and patch will be coadded. A list of the available optional arguments can be obtained by calling assembleCoadd.py with the --help command line argument:

assembleCoadd.py --help

To demonstrate usage of the AssembleCoaddTask in the larger context of multi-band processing, we will generate the HSC-I & -R band coadds from HSC engineering test data provided in the ci_hsc package. To begin, assuming that the lsst stack has been already set up, we must set up the obs_subaru and ci_hsc packages. This defines the environment variable $CI_HSC_DIR and points at the location of the package. The raw HSC data live in the $CI_HSC_DIR/raw directory. To begin assembling the coadds, we must first run:

  • processCcd
  • process the individual ccds in $CI_HSC_RAW to produce calibrated exposures
  • makeSkyMap
  • create a skymap that covers the area of the sky present in the raw exposures
  • makeCoaddTempExp
  • warp the individual calibrated exposures to the tangent plane of the coadd

We can perform all of these steps by running

$CI_HSC_DIR scons warp-903986 warp-904014 warp-903990 warp-904010 warp-903988

This will produce warped exposures for each visit. To coadd the warped data, we call assembleCoadd.py as follows:

assembleCoadd.py --legacyCoadd $CI_HSC_DIR/DATA --id patch=5,4 tract=0 filter=HSC-I        --selectId visit=903986 ccd=16 --selectId visit=903986 ccd=22 --selectId visit=903986 ccd=23        --selectId visit=903986 ccd=100 --selectId visit=904014 ccd=1 --selectId visit=904014 ccd=6        --selectId visit=904014 ccd=12 --selectId visit=903990 ccd=18 --selectId visit=903990 ccd=25        --selectId visit=904010 ccd=4 --selectId visit=904010 ccd=10 --selectId visit=904010 ccd=100        --selectId visit=903988 ccd=16 --selectId visit=903988 ccd=17 --selectId visit=903988 ccd=23        --selectId visit=903988 ccd=24

that will process the HSC-I band data. The results are written in $CI_HSC_DIR/DATA/deepCoadd-results/HSC-I.

You may also choose to run:

scons warp-903334 warp-903336 warp-903338 warp-903342 warp-903344 warp-903346
assembleCoadd.py --legacyCoadd $CI_HSC_DIR/DATA --id patch=5,4 tract=0 filter=HSC-R        --selectId visit=903334 ccd=16 --selectId visit=903334 ccd=22 --selectId visit=903334 ccd=23        --selectId visit=903334 ccd=100 --selectId visit=903336 ccd=17 --selectId visit=903336 ccd=24        --selectId visit=903338 ccd=18 --selectId visit=903338 ccd=25 --selectId visit=903342 ccd=4        --selectId visit=903342 ccd=10 --selectId visit=903342 ccd=100 --selectId visit=903344 ccd=0        --selectId visit=903344 ccd=5 --selectId visit=903344 ccd=11 --selectId visit=903346 ccd=1        --selectId visit=903346 ccd=6 --selectId visit=903346 ccd=12

to generate the coadd for the HSC-R band if you are interested in following multiBand Coadd processing as discussed in pipeTasks_multiBand (but note that normally, one would use the SafeClipAssembleCoaddTask rather than AssembleCoaddTask to make the coadd.

Attributes Summary

canMultiprocess

Methods Summary

applyAltMaskPlanes(mask, altMaskSpans) Apply in place alt mask formatted as SpanSets to a mask.
assembleMetadata(coaddExposure, …) Set the metadata for the coadd.
assembleOnlineMeanCoadd(coaddExposure, …) Assemble the coadd using the “online” method.
assembleSubregion(coaddExposure, bbox, …) Assemble the coadd for a sub-region.
emptyMetadata() Empty (clear) the metadata for this Task and all sub-Tasks.
filterWarps(inputs, goodVisits) Return list of only inputRefs with visitId in goodVisits ordered by goodVisit.
getAllSchemaCatalogs() Get schema catalogs for all tasks in the hierarchy, combining the results into a single dict.
getBadPixelMask() Convenience method to provide the bitmask from the mask plane names
getFullMetadata() Get metadata for all tasks.
getFullName() Get the task name as a hierarchical name including parent task names.
getName() Get the name of the task.
getResourceConfig() Return resource configuration for this task.
getSchemaCatalogs() Get the schemas generated by this task.
getSkyInfo(patchRef) Use getSkyinfo to return the skyMap, tract and patch information, wcs and the outer bbox of the patch.
getTaskDict() Get a dictionary of all tasks as a shallow copy.
getTempExpDatasetName([warpType]) Return warp name for given warpType and task config
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.
makeSupplementaryDataGen3(butlerQC, …)

Deprecated since version v25.0.

prepareInputs(refList) Prepare the input warps for coaddition by measuring the weight for each warp and the scaling for the photometric zero point.
prepareStats([mask]) Prepare the statistics for coadding images.
processResults(coaddExposure[, …]) Interpolate over missing data and mask bright stars.
removeMaskPlanes(maskedImage) Unset the mask of an image for mask planes specified in the config.
run(skyInfo, tempExpRefList, …[, …]) Assemble a coadd from input warps.
runQuantum(butlerQC, inputRefs, outputRefs) Method to do butler IO and or transforms to provide in memory objects for tasks run method
setBrightObjectMasks(exposure, brightObjectMasks) Set the bright object masks.
setInexactPsf(mask) Set INEXACT_PSF mask plane.
setRejectedMaskMapping(statsCtrl) Map certain mask planes of the warps to new planes for the coadd.
shrinkValidPolygons(coaddInputs) Shrink coaddInputs’ ccds’ ValidPolygons in place.
timer(name, logLevel) Context manager to log performance data for an arbitrary block of code.

Attributes Documentation

canMultiprocess = True

Methods Documentation

applyAltMaskPlanes(mask, altMaskSpans)

Apply in place alt mask formatted as SpanSets to a mask.

Parameters:
mask : lsst.afw.image.Mask

Original mask.

altMaskSpans : dict

SpanSet lists to apply. Each element contains the new mask plane name (e.g. “CLIPPED and/or “NO_DATA”) as the key, and list of SpanSets to apply to the mask.

Returns:
mask : lsst.afw.image.Mask

Updated mask.

assembleMetadata(coaddExposure, tempExpRefList, weightList)

Set the metadata for the coadd.

This basic implementation sets the filter from the first input.

Parameters:
coaddExposure : lsst.afw.image.Exposure

The target exposure for the coadd.

tempExpRefList : list

List of data references to tempExp.

weightList : list

List of weights.

Raises:
AssertionError

Raised if there is a length mismatch.

assembleOnlineMeanCoadd(coaddExposure, tempExpRefList, imageScalerList, weightList, altMaskList, statsCtrl, nImage=None)

Assemble the coadd using the “online” method.

This method takes a running sum of images and weights to save memory. It only works for MEAN statistics.

Parameters:
coaddExposure : lsst.afw.image.Exposure

The target exposure for the coadd.

tempExpRefList : list

List of data reference to tempExp.

imageScalerList : list

List of image scalers.

weightList : list

List of weights.

altMaskList : list

List of alternate masks to use rather than those stored with tempExp, or None. Each element is dict with keys = mask plane name to which to add the spans.

statsCtrl : lsst.afw.math.StatisticsControl

Statistics control object for coadd.

nImage : lsst.afw.image.ImageU, optional

Keeps track of exposure count for each pixel.

assembleSubregion(coaddExposure, bbox, tempExpRefList, imageScalerList, weightList, altMaskList, statsFlags, statsCtrl, nImage=None)

Assemble the coadd for a sub-region.

For each coaddTempExp, check for (and swap in) an alternative mask if one is passed. Remove mask planes listed in config.removeMaskPlanes. Finally, stack the actual exposures using lsst.afw.math.statisticsStack with the statistic specified by statsFlags. Typically, the statsFlag will be one of lsst.afw.math.MEAN for a mean-stack or lsst.afw.math.MEANCLIP for outlier rejection using an N-sigma clipped mean where N and iterations are specified by statsCtrl. Assign the stacked subregion back to the coadd.

Parameters:
coaddExposure : lsst.afw.image.Exposure

The target exposure for the coadd.

bbox : lsst.geom.Box

Sub-region to coadd.

tempExpRefList : list

List of data reference to tempExp.

imageScalerList : list

List of image scalers.

weightList : list

List of weights.

altMaskList : list

List of alternate masks to use rather than those stored with tempExp, or None. Each element is dict with keys = mask plane name to which to add the spans.

statsFlags : lsst.afw.math.Property

Property object for statistic for coadd.

statsCtrl : lsst.afw.math.StatisticsControl

Statistics control object for coadd.

nImage : lsst.afw.image.ImageU, optional

Keeps track of exposure count for each pixel.

emptyMetadata() → None

Empty (clear) the metadata for this Task and all sub-Tasks.

filterWarps(inputs, goodVisits)

Return list of only inputRefs with visitId in goodVisits ordered by goodVisit.

Parameters:
inputs : list of DeferredDatasetRef

List of lsst.pipe.base.DeferredDatasetRef with dataId containing visit.

goodVisit : dict

Dictionary with good visitIds as the keys. Value ignored.

Returns:
filteredInputs : list of DeferredDatasetRef

Filtered and sorted list of inputRefs with visitId in goodVisits ordered by goodVisit.

getAllSchemaCatalogs() → Dict[str, Any]

Get schema catalogs for all tasks in the hierarchy, combining the results into a single dict.

Returns:
schemacatalogs : dict

Keys are butler dataset type, values are a empty catalog (an instance of the appropriate lsst.afw.table Catalog type) for all tasks in the hierarchy, from the top-level task down through all subtasks.

Notes

This method may be called on any task in the hierarchy; it will return the same answer, regardless.

The default implementation should always suffice. If your subtask uses schemas the override Task.getSchemaCatalogs, not this method.

getBadPixelMask()

Convenience method to provide the bitmask from the mask plane names

getFullMetadata() → lsst.pipe.base._task_metadata.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.

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”.
getName() → str

Get the name of the task.

Returns:
taskName : str

Name of the task.

See also

getFullName
getResourceConfig() → Optional[ResourceConfig]

Return resource configuration for this task.

Returns:
Object of type ResourceConfig or None if resource
configuration is not defined for this task.
getSchemaCatalogs() → Dict[str, Any]

Get the schemas generated by this task.

Returns:
schemaCatalogs : dict

Keys are butler dataset type, values are an empty catalog (an instance of the appropriate lsst.afw.table Catalog type) for this task.

See also

Task.getAllSchemaCatalogs

Notes

Warning

Subclasses that use schemas must override this method. The default implementation returns an empty dict.

This method may be called at any time after the Task is constructed, which means that all task schemas should be computed at construction time, not when data is actually processed. This reflects the philosophy that the schema should not depend on the data.

Returning catalogs rather than just schemas allows us to save e.g. slots for SourceCatalog as well.

getSkyInfo(patchRef)

Use getSkyinfo to return the skyMap, tract and patch information, wcs and the outer bbox of the patch.

Parameters:
patchRef : Unknown

Data reference for sky map. Must include keys “tract” and “patch”.

Returns:
getSkyInfo : lsst.pipe.base.Struct

Sky Info as a struct with attributes:

skyMap

sky map (lsst.skyMap.SkyMap).

tractInfo

Information for chosen tract of sky map (lsst.skymap.TractInfo).

patchInfo

Information about chosen patch of tract (lsst.skymap.PatchInfo).

wcs

WCS of tract (lsst.afw.image.SkyWcs).

bbox

Outer bbox of patch, as an geom Box2I (lsst.afw.geom.Box2I).

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.

getTempExpDatasetName(warpType='direct')

Return warp name for given warpType and task config

Parameters:
warpType : str

Either ‘direct’ or ‘psfMatched’.

Returns:
WarpDatasetName : str
classmethod makeField(doc: str) → lsst.pex.config.configurableField.ConfigurableField

Make a lsst.pex.config.ConfigurableField for this task.

Parameters:
doc : str

Help text for the field.

Returns:
configurableField : lsst.pex.config.ConfigurableField

A ConfigurableField for this task.

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) → 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”.

Notes

The subtask must be defined by Task.config.name, an instance of ConfigurableField or RegistryField.

makeSupplementaryDataGen3(butlerQC, inputRefs, outputRefs)

Deprecated since version v25.0: makeSupplementaryDataGen3 is deprecated in favor of _makeSupplementaryData

prepareInputs(refList)

Prepare the input warps for coaddition by measuring the weight for each warp and the scaling for the photometric zero point.

Each Warp has its own photometric zeropoint and background variance. Before coadding these Warps together, compute a scale factor to normalize the photometric zeropoint and compute the weight for each Warp.

Parameters:
refList : list

List of data references to tempExp.

Returns:
result : Struct

Results as a struct with attributes:

tempExprefList

list of data references to tempExp.

weightList

list of weightings.

imageScalerList

list of image scalers.

prepareStats(mask=None)

Prepare the statistics for coadding images.

Parameters:
mask : int, optional

Bit mask value to exclude from coaddition.

Returns:
stats : Struct

Statistics as a struct with attributes:

statsCtrl

Statistics control object for coadd (StatisticsControl).

statsFlags

Statistic for coadd (Property).

processResults(coaddExposure, brightObjectMasks=None, dataId=None)

Interpolate over missing data and mask bright stars.

Parameters:
coaddExposure : lsst.afw.image.Exposure

The coadded exposure to process.

brightObjectMasks : lsst.afw.table or None, optional

Table of bright objects to mask.

dataId : lsst.daf.butler.DataId or None, optional

Data identification.

removeMaskPlanes(maskedImage)

Unset the mask of an image for mask planes specified in the config.

Parameters:
maskedImage : lsst.afw.image.MaskedImage

The masked image to be modified.

Raises:
InvalidParameterError

Raised if no mask plane with that name was found.

run(skyInfo, tempExpRefList, imageScalerList, weightList, altMaskList=None, mask=None, supplementaryData=None)

Assemble a coadd from input warps.

Assemble the coadd using the provided list of coaddTempExps. Since the full coadd covers a patch (a large area), the assembly is performed over small areas on the image at a time in order to conserve memory usage. Iterate over subregions within the outer bbox of the patch using assembleSubregion to stack the corresponding subregions from the coaddTempExps with the statistic specified. Set the edge bits the coadd mask based on the weight map.

Parameters:
skyInfo : Struct

Struct with geometric information about the patch.

tempExpRefList : list

List of data references to Warps (previously called CoaddTempExps).

imageScalerList : list

List of image scalers.

weightList : list

List of weights.

altMaskList : list, optional

List of alternate masks to use rather than those stored with tempExp.

mask : int, optional

Bit mask value to exclude from coaddition.

supplementaryData : Struct, optional

Struct with additional data products needed to assemble coadd. Only used by subclasses that implement _makeSupplementaryData and override run.

Returns:
result : Struct

Results as a struct with attributes:

coaddExposure

Coadded exposure (lsst.afw.image.Exposure).

nImage

Exposure count image (lsst.afw.image.Image), if requested.

inputMap

Bit-wise map of inputs, if requested.

warpRefList

Input list of refs to the warps (lsst.daf.butler.DeferredDatasetHandle) (unmodified).

imageScalerList

Input list of image scalers (list) (unmodified).

weightList

Input list of weights (list) (unmodified).

runQuantum(butlerQC, inputRefs, outputRefs)

Method to do butler IO and or transforms to provide in memory objects for tasks run method

Parameters:
butlerQC : ButlerQuantumContext

A butler which is specialized to operate in the context of a lsst.daf.butler.Quantum.

inputRefs : InputQuantizedConnection

Datastructure whose attribute names are the names that identify connections defined in corresponding PipelineTaskConnections class. The values of these attributes are the lsst.daf.butler.DatasetRef objects associated with the defined input/prerequisite connections.

outputRefs : OutputQuantizedConnection

Datastructure whose attribute names are the names that identify connections defined in corresponding PipelineTaskConnections class. The values of these attributes are the lsst.daf.butler.DatasetRef objects associated with the defined output connections.

setBrightObjectMasks(exposure, brightObjectMasks, dataId=None)

Set the bright object masks.

Parameters:
exposure : lsst.afw.image.Exposure

Exposure under consideration.

brightObjectMasks : lsst.afw.table

Table of bright objects to mask.

dataId : lsst.daf.butler.DataId, optional

Data identifier dict for patch.

setInexactPsf(mask)

Set INEXACT_PSF mask plane.

If any of the input images isn’t represented in the coadd (due to clipped pixels or chip gaps), the CoaddPsf will be inexact. Flag these pixels.

Parameters:
mask : lsst.afw.image.Mask

Coadded exposure’s mask, modified in-place.

static setRejectedMaskMapping(statsCtrl)

Map certain mask planes of the warps to new planes for the coadd.

If a pixel is rejected due to a mask value other than EDGE, NO_DATA, or CLIPPED, set it to REJECTED on the coadd. If a pixel is rejected due to EDGE, set the coadd pixel to SENSOR_EDGE. If a pixel is rejected due to CLIPPED, set the coadd pixel to CLIPPED.

Parameters:
statsCtrl : lsst.afw.math.StatisticsControl

Statistics control object for coadd.

Returns:
maskMap : list of tuple of int

A list of mappings of mask planes of the warped exposures to mask planes of the coadd.

shrinkValidPolygons(coaddInputs)

Shrink coaddInputs’ ccds’ ValidPolygons in place.

Either modify each ccd’s validPolygon in place, or if CoaddInputs does not have a validPolygon, create one from its bbox.

Parameters:
coaddInputs : lsst.afw.image.coaddInputs

Original mask.

timer(name: str, logLevel: int = 10) → Iterator[None]

Context manager to log performance data for an arbitrary block of code.

Parameters:
name : str

Name of code being timed; data will be logged using item name: Start and End.

logLevel

A logging level constant.

See also

timer.logInfo

Examples

Creating a timer context:

with self.timer("someCodeToTime"):
    pass  # code to time