lsst.ip.diffim gfb11b3eabb+728cca2e53
Loading...
Searching...
No Matches
lsst.ip.diffim.utils Namespace Reference

Functions

 record_from_obs_info (obs_info, instrument, visit, universe)
 get_difference_image_provenance (image, attribute, connection, dataId)
 getKernelCenterDisplacement (kernel, x, y, image=None)
 getPsfFwhm (psf, average=True, position=None)
float evaluateMeanPsfFwhm (afwImage.Exposure exposure, float fwhmExposureBuffer, int fwhmExposureGrid)
afwImage.ImageD computeAveragePsf (afwImage.Exposure exposure, float psfExposureBuffer, int psfExposureGrid)
 computeRobustStatistics (image, mask, statsCtrl, statistic=afwMath.MEANCLIP)
 computePSFNoiseEquivalentArea (psf)
 angleMean (angles)
 evaluateMaskFraction (mask, maskPlane)
 computeDifferenceImageMetrics (science, difference, stars, sky_sources=None)
 populate_sattle_visit_cache (visit_info, historical=False)
 checkMask (mask, sources, excludeMaskPlanes)
 setSourceFootprints (sources, kernelSize)

Variables

 _LOG = getLogger(__name__)

Detailed Description

Support utilities for Measuring sources

Function Documentation

◆ angleMean()

angleMean ( angles)
Calculate the mean of an array of angles.

Parameters
----------
angles : `ndarray`
    An array of angles, in radians

Returns
-------
`lsst.geom.Angle`
    The mean angle

Definition at line 411 of file utils.py.

◆ checkMask()

checkMask ( mask,
sources,
excludeMaskPlanes )
Exclude sources that have masked pixels in their footprints.

Parameters
----------
mask : `lsst.afw.image.Mask`
    The image mask plane to use to reject sources
    based on the location of their centroid on the ccd.
sources : `lsst.afw.table.SourceCatalog`
    The source catalog to evaluate.
excludeMaskPlanes : `list` of `str`
    List of the names of the mask planes to exclude.

Returns
-------
good : `numpy.ndarray` of `bool`
    Array indicating whether each source in the catalog should be
    kept (True) or rejected (False) based on the value of the
    mask plane at its location.

Definition at line 565 of file utils.py.

◆ computeAveragePsf()

afwImage.ImageD computeAveragePsf ( afwImage.Exposure exposure,
float psfExposureBuffer,
int psfExposureGrid )
Get the average PSF by evaluating it on a grid within an exposure.

Parameters
----------
exposure : `~lsst.afw.image.Exposure`
    The exposure for which the average PSF is to be computed.
    The exposure must contain a `psf` attribute.
psfExposureBuffer : `float`
    Fractional buffer margin to be left out of all sides of the image
    during the construction of the grid to compute average PSF in an
    exposure.
psfExposureGrid : `int`
    Grid size to compute the average PSF in an exposure.

Returns
-------
psfImage : `~lsst.afw.image.Image`
    The average PSF across the exposure.

Raises
------
ValueError
    Raised if the PSF cannot be computed at any of the grid points.

See Also
--------
`evaluateMeanPsfFwhm`

Definition at line 306 of file utils.py.

◆ computeDifferenceImageMetrics()

computeDifferenceImageMetrics ( science,
difference,
stars,
sky_sources = None )
Compute quality metrics (saved to the task metadata) on the
difference image, at the locations of detected stars on the science
image. This restricts the metric to locations that should be
well-subtracted.

Parameters
----------
science : `lsst.afw.image.ExposureF`
    Science exposure that was subtracted.
difference : `lsst.afw.image.ExposureF`
    Result of subtracting template and science.
stars : `lsst.afw.table.SourceCatalog`
    Good calibration sources detected on science image; these
    footprints are what the metrics are computed on.

Returns
-------
metrics : `lsst.pipe.base.Struct`

    ``differenceFootprintRatioMean`` : `float`
        Mean of the ratio of the absolute value of the difference image
        (with the mean absolute value of the sky regions on the difference
        image removed) to the science image, computed in the footprints
        of stars detected on the science image (the sums below are of the
        pixels in each star or sky footprint):
        :math:`\mathrm{mean}_{footprints}((\sum |difference| -
        \mathrm{mean}(\sum |difference_{sky}|)) / \sum science)`
    ``differenceFootprintRatioStdev`` : `float`
        Standard Deviation across footprints of the above ratio.
    ``differenceFootprintSkyRatioMean`` : `float`
        Mean of the ratio of the absolute value of sky source regions on
        the difference image to the science image (the sum below is of the
        pixels in each sky source footprint):
        :math:`\mathrm{mean}_{footprints}(\sum |difference_{sky}| / \sum science_{sky})`
    ``differenceFootprintSkyRatioStdev`` : `float`
        Standard Deivation across footprints of the above sky ratio.

Definition at line 447 of file utils.py.

◆ computePSFNoiseEquivalentArea()

computePSFNoiseEquivalentArea ( psf)
Compute the noise equivalent area for an image psf

Parameters
----------
psf : `lsst.afw.detection.Psf`

Returns
-------
nea : `float`

Definition at line 395 of file utils.py.

◆ computeRobustStatistics()

computeRobustStatistics ( image,
mask,
statsCtrl,
statistic = afwMath.MEANCLIP )
Calculate a robust mean of the variance plane of an exposure.

Parameters
----------
image : `lsst.afw.image.Image`
    Image or variance plane of an exposure to evaluate.
mask : `lsst.afw.image.Mask`
    Mask plane to use for excluding pixels.
statsCtrl : `lsst.afw.math.StatisticsControl`
    Statistics control object for configuring the calculation.
statistic : `lsst.afw.math.Property`, optional
    The type of statistic to compute. Typical values are
    ``afwMath.MEANCLIP`` or ``afwMath.STDEVCLIP``.

Returns
-------
value : `float`
    The result of the statistic calculated from the unflagged pixels.

Definition at line 371 of file utils.py.

◆ evaluateMaskFraction()

evaluateMaskFraction ( mask,
maskPlane )
Evaluate the fraction of masked pixels in a mask plane.

Parameters
----------
mask : `lsst.afw.image.Mask`
    The mask to evaluate the fraction on
maskPlane : `str`
    The particular mask plane to evaluate the fraction

Returns
-------
value : `float`
    The calculated fraction of masked pixels

Definition at line 428 of file utils.py.

◆ evaluateMeanPsfFwhm()

float evaluateMeanPsfFwhm ( afwImage.Exposure exposure,
float fwhmExposureBuffer,
int fwhmExposureGrid )
Get the mean PSF FWHM by evaluating it on a grid within an exposure.

Parameters
----------
exposure : `~lsst.afw.image.Exposure`
    The exposure for which the mean FWHM of the PSF is to be computed.
    The exposure must contain a `psf` attribute.
fwhmExposureBuffer : `float`
    Fractional buffer margin to be left out of all sides of the image
    during the construction of the grid to compute mean PSF FWHM in an
    exposure.
fwhmExposureGrid : `int`
    Grid size to compute the average PSF FWHM in an exposure (pixels).

Returns
-------
meanFwhm : `float`
    The mean PSF FWHM on the exposure.

Raises
------
ValueError
    Raised if the PSF cannot be computed at any of the grid points.

See Also
--------
`getPsfFwhm`
`computeAveragePsf`

Definition at line 246 of file utils.py.

◆ get_difference_image_provenance()

get_difference_image_provenance ( image,
attribute,
connection,
dataId )
Get the PSF matching kernel or the template records of an input
difference image.

Parameters
----------
image : `lsst.images.DifferenceImage`
    Input image read by a task in future mode.
attribute : {"kernel", "templates"}
    Name of the attribute to get.
connection : `str`
    Name of the input connection the image was read from.
dataId : `lsst.daf.butler.DataCoordinate`
    Data ID of the quantum, for the error message.

Returns
-------
value : `lsst.images.convolution_kernels.ConvolutionKernel` or \
        `list` [`lsst.images.DifferenceImageTemplateInfo`]
    Value of the attribute.

Raises
------
lsst.pipe.base.InvalidQuantumError
    Raised if the image does not have the attribute, which happens when
    the input was written as a legacy Exposure and converted on read.

Definition at line 113 of file utils.py.

◆ getKernelCenterDisplacement()

getKernelCenterDisplacement ( kernel,
x,
y,
image = None )
Calculate the PSF matching kernel peak offset from the nominal
position.

