LSST Applications  21.0.0-172-gfb10e10a+18fedfabac,22.0.0+297cba6710,22.0.0+80564b0ff1,22.0.0+8d77f4f51a,22.0.0+a28f4c53b1,22.0.0+dcf3732eb2,22.0.1-1-g7d6de66+2a20fdde0d,22.0.1-1-g8e32f31+297cba6710,22.0.1-1-geca5380+7fa3b7d9b6,22.0.1-12-g44dc1dc+2a20fdde0d,22.0.1-15-g6a90155+515f58c32b,22.0.1-16-g9282f48+790f5f2caa,22.0.1-2-g92698f7+dcf3732eb2,22.0.1-2-ga9b0f51+7fa3b7d9b6,22.0.1-2-gd1925c9+bf4f0e694f,22.0.1-24-g1ad7a390+a9625a72a8,22.0.1-25-g5bf6245+3ad8ecd50b,22.0.1-25-gb120d7b+8b5510f75f,22.0.1-27-g97737f7+2a20fdde0d,22.0.1-32-gf62ce7b1+aa4237961e,22.0.1-4-g0b3f228+2a20fdde0d,22.0.1-4-g243d05b+871c1b8305,22.0.1-4-g3a563be+32dcf1063f,22.0.1-4-g44f2e3d+9e4ab0f4fa,22.0.1-42-gca6935d93+ba5e5ca3eb,22.0.1-5-g15c806e+85460ae5f3,22.0.1-5-g58711c4+611d128589,22.0.1-5-g75bb458+99c117b92f,22.0.1-6-g1c63a23+7fa3b7d9b6,22.0.1-6-g50866e6+84ff5a128b,22.0.1-6-g8d3140d+720564cf76,22.0.1-6-gd805d02+cc5644f571,22.0.1-8-ge5750ce+85460ae5f3,master-g6e05de7fdc+babf819c66,master-g99da0e417a+8d77f4f51a,w.2021.48
LSST Data Management Base Package
Public Member Functions | Public Attributes | Static Public Attributes | List of all members
lsst.ip.diffim.imageDecorrelation.DecorrelateALKernelSpatialTask Class Reference
Inheritance diagram for lsst.ip.diffim.imageDecorrelation.DecorrelateALKernelSpatialTask:

Public Member Functions

def __init__ (self, *args, **kwargs)
 
def computeVarianceMean (self, exposure)
 
def run (self, scienceExposure, templateExposure, subtractedExposure, psfMatchingKernel, spatiallyVarying=True, preConvKernel=None, templateMatched=True, preConvMode=False)
 

Public Attributes

 statsControl
 

Static Public Attributes

 ConfigClass = DecorrelateALKernelSpatialConfig
 

Detailed Description

Decorrelate the effect of convolution by Alard-Lupton matching kernel in image difference

Notes
-----

Pipe-task that removes the neighboring-pixel covariance in an
image difference that are added when the template image is
convolved with the Alard-Lupton PSF matching kernel.

This task is a simple wrapper around @ref DecorrelateALKernelTask,
which takes a `spatiallyVarying` parameter in its `run` method. If
it is `False`, then it simply calls the `run` method of @ref
DecorrelateALKernelTask. If it is True, then it uses the @ref
ImageMapReduceTask framework to break the exposures into
subExposures on a grid, and performs the `run` method of @ref
DecorrelateALKernelTask on each subExposure. This enables it to
account for spatially-varying PSFs and noise in the exposures when
performing the decorrelation.

This task has no standalone example, however it is applied as a
subtask of pipe.tasks.imageDifference.ImageDifferenceTask.
There is also an example of its use in `tests/testImageDecorrelation.py`.

Definition at line 788 of file imageDecorrelation.py.

Constructor & Destructor Documentation

◆ __init__()

def lsst.ip.diffim.imageDecorrelation.DecorrelateALKernelSpatialTask.__init__ (   self,
args,
**  kwargs 
)
Create the image decorrelation Task

Parameters
----------
args :
    arguments to be passed to
    `lsst.pipe.base.task.Task.__init__`
