LSST Applications g0265f82a02+d6b5cd48b5,g02d81e74bb+7bcba2e4e8,g2079a07aa2+14824f138e,g212a7c68fe+4b38ad7149,g2305ad1205+906def1e41,g295015adf3+564da5d084,g2bbee38e9b+d6b5cd48b5,g337abbeb29+d6b5cd48b5,g3ddfee87b4+cff7e20090,g487adcacf7+50712f9db4,g50ff169b8f+5929b3527e,g52b1c1532d+a6fc98d2e7,g591dd9f2cf+d19d1a10d7,g5a732f18d5+66d966b544,g64a986408d+7bcba2e4e8,g858d7b2824+7bcba2e4e8,g8a8a8dda67+a6fc98d2e7,g99cad8db69+808e2eeadf,g9ddcbc5298+d4bad12328,ga1e77700b3+246acaaf9c,ga8c6da7877+9e3c062e8e,gb0e22166c9+3863383f4c,gb6a65358fc+d6b5cd48b5,gb983acf43b+60bb7664b7,gba4ed39666+9664299f35,gbb8dafda3b+6623599aa9,gc07e1c2157+f6e5778202,gc120e1dc64+6e28925a4e,gc28159a63d+d6b5cd48b5,gcf0d15dbbd+cff7e20090,gdaeeff99f8+a38ce5ea23,ge6526c86ff+bcc88f9437,ge79ae78c31+d6b5cd48b5,gee10cc3b42+a6fc98d2e7,gf1cff7945b+7bcba2e4e8,v24.1.5.rc1
LSST Data Management Base Package
Loading...
Searching...
No Matches
Classes | Functions | Variables
lsst.ip.diffim.subtractImages Namespace Reference

Classes

class  AlardLuptonPreconvolveSubtractConfig
 
class  AlardLuptonPreconvolveSubtractConnections
 
class  AlardLuptonPreconvolveSubtractTask
 
class  AlardLuptonSubtractBaseConfig
 
class  AlardLuptonSubtractConfig
 
class  AlardLuptonSubtractConnections
 
class  AlardLuptonSubtractTask
 
class  SubtractImageOutputConnections
 
class  SubtractInputConnections
 
class  SubtractScoreOutputConnections
 

Functions

 checkTemplateIsSufficient (templateExposure, logger, requiredTemplateFraction=0., exceptionMessage="")
 
 _subtractImages (science, template, backgroundModel=None)
 
 _shapeTest (exp1, exp2, fwhmExposureBuffer, fwhmExposureGrid)
 
 _interpolateImage (maskedImage, badMaskPlanes, fallbackValue=None)
 

Variables

tuple _dimensions = ("instrument", "visit", "detector")
 
dict _defaultTemplates = {"coaddName": "deep", "fakesType": ""}
 

Function Documentation

◆ _interpolateImage()

lsst.ip.diffim.subtractImages._interpolateImage ( maskedImage,
badMaskPlanes,
fallbackValue = None )
protected
Replace masked image pixels with interpolated values.

Parameters
----------
maskedImage : `lsst.afw.image.MaskedImage`
    Image on which to perform interpolation.
badMaskPlanes : `list` of `str`
    List of mask planes to interpolate over.
fallbackValue : `float`, optional
    Value to set when interpolation fails.

Returns
-------
result: `float`
    The number of masked pixels that were replaced.

Definition at line 1170 of file subtractImages.py.

1170def _interpolateImage(maskedImage, badMaskPlanes, fallbackValue=None):
1171 """Replace masked image pixels with interpolated values.
1172
1173 Parameters
1174 ----------
1175 maskedImage : `lsst.afw.image.MaskedImage`
1176 Image on which to perform interpolation.
1177 badMaskPlanes : `list` of `str`
1178 List of mask planes to interpolate over.
1179 fallbackValue : `float`, optional
1180 Value to set when interpolation fails.
1181
1182 Returns
1183 -------
1184 result: `float`
1185 The number of masked pixels that were replaced.
1186 """
1187 imgBadMaskPlanes = [
1188 maskPlane for maskPlane in badMaskPlanes if maskPlane in maskedImage.mask.getMaskPlaneDict()
1189 ]
1190
1191 image = maskedImage.image.array
1192 badPixels = (maskedImage.mask.array & maskedImage.mask.getPlaneBitMask(imgBadMaskPlanes)) > 0
1193 image[badPixels] = np.nan
1194 if fallbackValue is None:
1195 fallbackValue = np.nanmedian(image)
1196 # For this initial implementation, skip the interpolation and just fill with
1197 # the median value.
1198 image[badPixels] = fallbackValue
1199 return np.sum(badPixels)

◆ _shapeTest()

lsst.ip.diffim.subtractImages._shapeTest ( exp1,
exp2,
fwhmExposureBuffer,
fwhmExposureGrid )
protected
Determine that the PSF of ``exp1`` is not wider than that of ``exp2``.

Parameters
----------
exp1 : `~lsst.afw.image.Exposure`
    Exposure with the reference point spread function (PSF) to evaluate.
exp2 : `~lsst.afw.image.Exposure`
    Exposure with a candidate point spread function (PSF) to evaluate.
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, if the PSF is not available at its average position.
fwhmExposureGrid : `int`
    Grid size to compute the mean FWHM in an exposure, if the PSF is not
    available at its average position.
Returns
-------
result : `bool`
    True if ``exp1`` has a PSF that is not wider than that of ``exp2`` in
    either dimension.

Definition at line 1128 of file subtractImages.py.

1128def _shapeTest(exp1, exp2, fwhmExposureBuffer, fwhmExposureGrid):
1129 """Determine that the PSF of ``exp1`` is not wider than that of ``exp2``.
1130
1131 Parameters
1132 ----------
1133 exp1 : `~lsst.afw.image.Exposure`
1134 Exposure with the reference point spread function (PSF) to evaluate.
1135 exp2 : `~lsst.afw.image.Exposure`
1136 Exposure with a candidate point spread function (PSF) to evaluate.
1137 fwhmExposureBuffer : `float`
1138 Fractional buffer margin to be left out of all sides of the image
1139 during the construction of the grid to compute mean PSF FWHM in an
1140 exposure, if the PSF is not available at its average position.
1141 fwhmExposureGrid : `int`
1142 Grid size to compute the mean FWHM in an exposure, if the PSF is not
1143 available at its average position.
1144 Returns
1145 -------
1146 result : `bool`
1147 True if ``exp1`` has a PSF that is not wider than that of ``exp2`` in
1148 either dimension.
1149 """
1150 try:
1151 shape1 = getPsfFwhm(exp1.psf, average=False)
1152 shape2 = getPsfFwhm(exp2.psf, average=False)
1154 shape1 = evaluateMeanPsfFwhm(exp1,
1155 fwhmExposureBuffer=fwhmExposureBuffer,
1156 fwhmExposureGrid=fwhmExposureGrid
1157 )
1158 shape2 = evaluateMeanPsfFwhm(exp2,
1159 fwhmExposureBuffer=fwhmExposureBuffer,
1160 fwhmExposureGrid=fwhmExposureGrid
1161 )
1162 return shape1 <= shape2
1163
1164 # Results from getPsfFwhm is a tuple of two values, one for each dimension.
1165 xTest = shape1[0] <= shape2[0]
1166 yTest = shape1[1] <= shape2[1]
1167 return xTest | yTest
1168
1169
Reports invalid arguments.
Definition Runtime.h:66

◆ _subtractImages()

lsst.ip.diffim.subtractImages._subtractImages ( science,
template,
backgroundModel = None )
protected
Subtract template from science, propagating relevant metadata.

Parameters
----------
science : `lsst.afw.Exposure`
    The input science image.
template : `lsst.afw.Exposure`
    The template to subtract from the science image.
backgroundModel : `lsst.afw.MaskedImage`, optional
    Differential background model

Returns
-------
difference : `lsst.afw.Exposure`
    The subtracted image.

Definition at line 1104 of file subtractImages.py.