Parameters
----------
kernel : `~lsst.afw.math.LinearCombinationKernel`
    The PSF matching kernel to evaluate.
x : `float`
    The x position on the detector to evaluate the kernel
y : `float`
    The y position on the detector to evaluate the kernel
image : `~lsst.afw.image.ImageD`
    The image to use as base for computing kernel pixel values

Returns
-------
kernel_sum : `float`
    The sum of the kernel on the desired location
dx : `float`
    The displacement of the kernel averaged peak, with respect to the
    center of the extraction of the kernel
dy : `float`
    The displacement of the kernel averaged peak, with respect to the
    center of the extraction of the kernel
pos_angle: `float`
    The position angle in detector coordinates of the displacement
length : `float`
    The displacement module of the kernel centroid in pixel units

Definition at line 151 of file utils.py.

◆ getPsfFwhm()

getPsfFwhm ( psf,
average = True,
position = None )
Directly calculate the horizontal and vertical widths
of a PSF at half its maximum value.

Parameters
----------
psf : `~lsst.afw.detection.Psf`
    Point spread function (PSF) to evaluate.
average : `bool`, optional
    Set to return the average width over Y and X axes.
position : `~lsst.geom.Point2D`, optional
    The position at which to evaluate the PSF. If `None`, then the
    average position is used.

Returns
-------
psfSize : `float` | `tuple` [`float`]
    The FWHM of the PSF computed at its average position.
    Returns the widths along the Y and X axes,
    or the average of the two if `average` is set.

See Also
--------
evaluateMeanPsfFwhm

Definition at line 210 of file utils.py.

◆ populate_sattle_visit_cache()

populate_sattle_visit_cache ( visit_info,
historical = False )
Populate a cache of predicted satellite positions in the sattle service.

Parameters
----------
visit_info: `lsst.afw.table.ExposureRecord.visitInfo`
    Visit info for the science exposure being processed.
historical: `bool`
    Set to True if observations are older than the current day.

Raises
------
requests.HTTPError
    Raised if sattle call does not return success.

Definition at line 528 of file utils.py.

◆ record_from_obs_info()

record_from_obs_info ( obs_info,
instrument,
visit,
universe )
Build an ``exposure`` dimension record from an observation info.

Parameters
----------
obs_info : `astro_metadata_translator.ObservationInfo`
    Observation info of an image that the image to be converted is
    derived from.
instrument : `str`
    Name of the instrument, usually from the quantum data ID.
visit : `int`
    Id of the visit, usually from the quantum data ID. It is also used
    as the id of the exposure.
universe : `lsst.daf.butler.DimensionUniverse`
    Dimension universe that defines the record's schema, usually
    ``butlerQC.quantum.dataId.universe``.

Returns
-------
record : `lsst.daf.butler.DimensionRecord`
    An ``exposure`` record holding the fields that `lsst.images` reads
    when it converts a legacy image. Fields it does not read, such as
    ``dark_time`` and ``target_name``, are `None`.

Raises
------
ValueError
    Raised if ``obs_info`` is `None`, which means the image it came from
    was not in an `lsst.images` format.

Notes
-----
The instrument and the visit are passed separately because an
observation info does not carry them in the form the conversion needs:
its ``instrument`` is read from the legacy FITS header rather than from
the record, and its ``exposure_id`` is the id that the visit info held.

Definition at line 51 of file utils.py.

◆ setSourceFootprints()

setSourceFootprints ( sources,
kernelSize )
Add footprints of fixed size to a source catalog

Each source's footprint is replaced by a centered box of side
``2*kernelSize + 1`` pixels (always odd), preserving the brightest peak
of the original footprint.

Parameters
----------
sources : `lsst.afw.table.SourceCatalog`
    The source catalog to add footprints to. Modified in place.
kernelSize : `int`
    Width (in pixels) of the PSF-matching kernel. The footprint size is
    ``2*kernelSize + 1`` so that the kernel can be convolved across the
    source without falling off the stamp.

Returns
-------
sources : `lsst.afw.table.SourceCatalog`
    The input `sources` catalog that was modified in place,
    returned for convenience.

Definition at line 605 of file utils.py.

Variable Documentation

◆ _LOG

lsst.ip.diffim.utils._LOG = getLogger(__name__)
protected

Definition at line 48 of file utils.py.