kwargs :
    additional keyword arguments to be passed to
    `lsst.pipe.base.task.Task.__init__`

Definition at line 815 of file imageDecorrelation.py.

815  def __init__(self, *args, **kwargs):
816  """Create the image decorrelation Task
817 
818  Parameters
819  ----------
820  args :
821  arguments to be passed to
822  `lsst.pipe.base.task.Task.__init__`
823  kwargs :
824  additional keyword arguments to be passed to
825  `lsst.pipe.base.task.Task.__init__`
826  """
827  pipeBase.Task.__init__(self, *args, **kwargs)
828 
829  self.statsControl = afwMath.StatisticsControl()
830  self.statsControl.setNumSigmaClip(3.)
831  self.statsControl.setNumIter(3)
832  self.statsControl.setAndMask(afwImage.Mask.getPlaneBitMask(self.config.ignoreMaskPlanes))
833 
Pass parameters to a Statistics object.
Definition: Statistics.h:92

Member Function Documentation

◆ computeVarianceMean()

def lsst.ip.diffim.imageDecorrelation.DecorrelateALKernelSpatialTask.computeVarianceMean (   self,
  exposure 
)
Compute the mean of the variance plane of `exposure`.

Definition at line 834 of file imageDecorrelation.py.

834  def computeVarianceMean(self, exposure):
835  """Compute the mean of the variance plane of `exposure`.
836  """
837  statObj = afwMath.makeStatistics(exposure.getMaskedImage().getVariance(),
838  exposure.getMaskedImage().getMask(),
839  afwMath.MEANCLIP, self.statsControl)
840  var = statObj.getValue(afwMath.MEANCLIP)
841  return var
842 
Statistics makeStatistics(lsst::afw::image::Image< Pixel > const &img, lsst::afw::image::Mask< image::MaskPixel > const &msk, int const flags, StatisticsControl const &sctrl=StatisticsControl())
Handle a watered-down front-end to the constructor (no variance)
Definition: Statistics.h:359

◆ run()

def lsst.ip.diffim.imageDecorrelation.DecorrelateALKernelSpatialTask.run (   self,
  scienceExposure,
  templateExposure,
  subtractedExposure,
  psfMatchingKernel,
  spatiallyVarying = True,
  preConvKernel = None,
  templateMatched = True,
  preConvMode = False 
)
Perform decorrelation of an image difference exposure.

Decorrelates the diffim due to the convolution of the
templateExposure with the A&L psfMatchingKernel. If
`spatiallyVarying` is True, it utilizes the spatially varying
matching kernel via the `imageMapReduce` framework to perform
spatially-varying decorrelation on a grid of subExposures.

Parameters
----------
scienceExposure : `lsst.afw.image.Exposure`
   the science Exposure used for PSF matching
templateExposure : `lsst.afw.image.Exposure`
   the template Exposure used for PSF matching
subtractedExposure : `lsst.afw.image.Exposure`
   the subtracted Exposure produced by `ip_diffim.ImagePsfMatchTask.subtractExposures()`
psfMatchingKernel : an (optionally spatially-varying) PSF matching kernel produced
   by `ip_diffim.ImagePsfMatchTask.subtractExposures()`
spatiallyVarying : `bool`
   if True, perform the spatially-varying operation
preConvKernel : `lsst.meas.algorithms.Psf`
   if not none, the scienceExposure has been pre-filtered with this kernel. (Currently
   this option is experimental.)
templateMatched : `bool`, optional
   If True, the template exposure was matched (convolved) to the science exposure.
preConvMode : `bool`, optional
    If True, ``subtractedExposure`` is assumed to be a likelihood difference image
    and will be noise corrected as a likelihood image.

Returns
-------
results : `lsst.pipe.base.Struct`
    a structure containing:
    - ``correctedExposure`` : the decorrelated diffim

Definition at line 843 of file imageDecorrelation.py.

