LSST Applications g04e9c324dd+8c5ae1fdc5,g134cb467dc+1b3060144d,g18429d2f64+f642bf4753,g199a45376c+0ba108daf9,g1fd858c14a+2dcf163641,g262e1987ae+7b8c96d2ca,g29ae962dfc+3bd6ecb08a,g2cef7863aa+aef1011c0b,g35bb328faa+8c5ae1fdc5,g3fd5ace14f+53e1a9e7c5,g4595892280+fef73a337f,g47891489e3+2efcf17695,g4d44eb3520+642b70b07e,g53246c7159+8c5ae1fdc5,g67b6fd64d1+2efcf17695,g67fd3c3899+b70e05ef52,g74acd417e5+317eb4c7d4,g786e29fd12+668abc6043,g87389fa792+8856018cbb,g89139ef638+2efcf17695,g8d7436a09f+3be3c13596,g8ea07a8fe4+9f5ccc88ac,g90f42f885a+a4e7b16d9b,g97be763408+ad77d7208f,g9dd6db0277+b70e05ef52,ga681d05dcb+a3f46e7fff,gabf8522325+735880ea63,gac2eed3f23+2efcf17695,gb89ab40317+2efcf17695,gbf99507273+8c5ae1fdc5,gd8ff7fe66e+b70e05ef52,gdab6d2f7ff+317eb4c7d4,gdc713202bf+b70e05ef52,gdfd2d52018+b10e285e0f,ge365c994fd+310e8507c4,ge410e46f29+2efcf17695,geaed405ab2+562b3308c0,gffca2db377+8c5ae1fdc5,w.2025.35
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  InsufficientKernelSourcesError
 
class  SimplifiedSubtractConfig
 
class  SimplifiedSubtractConnections
 
class  SimplifiedSubtractTask
 
class  SubtractImageOutputConnections
 
class  SubtractInputConnections
 
class  SubtractScoreOutputConnections
 

Functions

 checkTemplateIsSufficient (templateExposure, scienceExposure, 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 1572 of file subtractImages.py.

1572def _interpolateImage(maskedImage, badMaskPlanes, fallbackValue=None):
1573 """Replace masked image pixels with interpolated values.
1574
1575 Parameters
1576 ----------
1577 maskedImage : `lsst.afw.image.MaskedImage`
1578 Image on which to perform interpolation.
1579 badMaskPlanes : `list` of `str`
1580 List of mask planes to interpolate over.
1581 fallbackValue : `float`, optional
1582 Value to set when interpolation fails.
1583
1584 Returns
1585 -------
1586 result: `float`
1587 The number of masked pixels that were replaced.
1588 """
1589 imgBadMaskPlanes = [
1590 maskPlane for maskPlane in badMaskPlanes if maskPlane in maskedImage.mask.getMaskPlaneDict()
1591 ]
1592
1593 image = maskedImage.image.array
1594 badPixels = (maskedImage.mask.array & maskedImage.mask.getPlaneBitMask(imgBadMaskPlanes)) > 0
1595 image[badPixels] = np.nan
1596 if fallbackValue is None:
1597 fallbackValue = np.nanmedian(image)
1598 # For this initial implementation, skip the interpolation and just fill with
1599 # the median value.
1600 image[badPixels] = fallbackValue
1601 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 1377 of file subtractImages.py.

1377def _shapeTest(exp1, exp2, fwhmExposureBuffer, fwhmExposureGrid):
1378 """Determine that the PSF of ``exp1`` is not wider than that of ``exp2``.
1379
1380 Parameters
1381 ----------
1382 exp1 : `~lsst.afw.image.Exposure`
1383 Exposure with the reference point spread function (PSF) to evaluate.
1384 exp2 : `~lsst.afw.image.Exposure`
1385 Exposure with a candidate point spread function (PSF) to evaluate.
1386 fwhmExposureBuffer : `float`
1387 Fractional buffer margin to be left out of all sides of the image
1388 during the construction of the grid to compute mean PSF FWHM in an
1389 exposure, if the PSF is not available at its average position.
1390 fwhmExposureGrid : `int`
1391 Grid size to compute the mean FWHM in an exposure, if the PSF is not
1392 available at its average position.
1393 Returns
1394 -------
1395 result : `bool`
1396 True if ``exp1`` has a PSF that is not wider than that of ``exp2`` in
1397 either dimension.
1398 """
1399 try:
1400 shape1 = getPsfFwhm(exp1.psf, average=False)
1401 shape2 = getPsfFwhm(exp2.psf, average=False)
1403 shape1 = evaluateMeanPsfFwhm(exp1,
1404 fwhmExposureBuffer=fwhmExposureBuffer,
1405 fwhmExposureGrid=fwhmExposureGrid
1406 )
1407 shape2 = evaluateMeanPsfFwhm(exp2,
1408 fwhmExposureBuffer=fwhmExposureBuffer,
1409 fwhmExposureGrid=fwhmExposureGrid
1410 )
1411 return shape1 <= shape2
1412
1413 # Results from getPsfFwhm is a tuple of two values, one for each dimension.
1414 xTest = shape1[0] <= shape2[0]
1415 yTest = shape1[1] <= shape2[1]
1416 return xTest | yTest
1417
1418
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 1353 of file subtractImages.py.

1353def _subtractImages(science, template, backgroundModel=None):
1354 """Subtract template from science, propagating relevant metadata.
1355
1356 Parameters
1357 ----------
1358 science : `lsst.afw.Exposure`
1359 The input science image.
1360 template : `lsst.afw.Exposure`
1361 The template to subtract from the science image.
1362 backgroundModel : `lsst.afw.MaskedImage`, optional
1363 Differential background model
1364
1365 Returns
1366 -------
1367 difference : `lsst.afw.Exposure`
1368 The subtracted image.
1369 """
1370 difference = science.clone()
1371 if backgroundModel is not None:
1372 difference.maskedImage -= backgroundModel
1373 difference.maskedImage -= template.maskedImage
1374 return difference
1375
1376

◆ checkTemplateIsSufficient()

lsst.ip.diffim.subtractImages.checkTemplateIsSufficient ( templateExposure,
scienceExposure,
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 1306 of file subtractImages.py.

1307 exceptionMessage=""):
1308 """Raise NoWorkFound if template coverage < requiredTemplateFraction
1309
1310 Parameters
1311 ----------
1312 templateExposure : `lsst.afw.image.ExposureF`
1313 The template exposure to check
1314 logger : `logging.Logger`
1315 Logger for printing output.
1316 requiredTemplateFraction : `float`, optional
1317 Fraction of pixels of the science image required to have coverage
1318 in the template.
1319 exceptionMessage : `str`, optional
1320 Message to include in the exception raised if the template coverage
1321 is insufficient.
1322
1323 Returns
1324 -------
1325 templateCoverageFraction: `float`
1326 Fraction of pixels in the template with data.
1327
1328 Raises
1329 ------
1330 lsst.pipe.base.NoWorkFound
1331 Raised if fraction of good pixels, defined as not having NO_DATA
1332 set, is less than the requiredTemplateFraction
1333 """
1334 # Count the number of pixels with the NO_DATA mask bit set
1335 # counting NaN pixels is insufficient because pixels without data are often intepolated over)
1336 noTemplate = templateExposure.mask.array & templateExposure.mask.getPlaneBitMask('NO_DATA')
1337 # Also need to account for missing data in the science image,
1338 # because template coverage there doesn't help
1339 noScience = scienceExposure.mask.array & scienceExposure.mask.getPlaneBitMask('NO_DATA')
1340 pixNoData = np.count_nonzero(noTemplate | noScience)
1341 pixGood = templateExposure.getBBox().getArea() - pixNoData
1342 templateCoverageFraction = pixGood/templateExposure.getBBox().getArea()
1343 logger.info("template has %d good pixels (%.1f%%)", pixGood, 100*templateCoverageFraction)
1344
1345 if templateCoverageFraction < requiredTemplateFraction:
1346 message = ("Insufficient Template Coverage. (%.1f%% < %.1f%%)" % (
1347 100*templateCoverageFraction,
1348 100*requiredTemplateFraction))
1349 raise lsst.pipe.base.NoWorkFound(message + " " + exceptionMessage)
1350 return templateCoverageFraction
1351
1352

Variable Documentation

◆ _defaultTemplates

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

Definition at line 44 of file subtractImages.py.

◆ _dimensions

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

Definition at line 43 of file subtractImages.py.