LSST Applications g042eb84c57+730a74494b,g04e9c324dd+8c5ae1fdc5,g134cb467dc+1f1e3e7524,g199a45376c+0ba108daf9,g1fd858c14a+fa7d31856b,g210f2d0738+f66ac109ec,g262e1987ae+83a3acc0e5,g29ae962dfc+d856a2cb1f,g2cef7863aa+aef1011c0b,g35bb328faa+8c5ae1fdc5,g3fd5ace14f+a1e0c9f713,g47891489e3+0d594cb711,g4d44eb3520+c57ec8f3ed,g4d7b6aa1c5+f66ac109ec,g53246c7159+8c5ae1fdc5,g56a1a4eaf3+fd7ad03fde,g64539dfbff+f66ac109ec,g67b6fd64d1+0d594cb711,g67fd3c3899+f66ac109ec,g6985122a63+0d594cb711,g74acd417e5+3098891321,g786e29fd12+668abc6043,g81db2e9a8d+98e2ab9f28,g87389fa792+8856018cbb,g89139ef638+0d594cb711,g8d7436a09f+80fda9ce03,g8ea07a8fe4+760ca7c3fc,g90f42f885a+033b1d468d,g97be763408+a8a29bda4b,g99822b682c+e3ec3c61f9,g9d5c6a246b+0d5dac0c3d,ga41d0fce20+9243b26dd2,gbf99507273+8c5ae1fdc5,gd7ef33dd92+0d594cb711,gdab6d2f7ff+3098891321,ge410e46f29+0d594cb711,geaed405ab2+c4bbc419c6,gf9a733ac38+8c5ae1fdc5,w.2025.38
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 1584 of file subtractImages.py.

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

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

1365def _subtractImages(science, template, backgroundModel=None):
1366 """Subtract template from science, propagating relevant metadata.
1367
1368 Parameters
1369 ----------
1370 science : `lsst.afw.Exposure`
1371 The input science image.
1372 template : `lsst.afw.Exposure`
1373 The template to subtract from the science image.
1374 backgroundModel : `lsst.afw.MaskedImage`, optional
1375 Differential background model
1376
1377 Returns
1378 -------
1379 difference : `lsst.afw.Exposure`
1380 The subtracted image.
1381 """
1382 difference = science.clone()
1383 if backgroundModel is not None:
1384 difference.maskedImage -= backgroundModel
1385 difference.maskedImage -= template.maskedImage
1386 return difference
1387
1388

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

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

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.