LSST Applications 27.0.0,g0265f82a02+469cd937ee,g02d81e74bb+21ad69e7e1,g1470d8bcf6+cbe83ee85a,g2079a07aa2+e67c6346a6,g212a7c68fe+04a9158687,g2305ad1205+94392ce272,g295015adf3+81dd352a9d,g2bbee38e9b+469cd937ee,g337abbeb29+469cd937ee,g3939d97d7f+72a9f7b576,g487adcacf7+71499e7cba,g50ff169b8f+5929b3527e,g52b1c1532d+a6fc98d2e7,g591dd9f2cf+df404f777f,g5a732f18d5+be83d3ecdb,g64a986408d+21ad69e7e1,g858d7b2824+21ad69e7e1,g8a8a8dda67+a6fc98d2e7,g99cad8db69+f62e5b0af5,g9ddcbc5298+d4bad12328,ga1e77700b3+9c366c4306,ga8c6da7877+71e4819109,gb0e22166c9+25ba2f69a1,gb6a65358fc+469cd937ee,gbb8dafda3b+69d3c0e320,gc07e1c2157+a98bf949bb,gc120e1dc64+615ec43309,gc28159a63d+469cd937ee,gcf0d15dbbd+72a9f7b576,gdaeeff99f8+a38ce5ea23,ge6526c86ff+3a7c1ac5f1,ge79ae78c31+469cd937ee,gee10cc3b42+a6fc98d2e7,gf1cff7945b+21ad69e7e1,gfbcc870c63+9a11dc8c8f
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 1182 of file subtractImages.py.

1182def _interpolateImage(maskedImage, badMaskPlanes, fallbackValue=None):
1183 """Replace masked image pixels with interpolated values.
1184
1185 Parameters
1186 ----------
1187 maskedImage : `lsst.afw.image.MaskedImage`
1188 Image on which to perform interpolation.
1189 badMaskPlanes : `list` of `str`
1190 List of mask planes to interpolate over.
1191 fallbackValue : `float`, optional
1192 Value to set when interpolation fails.
1193
1194 Returns
1195 -------
1196 result: `float`
1197 The number of masked pixels that were replaced.
1198 """
1199 imgBadMaskPlanes = [
1200 maskPlane for maskPlane in badMaskPlanes if maskPlane in maskedImage.mask.getMaskPlaneDict()
1201 ]
1202
1203 image = maskedImage.image.array
1204 badPixels = (maskedImage.mask.array & maskedImage.mask.getPlaneBitMask(imgBadMaskPlanes)) > 0
1205 image[badPixels] = np.nan
1206 if fallbackValue is None:
1207 fallbackValue = np.nanmedian(image)
1208 # For this initial implementation, skip the interpolation and just fill with
1209 # the median value.
1210 image[badPixels] = fallbackValue
1211 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 1140 of file subtractImages.py.

1140def _shapeTest(exp1, exp2, fwhmExposureBuffer, fwhmExposureGrid):
1141 """Determine that the PSF of ``exp1`` is not wider than that of ``exp2``.
1142
1143 Parameters
1144 ----------
1145 exp1 : `~lsst.afw.image.Exposure`
1146 Exposure with the reference point spread function (PSF) to evaluate.
1147 exp2 : `~lsst.afw.image.Exposure`
1148 Exposure with a candidate point spread function (PSF) to evaluate.
1149 fwhmExposureBuffer : `float`
1150 Fractional buffer margin to be left out of all sides of the image
1151 during the construction of the grid to compute mean PSF FWHM in an
1152 exposure, if the PSF is not available at its average position.
1153 fwhmExposureGrid : `int`
1154 Grid size to compute the mean FWHM in an exposure, if the PSF is not
1155 available at its average position.
1156 Returns
1157 -------
1158 result : `bool`
1159 True if ``exp1`` has a PSF that is not wider than that of ``exp2`` in
1160 either dimension.
1161 """
1162 try:
1163 shape1 = getPsfFwhm(exp1.psf, average=False)
1164 shape2 = getPsfFwhm(exp2.psf, average=False)
1166 shape1 = evaluateMeanPsfFwhm(exp1,
1167 fwhmExposureBuffer=fwhmExposureBuffer,
1168 fwhmExposureGrid=fwhmExposureGrid
1169 )
1170 shape2 = evaluateMeanPsfFwhm(exp2,
1171 fwhmExposureBuffer=fwhmExposureBuffer,
1172 fwhmExposureGrid=fwhmExposureGrid
1173 )
1174 return shape1 <= shape2
1175
1176 # Results from getPsfFwhm is a tuple of two values, one for each dimension.
1177 xTest = shape1[0] <= shape2[0]
1178 yTest = shape1[1] <= shape2[1]
1179 return xTest | yTest
1180
1181
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 1116 of file subtractImages.py.

1116def _subtractImages(science, template, backgroundModel=None):
1117 """Subtract template from science, propagating relevant metadata.
1118
1119 Parameters
1120 ----------
1121 science : `lsst.afw.Exposure`
1122 The input science image.
1123 template : `lsst.afw.Exposure`
1124 The template to subtract from the science image.
1125 backgroundModel : `lsst.afw.MaskedImage`, optional
1126 Differential background model
1127
1128 Returns
1129 -------
1130 difference : `lsst.afw.Exposure`
1131 The subtracted image.
1132 """
1133 difference = science.clone()
1134 if backgroundModel is not None:
1135 difference.maskedImage -= backgroundModel
1136 difference.maskedImage -= template.maskedImage
1137 return difference
1138
1139

◆ 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 1072 of file subtractImages.py.

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

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.