1104def _subtractImages(science, template, backgroundModel=None):
1105 """Subtract template from science, propagating relevant metadata.
1106
1107 Parameters
1108 ----------
1109 science : `lsst.afw.Exposure`
1110 The input science image.
1111 template : `lsst.afw.Exposure`
1112 The template to subtract from the science image.
1113 backgroundModel : `lsst.afw.MaskedImage`, optional
1114 Differential background model
1115
1116 Returns
1117 -------
1118 difference : `lsst.afw.Exposure`
1119 The subtracted image.
1120 """
1121 difference = science.clone()
1122 if backgroundModel is not None:
1123 difference.maskedImage -= backgroundModel
1124 difference.maskedImage -= template.maskedImage
1125 return difference
1126
1127

◆ checkTemplateIsSufficient()

lsst.ip.diffim.subtractImages.checkTemplateIsSufficient ( templateExposure,
logger,
requiredTemplateFraction = 0.,
exceptionMessage = "" )
Raise NoWorkFound if template coverage < requiredTemplateFraction

Parameters
----------
templateExposure : `lsst.afw.image.ExposureF`
    The template exposure to check
logger : `lsst.log.Log`
    Logger for printing output.
requiredTemplateFraction : `float`, optional
    Fraction of pixels of the science image required to have coverage
    in the template.
exceptionMessage : `str`, optional
    Message to include in the exception raised if the template coverage
    is insufficient.

Returns
-------
templateCoverageFraction: `float`
    Fraction of pixels in the template with data.

Raises
------
lsst.pipe.base.NoWorkFound
    Raised if fraction of good pixels, defined as not having NO_DATA
    set, is less than the requiredTemplateFraction

Definition at line 1060 of file subtractImages.py.

1061 exceptionMessage=""):
1062 """Raise NoWorkFound if template coverage < requiredTemplateFraction
1063
1064 Parameters
1065 ----------
1066 templateExposure : `lsst.afw.image.ExposureF`
1067 The template exposure to check
1068 logger : `lsst.log.Log`
1069 Logger for printing output.
1070 requiredTemplateFraction : `float`, optional
1071 Fraction of pixels of the science image required to have coverage
1072 in the template.
1073 exceptionMessage : `str`, optional
1074 Message to include in the exception raised if the template coverage
1075 is insufficient.
1076
1077 Returns
1078 -------
1079 templateCoverageFraction: `float`
1080 Fraction of pixels in the template with data.
1081
1082 Raises
1083 ------
1084 lsst.pipe.base.NoWorkFound
1085 Raised if fraction of good pixels, defined as not having NO_DATA
1086 set, is less than the requiredTemplateFraction
1087 """
1088 # Count the number of pixels with the NO_DATA mask bit set
1089 # counting NaN pixels is insufficient because pixels without data are often intepolated over)
1090 pixNoData = np.count_nonzero(templateExposure.mask.array
1091 & templateExposure.mask.getPlaneBitMask('NO_DATA'))
1092 pixGood = templateExposure.getBBox().getArea() - pixNoData
1093 templateCoverageFraction = pixGood/templateExposure.getBBox().getArea()
1094 logger.info("template has %d good pixels (%.1f%%)", pixGood, 100*templateCoverageFraction)
1095
1096 if templateCoverageFraction < requiredTemplateFraction:
1097 message = ("Insufficient Template Coverage. (%.1f%% < %.1f%%)" % (
1098 100*templateCoverageFraction,
1099 100*requiredTemplateFraction))
1100 raise lsst.pipe.base.NoWorkFound(message + " " + exceptionMessage)
1101 return templateCoverageFraction
1102
1103

Variable Documentation

◆ _defaultTemplates

dict lsst.ip.diffim.subtractImages._defaultTemplates = {"coaddName": "deep", "fakesType": ""}
protected

Definition at line 43 of file subtractImages.py.

◆ _dimensions

tuple lsst.ip.diffim.subtractImages._dimensions = ("instrument", "visit", "detector")
protected

Definition at line 42 of file subtractImages.py.