844  spatiallyVarying=True, preConvKernel=None, templateMatched=True, preConvMode=False):
845  """Perform decorrelation of an image difference exposure.
846 
847  Decorrelates the diffim due to the convolution of the
848  templateExposure with the A&L psfMatchingKernel. If
849  `spatiallyVarying` is True, it utilizes the spatially varying
850  matching kernel via the `imageMapReduce` framework to perform
851  spatially-varying decorrelation on a grid of subExposures.
852 
853  Parameters
854  ----------
855  scienceExposure : `lsst.afw.image.Exposure`
856  the science Exposure used for PSF matching
857  templateExposure : `lsst.afw.image.Exposure`
858  the template Exposure used for PSF matching
859  subtractedExposure : `lsst.afw.image.Exposure`
860  the subtracted Exposure produced by `ip_diffim.ImagePsfMatchTask.subtractExposures()`
861  psfMatchingKernel : an (optionally spatially-varying) PSF matching kernel produced
862  by `ip_diffim.ImagePsfMatchTask.subtractExposures()`
863  spatiallyVarying : `bool`
864  if True, perform the spatially-varying operation
865  preConvKernel : `lsst.meas.algorithms.Psf`
866  if not none, the scienceExposure has been pre-filtered with this kernel. (Currently
867  this option is experimental.)
868  templateMatched : `bool`, optional
869  If True, the template exposure was matched (convolved) to the science exposure.
870  preConvMode : `bool`, optional
871  If True, ``subtractedExposure`` is assumed to be a likelihood difference image
872  and will be noise corrected as a likelihood image.
873 
874  Returns
875  -------
876  results : `lsst.pipe.base.Struct`
877  a structure containing:
878  - ``correctedExposure`` : the decorrelated diffim
879  """
880  self.log.info('Running A&L decorrelation: spatiallyVarying=%r', spatiallyVarying)
881 
882  svar = self.computeVarianceMean(scienceExposure)
883  tvar = self.computeVarianceMean(templateExposure)
884  if np.isnan(svar) or np.isnan(tvar): # Should not happen unless entire image has been masked.
885  # Double check that one of the exposures is all NaNs
886  if (np.all(np.isnan(scienceExposure.image.array))
887  or np.all(np.isnan(templateExposure.image.array))):
888  self.log.warning('Template or science image is entirely NaNs: skipping decorrelation.')
889  if np.isnan(svar):
890  svar = 1e-9
891  if np.isnan(tvar):
892  tvar = 1e-9
893 
894  var = self.computeVarianceMean(subtractedExposure)
895 
896  if spatiallyVarying:
897  self.log.info("Variance (science, template): (%f, %f)", svar, tvar)
898  self.log.info("Variance (uncorrected diffim): %f", var)
899  config = self.config.decorrelateMapReduceConfig
900  task = ImageMapReduceTask(config=config)
901  results = task.run(subtractedExposure, science=scienceExposure,
902  template=templateExposure, psfMatchingKernel=psfMatchingKernel,
903  preConvKernel=preConvKernel, forceEvenSized=True,
904  templateMatched=templateMatched, preConvMode=preConvMode)
905  results.correctedExposure = results.exposure
906 
907  # Make sure masks of input image are propagated to diffim
908  def gm(exp):
909  return exp.getMaskedImage().getMask()
910  gm(results.correctedExposure)[:, :] = gm(subtractedExposure)
911 
912  var = self.computeVarianceMean(results.correctedExposure)
913  self.log.info("Variance (corrected diffim): %f", var)
914 
915  else:
916  config = self.config.decorrelateConfig
917  task = DecorrelateALKernelTask(config=config)
918  results = task.run(scienceExposure, templateExposure,
919  subtractedExposure, psfMatchingKernel, preConvKernel=preConvKernel,
920  templateMatched=templateMatched, preConvMode=preConvMode)
921 
922  return results

Member Data Documentation

◆ ConfigClass

lsst.ip.diffim.imageDecorrelation.DecorrelateALKernelSpatialTask.ConfigClass = DecorrelateALKernelSpatialConfig
static

Definition at line 812 of file imageDecorrelation.py.

◆ statsControl

lsst.ip.diffim.imageDecorrelation.DecorrelateALKernelSpatialTask.statsControl

Definition at line 829 of file imageDecorrelation.py.


The documentation for this class was generated from the following file: