LSST Applications g013ef56533+d2224463a4,g199a45376c+0ba108daf9,g19c4beb06c+9f335b2115,g1fd858c14a+2459ca3e43,g210f2d0738+2d3d333a78,g262e1987ae+abbb004f04,g2825c19fe3+eedc38578d,g29ae962dfc+0cb55f06ef,g2cef7863aa+aef1011c0b,g35bb328faa+8c5ae1fdc5,g3fd5ace14f+19c3a54948,g47891489e3+501a489530,g4cdb532a89+a047e97985,g511e8cfd20+ce1f47b6d6,g53246c7159+8c5ae1fdc5,g54cd7ddccb+890c8e1e5d,g5fd55ab2c7+951cc3f256,g64539dfbff+2d3d333a78,g67b6fd64d1+501a489530,g67fd3c3899+2d3d333a78,g74acd417e5+0ea5dee12c,g786e29fd12+668abc6043,g87389fa792+8856018cbb,g89139ef638+501a489530,g8d7436a09f+5ea4c44d25,g8ea07a8fe4+81eaaadc04,g90f42f885a+34c0557caf,g9486f8a5af+165c016931,g97be763408+d5e351dcc8,gbf99507273+8c5ae1fdc5,gc2a301910b+2d3d333a78,gca7fc764a6+501a489530,gce8aa8abaa+8c5ae1fdc5,gd7ef33dd92+501a489530,gdab6d2f7ff+0ea5dee12c,ge410e46f29+501a489530,geaed405ab2+e3b4b2a692,gf9a733ac38+8c5ae1fdc5,w.2025.41
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 1531 of file subtractImages.py.

1531def _interpolateImage(maskedImage, badMaskPlanes, fallbackValue=None):
1532 """Replace masked image pixels with interpolated values.
1533
1534 Parameters
1535 ----------
1536 maskedImage : `lsst.afw.image.MaskedImage`
1537 Image on which to perform interpolation.
1538 badMaskPlanes : `list` of `str`
1539 List of mask planes to interpolate over.
1540 fallbackValue : `float`, optional
1541 Value to set when interpolation fails.
1542
1543 Returns
1544 -------
1545 result: `float`
1546 The number of masked pixels that were replaced.
1547 """
1548 imgBadMaskPlanes = [
1549 maskPlane for maskPlane in badMaskPlanes if maskPlane in maskedImage.mask.getMaskPlaneDict()
1550 ]
1551
1552 image = maskedImage.image.array
1553 badPixels = (maskedImage.mask.array & maskedImage.mask.getPlaneBitMask(imgBadMaskPlanes)) > 0
1554 image[badPixels] = np.nan
1555 if fallbackValue is None:
1556 fallbackValue = np.nanmedian(image)
1557 # For this initial implementation, skip the interpolation and just fill with
1558 # the median value.
1559 image[badPixels] = fallbackValue
1560 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 1396 of file subtractImages.py.

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

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

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

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

Variable Documentation

◆ _defaultTemplates

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

Definition at line 45 of file subtractImages.py.

◆ _dimensions

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

Definition at line 44 of file subtractImages.py.