LSST Applications g0f08755f38+9c285cab97,g1635faa6d4+13f3999e92,g1653933729+a8ce1bb630,g1a0ca8cf93+bf6eb00ceb,g28da252d5a+0829b12dee,g29321ee8c0+5700dc9eac,g2bbee38e9b+9634bc57db,g2bc492864f+9634bc57db,g2cdde0e794+c2c89b37c4,g3156d2b45e+41e33cbcdc,g347aa1857d+9634bc57db,g35bb328faa+a8ce1bb630,g3a166c0a6a+9634bc57db,g3e281a1b8c+9f2c4e2fc3,g414038480c+077ccc18e7,g41af890bb2+fde0dd39b6,g5fbc88fb19+17cd334064,g781aacb6e4+a8ce1bb630,g80478fca09+55a9465950,g82479be7b0+d730eedb7d,g858d7b2824+9c285cab97,g9125e01d80+a8ce1bb630,g9726552aa6+10f999ec6a,ga5288a1d22+2a84bb7594,gacf8899fa4+c69c5206e8,gae0086650b+a8ce1bb630,gb58c049af0+d64f4d3760,gc28159a63d+9634bc57db,gcf0d15dbbd+4b7d09cae4,gda3e153d99+9c285cab97,gda6a2b7d83+4b7d09cae4,gdaeeff99f8+1711a396fd,ge2409df99d+5e831397f4,ge79ae78c31+9634bc57db,gf0baf85859+147a0692ba,gf3967379c6+41c94011de,gf3fb38a9a8+8f07a9901b,gfb92a5be7c+9c285cab97,w.2024.46
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 1261 of file subtractImages.py.

1261def _interpolateImage(maskedImage, badMaskPlanes, fallbackValue=None):
1262 """Replace masked image pixels with interpolated values.
1263
1264 Parameters
1265 ----------
1266 maskedImage : `lsst.afw.image.MaskedImage`
1267 Image on which to perform interpolation.
1268 badMaskPlanes : `list` of `str`
1269 List of mask planes to interpolate over.
1270 fallbackValue : `float`, optional
1271 Value to set when interpolation fails.
1272
1273 Returns
1274 -------
1275 result: `float`
1276 The number of masked pixels that were replaced.
1277 """
1278 imgBadMaskPlanes = [
1279 maskPlane for maskPlane in badMaskPlanes if maskPlane in maskedImage.mask.getMaskPlaneDict()
1280 ]
1281
1282 image = maskedImage.image.array
1283 badPixels = (maskedImage.mask.array & maskedImage.mask.getPlaneBitMask(imgBadMaskPlanes)) > 0
1284 image[badPixels] = np.nan
1285 if fallbackValue is None:
1286 fallbackValue = np.nanmedian(image)
1287 # For this initial implementation, skip the interpolation and just fill with
1288 # the median value.
1289 image[badPixels] = fallbackValue
1290 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 1219 of file subtractImages.py.

1219def _shapeTest(exp1, exp2, fwhmExposureBuffer, fwhmExposureGrid):
1220 """Determine that the PSF of ``exp1`` is not wider than that of ``exp2``.
1221
1222 Parameters
1223 ----------
1224 exp1 : `~lsst.afw.image.Exposure`
1225 Exposure with the reference point spread function (PSF) to evaluate.
1226 exp2 : `~lsst.afw.image.Exposure`
1227 Exposure with a candidate point spread function (PSF) to evaluate.
1228 fwhmExposureBuffer : `float`
1229 Fractional buffer margin to be left out of all sides of the image
1230 during the construction of the grid to compute mean PSF FWHM in an
1231 exposure, if the PSF is not available at its average position.
1232 fwhmExposureGrid : `int`
1233 Grid size to compute the mean FWHM in an exposure, if the PSF is not
1234 available at its average position.
1235 Returns
1236 -------
1237 result : `bool`
1238 True if ``exp1`` has a PSF that is not wider than that of ``exp2`` in
1239 either dimension.
1240 """
1241 try:
1242 shape1 = getPsfFwhm(exp1.psf, average=False)
1243 shape2 = getPsfFwhm(exp2.psf, average=False)
1245 shape1 = evaluateMeanPsfFwhm(exp1,
1246 fwhmExposureBuffer=fwhmExposureBuffer,
1247 fwhmExposureGrid=fwhmExposureGrid
1248 )
1249 shape2 = evaluateMeanPsfFwhm(exp2,
1250 fwhmExposureBuffer=fwhmExposureBuffer,
1251 fwhmExposureGrid=fwhmExposureGrid
1252 )
1253 return shape1 <= shape2
1254
1255 # Results from getPsfFwhm is a tuple of two values, one for each dimension.
1256 xTest = shape1[0] <= shape2[0]
1257 yTest = shape1[1] <= shape2[1]
1258 return xTest | yTest
1259
1260
Reports invalid arguments.
Definition Runtime.h:66
Reports when the result of an operation cannot be represented by the destination type.
Definition Runtime.h:115

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

1195def _subtractImages(science, template, backgroundModel=None):
1196 """Subtract template from science, propagating relevant metadata.
1197
1198 Parameters
1199 ----------
1200 science : `lsst.afw.Exposure`
1201 The input science image.
1202 template : `lsst.afw.Exposure`
1203 The template to subtract from the science image.
1204 backgroundModel : `lsst.afw.MaskedImage`, optional
1205 Differential background model
1206
1207 Returns
1208 -------
1209 difference : `lsst.afw.Exposure`
1210 The subtracted image.
1211 """
1212 difference = science.clone()
1213 if backgroundModel is not None:
1214 difference.maskedImage -= backgroundModel
1215 difference.maskedImage -= template.maskedImage
1216 return difference
1217
1218

◆ 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 : `logging.Logger`
    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 1151 of file subtractImages.py.

1152 exceptionMessage=""):
1153 """Raise NoWorkFound if template coverage < requiredTemplateFraction
1154
1155 Parameters
1156 ----------
1157 templateExposure : `lsst.afw.image.ExposureF`
1158 The template exposure to check
1159 logger : `logging.Logger`
1160 Logger for printing output.
1161 requiredTemplateFraction : `float`, optional
1162 Fraction of pixels of the science image required to have coverage
1163 in the template.
1164 exceptionMessage : `str`, optional
1165 Message to include in the exception raised if the template coverage
1166 is insufficient.
1167
1168 Returns
1169 -------
1170 templateCoverageFraction: `float`
1171 Fraction of pixels in the template with data.
1172
1173 Raises
1174 ------
1175 lsst.pipe.base.NoWorkFound
1176 Raised if fraction of good pixels, defined as not having NO_DATA
1177 set, is less than the requiredTemplateFraction
1178 """
1179 # Count the number of pixels with the NO_DATA mask bit set
1180 # counting NaN pixels is insufficient because pixels without data are often intepolated over)
1181 pixNoData = np.count_nonzero(templateExposure.mask.array
1182 & templateExposure.mask.getPlaneBitMask('NO_DATA'))
1183 pixGood = templateExposure.getBBox().getArea() - pixNoData
1184 templateCoverageFraction = pixGood/templateExposure.getBBox().getArea()
1185 logger.info("template has %d good pixels (%.1f%%)", pixGood, 100*templateCoverageFraction)
1186
1187 if templateCoverageFraction < requiredTemplateFraction:
1188 message = ("Insufficient Template Coverage. (%.1f%% < %.1f%%)" % (
1189 100*templateCoverageFraction,
1190 100*requiredTemplateFraction))
1191 raise lsst.pipe.base.NoWorkFound(message + " " + exceptionMessage)
1192 return templateCoverageFraction
1193
1194

Variable Documentation

◆ _defaultTemplates

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

Definition at line 42 of file subtractImages.py.

◆ _dimensions

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

Definition at line 41 of file subtractImages.py.