LSST Applications g04a91732dc+146a938ab0,g07dc498a13+80b84b0d75,g0fba68d861+0decac7526,g1409bbee79+80b84b0d75,g1a7e361dbc+80b84b0d75,g1fd858c14a+f6e422e056,g20f46db602+483a84333a,g21d47ad084+4a6cd485de,g35bb328faa+fcb1d3bbc8,g42c1b31a95+a1301e4c20,g4d39ba7253+9b833be27e,g4e0f332c67+5d362be553,g53246c7159+fcb1d3bbc8,g60b5630c4e+9b833be27e,g78460c75b0+2f9a1b4bcd,g786e29fd12+cf7ec2a62a,g7b71ed6315+fcb1d3bbc8,g8852436030+790117df0f,g89139ef638+80b84b0d75,g8d6b6b353c+9b833be27e,g9125e01d80+fcb1d3bbc8,g989de1cb63+80b84b0d75,g9f33ca652e+9c6b68d7f3,ga9baa6287d+9b833be27e,gaaedd4e678+80b84b0d75,gabe3b4be73+1e0a283bba,gb1101e3267+9f3571abad,gb58c049af0+f03b321e39,gb90eeb9370+691e4ab549,gc741bbaa4f+5f483edd21,gcf25f946ba+790117df0f,gd24842266e+c54cdbdbd2,gd315a588df+5b65d88fe4,gd6cbbdb0b4+c8606af20c,gd9a9a58781+fcb1d3bbc8,gde0f65d7ad+c99546153d,ge278dab8ac+932305ba37,ge82c20c137+76d20ab76d,w.2025.10
LSST Data Management Base Package
Loading...
Searching...
No Matches
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 1325 of file subtractImages.py.

1325def _interpolateImage(maskedImage, badMaskPlanes, fallbackValue=None):
1326 """Replace masked image pixels with interpolated values.
1327
1328 Parameters
1329 ----------
1330 maskedImage : `lsst.afw.image.MaskedImage`
1331 Image on which to perform interpolation.
1332 badMaskPlanes : `list` of `str`
1333 List of mask planes to interpolate over.
1334 fallbackValue : `float`, optional
1335 Value to set when interpolation fails.
1336
1337 Returns
1338 -------
1339 result: `float`
1340 The number of masked pixels that were replaced.
1341 """
1342 imgBadMaskPlanes = [
1343 maskPlane for maskPlane in badMaskPlanes if maskPlane in maskedImage.mask.getMaskPlaneDict()
1344 ]
1345
1346 image = maskedImage.image.array
1347 badPixels = (maskedImage.mask.array & maskedImage.mask.getPlaneBitMask(imgBadMaskPlanes)) > 0
1348 image[badPixels] = np.nan
1349 if fallbackValue is None:
1350 fallbackValue = np.nanmedian(image)
1351 # For this initial implementation, skip the interpolation and just fill with
1352 # the median value.
1353 image[badPixels] = fallbackValue
1354 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 1283 of file subtractImages.py.

1283def _shapeTest(exp1, exp2, fwhmExposureBuffer, fwhmExposureGrid):
1284 """Determine that the PSF of ``exp1`` is not wider than that of ``exp2``.
1285
1286 Parameters
1287 ----------
1288 exp1 : `~lsst.afw.image.Exposure`
1289 Exposure with the reference point spread function (PSF) to evaluate.
1290 exp2 : `~lsst.afw.image.Exposure`
1291 Exposure with a candidate point spread function (PSF) to evaluate.
1292 fwhmExposureBuffer : `float`
1293 Fractional buffer margin to be left out of all sides of the image
1294 during the construction of the grid to compute mean PSF FWHM in an
1295 exposure, if the PSF is not available at its average position.
1296 fwhmExposureGrid : `int`
1297 Grid size to compute the mean FWHM in an exposure, if the PSF is not
1298 available at its average position.
1299 Returns
1300 -------
1301 result : `bool`
1302 True if ``exp1`` has a PSF that is not wider than that of ``exp2`` in
1303 either dimension.
1304 """
1305 try:
1306 shape1 = getPsfFwhm(exp1.psf, average=False)
1307 shape2 = getPsfFwhm(exp2.psf, average=False)
1309 shape1 = evaluateMeanPsfFwhm(exp1,
1310 fwhmExposureBuffer=fwhmExposureBuffer,
1311 fwhmExposureGrid=fwhmExposureGrid
1312 )
1313 shape2 = evaluateMeanPsfFwhm(exp2,
1314 fwhmExposureBuffer=fwhmExposureBuffer,
1315 fwhmExposureGrid=fwhmExposureGrid
1316 )
1317 return shape1 <= shape2
1318
1319 # Results from getPsfFwhm is a tuple of two values, one for each dimension.
1320 xTest = shape1[0] <= shape2[0]
1321 yTest = shape1[1] <= shape2[1]
1322 return xTest | yTest
1323
1324
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 1259 of file subtractImages.py.

1259def _subtractImages(science, template, backgroundModel=None):
1260 """Subtract template from science, propagating relevant metadata.
1261
1262 Parameters
1263 ----------
1264 science : `lsst.afw.Exposure`
1265 The input science image.
1266 template : `lsst.afw.Exposure`
1267 The template to subtract from the science image.
1268 backgroundModel : `lsst.afw.MaskedImage`, optional
1269 Differential background model
1270
1271 Returns
1272 -------
1273 difference : `lsst.afw.Exposure`
1274 The subtracted image.
1275 """
1276 difference = science.clone()
1277 if backgroundModel is not None:
1278 difference.maskedImage -= backgroundModel
1279 difference.maskedImage -= template.maskedImage
1280 return difference
1281
1282

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

1216 exceptionMessage=""):
1217 """Raise NoWorkFound if template coverage < requiredTemplateFraction
1218
1219 Parameters
1220 ----------
1221 templateExposure : `lsst.afw.image.ExposureF`
1222 The template exposure to check
1223 logger : `logging.Logger`
1224 Logger for printing output.
1225 requiredTemplateFraction : `float`, optional
1226 Fraction of pixels of the science image required to have coverage
1227 in the template.
1228 exceptionMessage : `str`, optional
1229 Message to include in the exception raised if the template coverage
1230 is insufficient.
1231
1232 Returns
1233 -------
1234 templateCoverageFraction: `float`
1235 Fraction of pixels in the template with data.
1236
1237 Raises
1238 ------
1239 lsst.pipe.base.NoWorkFound
1240 Raised if fraction of good pixels, defined as not having NO_DATA
1241 set, is less than the requiredTemplateFraction
1242 """
1243 # Count the number of pixels with the NO_DATA mask bit set
1244 # counting NaN pixels is insufficient because pixels without data are often intepolated over)
1245 pixNoData = np.count_nonzero(templateExposure.mask.array
1246 & templateExposure.mask.getPlaneBitMask('NO_DATA'))
1247 pixGood = templateExposure.getBBox().getArea() - pixNoData
1248 templateCoverageFraction = pixGood/templateExposure.getBBox().getArea()
1249 logger.info("template has %d good pixels (%.1f%%)", pixGood, 100*templateCoverageFraction)
1250
1251 if templateCoverageFraction < requiredTemplateFraction:
1252 message = ("Insufficient Template Coverage. (%.1f%% < %.1f%%)" % (
1253 100*templateCoverageFraction,
1254 100*requiredTemplateFraction))
1255 raise lsst.pipe.base.NoWorkFound(message + " " + exceptionMessage)
1256 return templateCoverageFraction
1257
1258

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.