lsst.ip.diffim g20c59dc0c7+acb0570d1a
Loading...
Searching...
No Matches
lsst.ip.diffim.getTemplate.GetTemplateTask Class Reference
Inheritance diagram for lsst.ip.diffim.getTemplate.GetTemplateTask:

Public Member Functions

 __init__ (self, *args, **kwargs)
 runQuantum (self, butlerQC, inputRefs, outputRefs)
 convert_outputs_to_future (self, template, coadd_refs, detector, exposureRecord)
 getExposures (self, coaddExposureHandles, bbox, skymap, wcs)
 run (self, *, coaddExposureHandles, bbox, wcs, dataIds, physical_filter, visit=None, instrument=None)
 checkHighVariance (self, template)

Public Attributes

 warper = afwMath.Warper.fromConfig(self.config.warp)
 schema = afwTable.ExposureTable.makeMinimalSchema()

Static Public Attributes

 ConfigClass = GetTemplateConfig

Protected Member Functions

 _clearUnmappedMaskPlanes (self, mask, planeMap)
 _correctVariance (self, template, plateScaleFactor)
 _plateScaleFactor (self, coaddInputs, wcs, bbox)
 _makeExposureCatalog (self, exposureRefs, dataIds, instrument=_UNKNOWN_INSTRUMENT)
 _merge (self, maskedImages, bbox, wcs)
 _makePsf (self, template, catalog, wcs)
 _makeGaussianPsf (self, template)

Static Protected Member Functions

 _checkInputs (dataIds, coaddExposures, scienceInstrument=None)
 _getInstrument (coaddInputs)

Static Protected Attributes

str _DefaultName = "getTemplate"

Detailed Description

Definition at line 242 of file getTemplate.py.

Constructor & Destructor Documentation

◆ __init__()

lsst.ip.diffim.getTemplate.GetTemplateTask.__init__ ( self,
* args,
** kwargs )

Definition at line 246 of file getTemplate.py.

Member Function Documentation

◆ _checkInputs()

lsst.ip.diffim.getTemplate.GetTemplateTask._checkInputs ( dataIds,
coaddExposures,
scienceInstrument = None )
staticprotected
Check that the all the dataIds are from the same band and that
the exposures all have the same photometric calibration, and choose
the instrument of the template.

Parameters
----------
dataIds : `dict` [`int`, `list` [`lsst.daf.butler.DataCoordinate`]]
    Record of the tract and patch of each coaddExposure.
coaddExposures : `dict` [`int`,  `list` of \
                  [`lsst.daf.butler.DeferredDatasetHandle` of \
                   `lsst.afw.image.Exposure` or
                   `lsst.afw.image.Exposure`]]
    Coadds to be mosaicked.
scienceInstrument : `str`, optional
    Instrument of the science image.

Returns
-------
band : `str`
    Filter band of all the input exposures.
photoCalib : `lsst.afw.image.PhotoCalib`
    Photometric calibration of all of the input exposures.
instrument : `str`
    ``scienceInstrument`` if any coadd was made from it, otherwise the
    instrument that the most coadds were made from, or ``"UNKNOWN"`` if
    no coadd records one. A tie goes to the instrument whose name sorts
    first.

Raises
------
RuntimeError
    Raised if the bands or calibrations of the input exposures are not
    all the same.

Definition at line 753 of file getTemplate.py.

◆ _clearUnmappedMaskPlanes()

lsst.ip.diffim.getTemplate.GetTemplateTask._clearUnmappedMaskPlanes ( self,
mask,
planeMap )
protected
Clear the pixels of every mask plane that conversion would reject.

Parameters
----------
mask : `lsst.afw.image.Mask`
    Template mask to modify in place.
planeMap : `dict` [`str`, `lsst.images.MaskPlane`]
    Plane map the template will be converted with. The optional
    planes of `lsst.images.get_legacy_optional_mask_planes` are kept
    as well, since conversion adds them when they have pixels set.

Definition at line 376 of file getTemplate.py.

◆ _correctVariance()

lsst.ip.diffim.getTemplate.GetTemplateTask._correctVariance ( self,
template,
plateScaleFactor )
protected
Correct the template variance plane for the effects of warping.

Apply a multiplicative correction factor to the template variance if
the plate scale of the coadd's constituent images is different than
the science image the template is being constructed for. This should
only be necessary if the coadd images were from a different instrument
than the science image. If the plate scale of the science instrument is
smaller than the plate scale of the coadd instrument, then the template
pixels will be correlated and the true variance will be higher than the
image pixel noise level would suggest.

Parameters
----------
template : `lsst.afw.image.Exposure`
    Assembled template; its variance plane is modified in place.
plateScaleFactor : `float` or `None`
    Correction for the change in pixel area, from `_plateScaleFactor`.

Raises
------
RuntimeError
    Raised if ``plateScaleFactor`` is `None`.

Definition at line 650 of file getTemplate.py.

◆ _getInstrument()

lsst.ip.diffim.getTemplate.GetTemplateTask._getInstrument ( coaddInputs)
staticprotected
Return the instrument whose observations were coadded to make a
coadd.

Parameters
----------
coaddInputs : `lsst.afw.image.CoaddInputs` or `None`
    Input records of the coadd.

Returns
-------
instrument : `str`
    Instrument label of the coadd, or ``"UNKNOWN"`` if it records none.

Notes
-----
Every input of a coadd comes from the same instrument, so the first
input record stands for all of them.

Definition at line 814 of file getTemplate.py.

◆ _makeExposureCatalog()

lsst.ip.diffim.getTemplate.GetTemplateTask._makeExposureCatalog ( self,
exposureRefs,
dataIds,
instrument = _UNKNOWN_INSTRUMENT )
protected
Make an exposure catalog for one tract.

Parameters
----------
exposureRefs : `list` of [`lsst.daf.butler.DeferredDatasetHandle` of \
                `lsst.afw.image.Exposure`]
    Exposures to include in the catalog.
dataIds : `list` [`lsst.daf.butler.DataCoordinate`]
    Data ids of each of the included exposures; must have "tract" and
    "patch" entries.
instrument : `str`, optional
    Instrument of the template, recorded in the catalog. Exposures
    made from another instrument are dropped, as are exposures that
    record no instrument unless ``instrument`` is ``"UNKNOWN"``.

Returns
-------
images : `dict` [`lsst.afw.image.MaskedImage`]
    MaskedImages of each of the input exposures, for warping.
catalog : `lsst.afw.table.ExposureCatalog`
    Catalog of metadata for each exposure
totalBox : `lsst.geom.Box2I`
    The union of the bounding boxes of all the input exposures.
coaddInputs : `lsst.afw.image.CoaddInputs` or `None`
    Input records of the first exposure kept, or `None` if none is
    kept.

Definition at line 839 of file getTemplate.py.

◆ _makeGaussianPsf()

lsst.ip.diffim.getTemplate.GetTemplateTask._makeGaussianPsf ( self,
template )
protected
Return a Gaussian PSF with the width of the template CoaddPsf.

Parameters
----------
template : `lsst.afw.image.Exposure`
    Template with the CoaddPsf to approximate. The width is measured
    at the average position of the PSF, or averaged over a grid of
    positions if the PSF cannot be evaluated there.

Returns
-------
psf : `lsst.afw.detection.GaussianPsf`
    Gaussian with the width of the template PSF.

Raises
------
ValueError
    Raised if the PSF cannot be evaluated at any grid position.

Definition at line 1014 of file getTemplate.py.

◆ _makePsf()

lsst.ip.diffim.getTemplate.GetTemplateTask._makePsf ( self,
template,
catalog,
wcs )
protected
Return a PSF containing the PSF at each of the input regions.

Note that although this includes all the exposures from the catalog,
the PSF knows which part of the template the inputs came from, so when
evaluated at a given position it will not include inputs that never
went in to those pixels.

Parameters
----------
template : `lsst.afw.image.Exposure`
    Generated template the PSF is for.
catalog : `lsst.afw.table.ExposureCatalog`
    Catalog of exposures that went into the template that contains all
    of the input PSFs.
wcs : `lsst.afw.geom.SkyWcs`
    WCS of the template, to warp the PSFs to.

Returns
-------
coaddPsf : `lsst.meas.algorithms.CoaddPsf`
    The meta-psf constructed from all of the input catalogs.

Definition at line 979 of file getTemplate.py.

◆ _merge()

lsst.ip.diffim.getTemplate.GetTemplateTask._merge ( self,
maskedImages,
bbox,
wcs )
protected
Merge the images that came from one tract into one larger image,
ignoring NaN pixels and non-finite variance pixels from individual
exposures.

Parameters
----------
maskedImages : `dict` [`lsst.afw.image.MaskedImage` or
                       `lsst.afw.image.Exposure`]
    Images to be merged into one larger bounding box.
bbox : `lsst.geom.Box2I`
    Bounding box defining the image to merge into.
wcs : `lsst.afw.geom.SkyWcs`
    WCS of all of the input images to set on the output image.

Returns
-------
merged : `lsst.afw.image.MaskedImage`
    Merged image with all of the inputs at their respective bbox
    positions.
count : `int`
    Count of the number of good pixels (those with positive weights)
    in the merged image.
included : `list` [`int`]
    List of indexes of patches that were included in the merged
    result, to be used to trim the exposure catalog.

Definition at line 905 of file getTemplate.py.

◆ _plateScaleFactor()

lsst.ip.diffim.getTemplate.GetTemplateTask._plateScaleFactor ( self,
coaddInputs,
wcs,
bbox )
protected
Compute the variance correction for the total change in pixel area
between the coadd's constituent images and the science image.

Parameters
----------
coaddInputs : `lsst.afw.image.CoaddInputs` or `None`
    Input records of one of the coadd patches.
wcs : `lsst.afw.geom.SkyWcs`
    WCS of the science image the template is being built for.
bbox : `lsst.geom.Box2I`
    Bounding box of the template, used only to choose where to
    evaluate the science image pixel scale.

Returns
-------
factor : `float` or `None`
    The correction factor equivalent to the ratio of the area of a pixel
    from the coadd's instrument to the science instrument, or `None` if
    this patch carries no input record from which it could be computed.

Definition at line 689 of file getTemplate.py.

◆ checkHighVariance()

lsst.ip.diffim.getTemplate.GetTemplateTask.checkHighVariance ( self,
template )
Set a mask plane for regions with unusually high variance.

Parameters
----------
template : `lsst.afw.image.Exposure`
    The warped template exposure, which will be modified in place.

Definition at line 728 of file getTemplate.py.

◆ convert_outputs_to_future()

lsst.ip.diffim.getTemplate.GetTemplateTask.convert_outputs_to_future ( self,
template,
coadd_refs,
detector,
exposureRecord )
Convert a template image to DifferenceImage format.

This replaces ``template`` with an `lsst.images.DifferenceImage`
instance and records the coadds contributed to it, along with the
instrument they were made from. The Gaussian PSF set by `run` is
converted to an `lsst.images.psfs.GaussianPointSpreadFunction`.

Parameters
----------
template : `lsst.afw.image.Exposure`
    Template to convert. Its detector is replaced with ``detector``
    and its mask is modified in place.
coadd_refs : `list` [`lsst.daf.butler.DatasetRef`]
    References to the coadds that may have gone into the template.
    May be a superset of the coadds that were used; supplies the
    dataset id and RUN collection recorded for each coadd that was.
detector : `lsst.afw.cameraGeom.Detector`
    Detector of the science image that the template was built for.
exposureRecord : `lsst.daf.butler.DimensionRecord`
    The ``exposure`` record of the observation the template was built
    for, which supplies the observation metadata recorded on the
    output.

Returns
-------
convertedTemplate : `lsst.images.DifferenceImage`
    The converted image.

Raises
------
RuntimeError
    Raised if the template has pixels set in a mask plane that
    `lsst.images.get_legacy_template_mask_planes` does not map and
    ``config.raiseOnUndefinedMaskMap`` is True, or if ``coadd_refs``
    spans more than one skymap.

Definition at line 306 of file getTemplate.py.

◆ getExposures()

lsst.ip.diffim.getTemplate.GetTemplateTask.getExposures ( self,
coaddExposureHandles,
bbox,
skymap,
wcs )
Return a data structure containing the coadds that overlap the
specified bbox projected onto the sky, and a corresponding data
structure of their dataIds.
These are the appropriate inputs to this task's `run` method.

The spatial index in the butler registry has generous padding and often
supplies patches near, but not directly overlapping the desired region.
This method filters the inputs so that `run` does not have to read in
all possibly-matching coadd exposures.

Parameters
----------
coaddExposureHandles : `iterable` \
                  [`lsst.daf.butler.DeferredDatasetHandle` of \
                   `lsst.afw.image.Exposure`]
    Dataset handles to exposures that might overlap the desired
    region.
bbox : `lsst.geom.Box2I`
    Template bounding box of the pixel geometry onto which the
    coaddExposures will be resampled.
skymap : `lsst.skymap.SkyMap`
    Geometry of the tracts and patches the coadds are defined on.
wcs : `lsst.afw.geom.SkyWcs`
    Template WCS onto which the coadds will be resampled.

Returns
-------
result : `lsst.pipe.base.Struct`
   A struct with attributes:

   ``coaddExposures``
       Dict of coadd exposures that overlap the projected bbox,
       indexed on tract id
       (`dict` [`int`, `list` [`lsst.daf.butler.DeferredDatasetHandle` of
                               `lsst.afw.image.Exposure`] ]).
   ``dataIds``
       Dict of data IDs of the coadd exposures that overlap the
       projected bbox, indexed on tract id
       (`dict` [`int`, `list [`lsst.daf.butler.DataCoordinate`] ]).

Raises
------
NoWorkFound
    Raised if no patches overlap the input detector bbox, or the input
    WCS is None.

Definition at line 399 of file getTemplate.py.

◆ run()

lsst.ip.diffim.getTemplate.GetTemplateTask.run ( self,
* ,
coaddExposureHandles,
bbox,
wcs,
dataIds,
physical_filter,
visit = None,
instrument = None )
Warp coadds from multiple tracts and patches to form a template to
subtract from a science image.

Tract and patch overlap regions are combined by a variance-weighted
average, and the variance planes are combined with the same weights,
not added in quadrature; the overlap regions are not statistically
independent, because they're derived from the same original data.
The PSF of the template is a Gaussian with the same width as the
CoaddPsf evaluated at the center of the detector.

The template is built from coadds of one instrument: the science
image's ``instrument`` if any coadd was made from it, and otherwise the
one that most of the coadds were made from. Coadds made from another
instrument are dropped, and so are coadds that record no instrument
unless none of the coadds records one.

Parameters
----------
coaddExposureHandles : `dict` [`int`,  `list` of \
                  [`lsst.daf.butler.DeferredDatasetHandle` of \
                   `lsst.afw.image.Exposure`]]
    Coadds to be mosaicked, indexed on tract id.
bbox : `lsst.geom.Box2I`
    Input Bounding box of the detector geometry onto which to
    resample the ``coaddExposureHandles``. The output template bbox
    will be grown by ``templateBorderSize``.
wcs : `lsst.afw.geom.SkyWcs`
    Template WCS onto which to resample the ``coaddExposureHandles``.
dataIds : `dict` [`int`, `list` [`lsst.daf.butler.DataCoordinate`]]
    Record of the tract and patch of each coaddExposure, indexed on
    tract id.
physical_filter : `str`
    Physical filter of the science image.
visit : `int`, optional
    If supplied, over-write the visit ID in the template's visitInfo
    so that downstream source injection tasks can link the template and
    science image for the visit.
instrument : `str`, optional
    Instrument of the science image. Coadds made from it are used in
    preference to coadds from any other instrument.

Returns
-------
result : `lsst.pipe.base.Struct`
   A struct with attributes:

   ``template``
       A template coadd exposure assembled out of patches, with
       pixels in nJy. Its PSF is a Gaussian approximation to the
       CoaddPsf of its inputs (`lsst.afw.image.ExposureF`).

Raises
------
NoWorkFound
    If no coadds are found with sufficient un-masked pixels.
RuntimeError
    If the template is not known to be from the science image's
    instrument and no coadd records the plate scale of its input
    images, so the template variance cannot be corrected.

Definition at line 486 of file getTemplate.py.

◆ runQuantum()

lsst.ip.diffim.getTemplate.GetTemplateTask.runQuantum ( self,
butlerQC,
inputRefs,
outputRefs )

Definition at line 273 of file getTemplate.py.

Member Data Documentation

◆ _DefaultName

str lsst.ip.diffim.getTemplate.GetTemplateTask._DefaultName = "getTemplate"
staticprotected

Definition at line 244 of file getTemplate.py.

◆ ConfigClass

lsst.ip.diffim.getTemplate.GetTemplateTask.ConfigClass = GetTemplateConfig
static

Definition at line 243 of file getTemplate.py.

◆ schema

lsst.ip.diffim.getTemplate.GetTemplateTask.schema = afwTable.ExposureTable.makeMinimalSchema()

Definition at line 251 of file getTemplate.py.

◆ warper

lsst.ip.diffim.getTemplate.GetTemplateTask.warper = afwMath.Warper.fromConfig(self.config.warp)

Definition at line 250 of file getTemplate.py.


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