LSST Applications  21.0.0-147-g0e635eb1+1acddb5be5,22.0.0+052faf71bd,22.0.0+1ea9a8b2b2,22.0.0+6312710a6c,22.0.0+729191ecac,22.0.0+7589c3a021,22.0.0+9f079a9461,22.0.1-1-g7d6de66+b8044ec9de,22.0.1-1-g87000a6+536b1ee016,22.0.1-1-g8e32f31+6312710a6c,22.0.1-10-gd060f87+016f7cdc03,22.0.1-12-g9c3108e+df145f6f68,22.0.1-16-g314fa6d+c825727ab8,22.0.1-19-g93a5c75+d23f2fb6d8,22.0.1-19-gb93eaa13+aab3ef7709,22.0.1-2-g8ef0a89+b8044ec9de,22.0.1-2-g92698f7+9f079a9461,22.0.1-2-ga9b0f51+052faf71bd,22.0.1-2-gac51dbf+052faf71bd,22.0.1-2-gb66926d+6312710a6c,22.0.1-2-gcb770ba+09e3807989,22.0.1-20-g32debb5+b8044ec9de,22.0.1-23-gc2439a9a+fb0756638e,22.0.1-3-g496fd5d+09117f784f,22.0.1-3-g59f966b+1e6ba2c031,22.0.1-3-g849a1b8+f8b568069f,22.0.1-3-gaaec9c0+c5c846a8b1,22.0.1-32-g5ddfab5d3+60ce4897b0,22.0.1-4-g037fbe1+64e601228d,22.0.1-4-g8623105+b8044ec9de,22.0.1-5-g096abc9+d18c45d440,22.0.1-5-g15c806e+57f5c03693,22.0.1-7-gba73697+57f5c03693,master-g6e05de7fdc+c1283a92b8,master-g72cdda8301+729191ecac,w.2021.39
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: