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 | List of all members
lsst.ip.diffim.dcrModel.DcrModel Class Reference

Public Member Functions

def __init__ (self, modelImages, effectiveWavelength, bandwidth, filterLabel=None, psf=None, mask=None, variance=None, photoCalib=None)
 
def fromImage (cls, maskedImage, dcrNumSubfilters, effectiveWavelength, bandwidth, filterLabel=None, psf=None, photoCalib=None)
 
def fromDataRef (cls, dataRef, effectiveWavelength, bandwidth, datasetType="dcrCoadd", numSubfilters=None, **kwargs)
 
def fromQuantum (cls, availableCoaddRefs, effectiveWavelength, bandwidth)
 
def __len__ (self)
 
def __getitem__ (self, subfilter)
 
def __setitem__ (self, subfilter, maskedImage)
 
def effectiveWavelength (self)
 
def filter (self)
 
def bandwidth (self)
 
def psf (self)
 
def bbox (self)
 
def mask (self)
 
def variance (self)
 
def getReferenceImage (self, bbox=None)
 
def assign (self, dcrSubModel, bbox=None)
 
def buildMatchedTemplate (self, exposure=None, order=3, visitInfo=None, bbox=None, wcs=None, mask=None, splitSubfilters=True, splitThreshold=0., amplifyModel=1.)
 
def buildMatchedExposure (self, exposure=None, visitInfo=None, bbox=None, wcs=None, mask=None)
 
def conditionDcrModel (self, modelImages, bbox, gain=1.)
 
def regularizeModelIter (self, subfilter, newModel, bbox, regularizationFactor, regularizationWidth=2)
 
def regularizeModelFreq (self, modelImages, bbox, statsCtrl, regularizationFactor, regularizationWidth=2, mask=None, convergenceMaskPlanes="DETECTED")
 
def calculateNoiseCutoff (self, image, statsCtrl, bufferSize, convergenceMaskPlanes="DETECTED", mask=None, bbox=None)
 
def applyImageThresholds (self, image, highThreshold=None, lowThreshold=None, regularizationWidth=2)
 

Public Attributes

 dcrNumSubfilters
 
 modelImages
 
 photoCalib
 

Detailed Description

A model of the true sky after correcting chromatic effects.

Attributes
----------
dcrNumSubfilters : `int`
    Number of sub-filters used to model chromatic effects within a band.
modelImages : `list` of `lsst.afw.image.Image`
    A list of masked images, each containing the model for one subfilter

Notes
-----
The ``DcrModel`` contains an estimate of the true sky, at a higher
wavelength resolution than the input observations. It can be forward-
modeled to produce Differential Chromatic Refraction (DCR) matched
templates for a given ``Exposure``, and provides utilities for conditioning
the model in ``dcrAssembleCoadd`` to avoid oscillating solutions between
iterations of forward modeling or between the subfilters of the model.

Definition at line 32 of file dcrModel.py.

Constructor & Destructor Documentation

◆ __init__()

def lsst.ip.diffim.dcrModel.DcrModel.__init__ (   self,
  modelImages,
  effectiveWavelength,
  bandwidth,
  filterLabel = None,
  psf = None,
  mask = None,
  variance = None,
  photoCalib = None 
)

Definition at line 52 of file dcrModel.py.

53  mask=None, variance=None, photoCalib=None):
54  self.dcrNumSubfilters = len(modelImages)
55  self.modelImages = modelImages
56  self._filterLabel = filterLabel
57  self._effectiveWavelength = effectiveWavelength
58  self._bandwidth = bandwidth
59  self._psf = psf
60  self._mask = mask
61  self._variance = variance
62  self.photoCalib = photoCalib
63 

Member Function Documentation

◆ __getitem__()

def lsst.ip.diffim.dcrModel.DcrModel.__getitem__ (   self,
  subfilter 
)
Iterate over the subfilters of the DCR model.

Parameters
----------
subfilter : `int`
    Index of the current ``subfilter`` within the full band.
    Negative indices are allowed, and count in reverse order
    from the highest ``subfilter``.

Returns
-------
modelImage : `lsst.afw.image.Image`
    The DCR model for the given ``subfilter``.

Raises
------
IndexError
    If the requested ``subfilter`` is greater or equal to the number
    of subfilters in the model.

Definition at line 220 of file dcrModel.py.

220  def __getitem__(self, subfilter):
221  """Iterate over the subfilters of the DCR model.
222 
223  Parameters
224  ----------
225  subfilter : `int`
226  Index of the current ``subfilter`` within the full band.
227  Negative indices are allowed, and count in reverse order
228  from the highest ``subfilter``.
229 
230  Returns
231  -------
232  modelImage : `lsst.afw.image.Image`
233  The DCR model for the given ``subfilter``.
234 
235  Raises
236  ------
237  IndexError
238  If the requested ``subfilter`` is greater or equal to the number
239  of subfilters in the model.
240  """
241  if np.abs(subfilter) >= len(self):
242  raise IndexError("subfilter out of bounds.")
243  return self.modelImages[subfilter]
244 

◆ __len__()

def lsst.ip.diffim.dcrModel.DcrModel.__len__ (   self)
Return the number of subfilters.

Returns
-------
dcrNumSubfilters : `int`
    The number of DCR subfilters in the model.

Definition at line 210 of file dcrModel.py.

210  def __len__(self):
211  """Return the number of subfilters.
212 
213  Returns
214  -------
215  dcrNumSubfilters : `int`
216  The number of DCR subfilters in the model.
217  """
218  return self.dcrNumSubfilters
219 

◆ __setitem__()

def lsst.ip.diffim.dcrModel.DcrModel.__setitem__ (   self,
  subfilter,
  maskedImage 
)
Update the model image for one subfilter.

Parameters
----------
subfilter : `int`
    Index of the current subfilter within the full band.
maskedImage : `lsst.afw.image.Image`
    The DCR model to set for the given ``subfilter``.

Raises
------
IndexError
    If the requested ``subfilter`` is greater or equal to the number
    of subfilters in the model.
ValueError
    If the bounding box of the new image does not match.

Definition at line 245 of file dcrModel.py.

245  def __setitem__(self, subfilter, maskedImage):
246  """Update the model image for one subfilter.
247 
248  Parameters
249  ----------
250  subfilter : `int`
251  Index of the current subfilter within the full band.
252  maskedImage : `lsst.afw.image.Image`
253  The DCR model to set for the given ``subfilter``.
254 
255  Raises
256  ------
257  IndexError
258  If the requested ``subfilter`` is greater or equal to the number
259  of subfilters in the model.
260  ValueError
261  If the bounding box of the new image does not match.
262  """
263  if np.abs(subfilter) >= len(self):
264  raise IndexError("subfilter out of bounds.")
265  if maskedImage.getBBox() != self.bbox:
266  raise ValueError("The bounding box of a subfilter must not change.")
267  self.modelImages[subfilter] = maskedImage
268 

◆ applyImageThresholds()

def lsst.ip.diffim.dcrModel.DcrModel.applyImageThresholds (   self,
  image,
  highThreshold = None,
  lowThreshold = None,
  regularizationWidth = 2 
)
Restrict image values to be between upper and lower limits.

This method flags all pixels in an image that are outside of the given
threshold values. The threshold values are taken from a reference
image, so noisy pixels are likely to get flagged. In order to exclude
those noisy pixels, the array of flags is eroded and dilated, which
removes isolated pixels outside of the thresholds from the list of
pixels to be modified. Pixels that remain flagged after this operation
have their values set to the appropriate upper or lower threshold
value.

Parameters
----------
image : `numpy.ndarray`
    The image to apply the thresholds to.
    The values will be modified in place.
highThreshold : `numpy.ndarray`, optional
    Array of upper limit values for each pixel of ``image``.
lowThreshold : `numpy.ndarray`, optional
    Array of lower limit values for each pixel of ``image``.
regularizationWidth : `int`, optional
    Minimum radius of a region to include in regularization, in pixels.

Definition at line 650 of file dcrModel.py.

650  def applyImageThresholds(self, image, highThreshold=None, lowThreshold=None, regularizationWidth=2):
651  """Restrict image values to be between upper and lower limits.
652 
653  This method flags all pixels in an image that are outside of the given
654  threshold values. The threshold values are taken from a reference
655  image, so noisy pixels are likely to get flagged. In order to exclude
656  those noisy pixels, the array of flags is eroded and dilated, which
657  removes isolated pixels outside of the thresholds from the list of
658  pixels to be modified. Pixels that remain flagged after this operation
659  have their values set to the appropriate upper or lower threshold
660  value.
661 
662  Parameters
663  ----------
664  image : `numpy.ndarray`
665  The image to apply the thresholds to.
666  The values will be modified in place.
667  highThreshold : `numpy.ndarray`, optional
668  Array of upper limit values for each pixel of ``image``.
669  lowThreshold : `numpy.ndarray`, optional
670  Array of lower limit values for each pixel of ``image``.
671  regularizationWidth : `int`, optional
672  Minimum radius of a region to include in regularization, in pixels.
673  """
674  # Generate the structure for binary erosion and dilation, which is used
675  # to remove noise-like pixels. Groups of pixels with a radius smaller
676  # than ``regularizationWidth`` will be excluded from regularization.
677  filterStructure = ndimage.iterate_structure(ndimage.generate_binary_structure(2, 1),
678  regularizationWidth)
679  if highThreshold is not None:
680  highPixels = image > highThreshold
681  if regularizationWidth > 0:
682  # Erode and dilate ``highPixels`` to exclude noisy pixels.
683  highPixels = ndimage.morphology.binary_opening(highPixels, structure=filterStructure)
684  image[highPixels] = highThreshold[highPixels]
685  if lowThreshold is not None:
686  lowPixels = image < lowThreshold
687  if regularizationWidth > 0:
688  # Erode and dilate ``lowPixels`` to exclude noisy pixels.
689  lowPixels = ndimage.morphology.binary_opening(lowPixels, structure=filterStructure)
690  image[lowPixels] = lowThreshold[lowPixels]
691 
692 

◆ assign()

def lsst.ip.diffim.dcrModel.DcrModel.assign (   self,
  dcrSubModel,
  bbox = None 
)
Update a sub-region of the ``DcrModel`` with new values.

Parameters
----------
dcrSubModel : `lsst.pipe.tasks.DcrModel`
    New model of the true scene after correcting chromatic effects.
bbox : `lsst.afw.geom.Box2I`, optional
    Sub-region of the coadd.
    Defaults to the bounding box of ``dcrSubModel``.

Raises
------
ValueError
    If the new model has a different number of subfilters.

Definition at line 363 of file dcrModel.py.

363  def assign(self, dcrSubModel, bbox=None):
364  """Update a sub-region of the ``DcrModel`` with new values.
365 
366  Parameters
367  ----------
368  dcrSubModel : `lsst.pipe.tasks.DcrModel`
369  New model of the true scene after correcting chromatic effects.
370  bbox : `lsst.afw.geom.Box2I`, optional
371  Sub-region of the coadd.
372  Defaults to the bounding box of ``dcrSubModel``.
373 
374  Raises
375  ------
376  ValueError
377  If the new model has a different number of subfilters.
378  """
379  if len(dcrSubModel) != len(self):
380  raise ValueError("The number of DCR subfilters must be the same "
381  "between the old and new models.")
382  bbox = bbox or self.bbox
383  for model, subModel in zip(self, dcrSubModel):
384  model.assign(subModel[bbox], bbox)
385 

◆ bandwidth()

def lsst.ip.diffim.dcrModel.DcrModel.bandwidth (   self)
Return the bandwidth of the model.

Returns
-------
bandwidth : `float`
    The bandwidth of the current filter, in nanometers.

Definition at line 292 of file dcrModel.py.

292  def bandwidth(self):
293  """Return the bandwidth of the model.
294 
295  Returns
296  -------
297  bandwidth : `float`
298  The bandwidth of the current filter, in nanometers.
299  """
300  return self._bandwidth
301 

◆ bbox()

def lsst.ip.diffim.dcrModel.DcrModel.bbox (   self)
Return the common bounding box of each subfilter image.

Returns
-------
bbox : `lsst.afw.geom.Box2I`
    Bounding box of the DCR model.

Definition at line 314 of file dcrModel.py.

314  def bbox(self):
315  """Return the common bounding box of each subfilter image.
316 
317  Returns
318  -------
319  bbox : `lsst.afw.geom.Box2I`
320  Bounding box of the DCR model.
321  """
322  return self[0].getBBox()
323 
AmpInfoBoxKey bbox
Definition: Amplifier.cc:117

◆ buildMatchedExposure()

def lsst.ip.diffim.dcrModel.DcrModel.buildMatchedExposure (   self,
  exposure = None,
  visitInfo = None,
  bbox = None,
  wcs = None,
  mask = None 
)
Wrapper to create an exposure from a template image.

Parameters
----------
exposure : `lsst.afw.image.Exposure`, optional
    The input exposure to build a matched template for.
    May be omitted if all of the metadata is supplied separately
visitInfo : `lsst.afw.image.VisitInfo`, optional
    Metadata for the exposure. Ignored if ``exposure`` is set.
bbox : `lsst.afw.geom.Box2I`, optional
    Sub-region of the coadd. Ignored if ``exposure`` is set.
wcs : `lsst.afw.geom.SkyWcs`, optional
    Coordinate system definition (wcs) for the exposure.
    Ignored if ``exposure`` is set.
mask : `lsst.afw.image.Mask`, optional
    reference mask to use for the template image.

Returns
-------
templateExposure : `lsst.afw.image.exposureF`
    The DCR-matched template

Raises
------
RuntimeError
    If no `photcCalib` is set.

Definition at line 450 of file dcrModel.py.

451  visitInfo=None, bbox=None, wcs=None, mask=None):
452  """Wrapper to create an exposure from a template image.
453 
454  Parameters
455  ----------
456  exposure : `lsst.afw.image.Exposure`, optional
457  The input exposure to build a matched template for.
458  May be omitted if all of the metadata is supplied separately
459  visitInfo : `lsst.afw.image.VisitInfo`, optional
460  Metadata for the exposure. Ignored if ``exposure`` is set.
461  bbox : `lsst.afw.geom.Box2I`, optional
462  Sub-region of the coadd. Ignored if ``exposure`` is set.
463  wcs : `lsst.afw.geom.SkyWcs`, optional
464  Coordinate system definition (wcs) for the exposure.
465  Ignored if ``exposure`` is set.
466  mask : `lsst.afw.image.Mask`, optional
467  reference mask to use for the template image.
468 
469  Returns
470  -------
471  templateExposure : `lsst.afw.image.exposureF`
472  The DCR-matched template
473 
474  Raises
475  ------
476  RuntimeError
477  If no `photcCalib` is set.
478  """
479  if bbox is None:
480  bbox = exposure.getBBox()
481  templateImage = self.buildMatchedTemplate(exposure=exposure, visitInfo=visitInfo,
482  bbox=bbox, wcs=wcs, mask=mask)
483  maskedImage = afwImage.MaskedImageF(bbox)
484  maskedImage.image = templateImage[bbox]
485  maskedImage.mask = self.mask[bbox]
486  maskedImage.variance = self.variance[bbox]
487  # The variance of the stacked image will be `dcrNumSubfilters`
488  # times the variance of the individual subfilters.
489  maskedImage.variance *= self.dcrNumSubfilters
490  templateExposure = afwImage.ExposureF(bbox, wcs)
491  templateExposure.setMaskedImage(maskedImage[bbox])
492  templateExposure.setPsf(self.psf)
493  templateExposure.setFilterLabel(self.filterLabel)
494  if self.photoCalib is None:
495  raise RuntimeError("No PhotoCalib set for the DcrModel. "
496  "If the DcrModel was created from a masked image"
497  " you must also specify the photoCalib.")
498  templateExposure.setPhotoCalib(self.photoCalib)
499  return templateExposure
500 

◆ buildMatchedTemplate()

def lsst.ip.diffim.dcrModel.DcrModel.buildMatchedTemplate (   self,
  exposure = None,
  order = 3,
  visitInfo = None,
  bbox = None,
  wcs = None,
  mask = None,
  splitSubfilters = True,
  splitThreshold = 0.,
  amplifyModel = 1. 
)
Create a DCR-matched template image for an exposure.

Parameters
----------
exposure : `lsst.afw.image.Exposure`, optional
    The input exposure to build a matched template for.
    May be omitted if all of the metadata is supplied separately
order : `int`, optional
    Interpolation order of the DCR shift.
visitInfo : `lsst.afw.image.VisitInfo`, optional
    Metadata for the exposure. Ignored if ``exposure`` is set.
bbox : `lsst.afw.geom.Box2I`, optional
    Sub-region of the coadd. Ignored if ``exposure`` is set.
wcs : `lsst.afw.geom.SkyWcs`, optional
    Coordinate system definition (wcs) for the exposure.
    Ignored if ``exposure`` is set.
mask : `lsst.afw.image.Mask`, optional
    reference mask to use for the template image.
splitSubfilters : `bool`, optional
    Calculate DCR for two evenly-spaced wavelengths in each subfilter,
    instead of at the midpoint. Default: True
splitThreshold : `float`, optional
    Minimum DCR difference within a subfilter required to use
    ``splitSubfilters``
amplifyModel : `float`, optional
    Multiplication factor to amplify differences between model planes.
    Used to speed convergence of iterative forward modeling.

Returns
-------
templateImage : `lsst.afw.image.ImageF`
    The DCR-matched template

Raises
------
ValueError
    If neither ``exposure`` or all of ``visitInfo``, ``bbox``, and
    ``wcs`` are set.

Definition at line 386 of file dcrModel.py.

388  splitSubfilters=True, splitThreshold=0., amplifyModel=1.):
389  """Create a DCR-matched template image for an exposure.
390 
391  Parameters
392  ----------
393  exposure : `lsst.afw.image.Exposure`, optional
394  The input exposure to build a matched template for.
395  May be omitted if all of the metadata is supplied separately
396  order : `int`, optional
397  Interpolation order of the DCR shift.
398  visitInfo : `lsst.afw.image.VisitInfo`, optional
399  Metadata for the exposure. Ignored if ``exposure`` is set.
400  bbox : `lsst.afw.geom.Box2I`, optional
401  Sub-region of the coadd. Ignored if ``exposure`` is set.
402  wcs : `lsst.afw.geom.SkyWcs`, optional
403  Coordinate system definition (wcs) for the exposure.
404  Ignored if ``exposure`` is set.
405  mask : `lsst.afw.image.Mask`, optional
406  reference mask to use for the template image.
407  splitSubfilters : `bool`, optional
408  Calculate DCR for two evenly-spaced wavelengths in each subfilter,
409  instead of at the midpoint. Default: True
410  splitThreshold : `float`, optional
411  Minimum DCR difference within a subfilter required to use
412  ``splitSubfilters``
413  amplifyModel : `float`, optional
414  Multiplication factor to amplify differences between model planes.
415  Used to speed convergence of iterative forward modeling.
416 
417  Returns
418  -------
419  templateImage : `lsst.afw.image.ImageF`
420  The DCR-matched template
421 
422  Raises
423  ------
424  ValueError
425  If neither ``exposure`` or all of ``visitInfo``, ``bbox``, and
426  ``wcs`` are set.
427  """
428  if self.effectiveWavelength is None or self.bandwidth is None:
429  raise ValueError("'effectiveWavelength' and 'bandwidth' must be set for the DcrModel in order "
430  "to calculate DCR.")
431  if exposure is not None:
432  visitInfo = exposure.getInfo().getVisitInfo()
433  bbox = exposure.getBBox()
434  wcs = exposure.getInfo().getWcs()
435  elif visitInfo is None or bbox is None or wcs is None:
436  raise ValueError("Either exposure or visitInfo, bbox, and wcs must be set.")
437  dcrShift = calculateDcr(visitInfo, wcs, self.effectiveWavelength, self.bandwidth, len(self),
438  splitSubfilters=splitSubfilters)
439  templateImage = afwImage.ImageF(bbox)
440  refModel = self.getReferenceImage(bbox)
441  for subfilter, dcr in enumerate(dcrShift):
442  if amplifyModel > 1:
443  model = (self[subfilter][bbox].array - refModel)*amplifyModel + refModel
444  else:
445  model = self[subfilter][bbox].array
446  templateImage.array += applyDcr(model, dcr, splitSubfilters=splitSubfilters,
447  splitThreshold=splitThreshold, order=order)
448  return templateImage
449 
def applyDcr(image, dcr, useInverse=False, splitSubfilters=False, splitThreshold=0., doPrefilter=True, order=3)
Definition: dcrModel.py:694
def calculateDcr(visitInfo, wcs, effectiveWavelength, bandwidth, dcrNumSubfilters, splitSubfilters=False)
Definition: dcrModel.py:759

◆ calculateNoiseCutoff()

def lsst.ip.diffim.dcrModel.DcrModel.calculateNoiseCutoff (   self,
  image,
  statsCtrl,
  bufferSize,
  convergenceMaskPlanes = "DETECTED",
  mask = None,
  bbox = None 
)
Helper function to calculate the background noise level of an image.

Parameters
----------
image : `lsst.afw.image.Image`
    The input image to evaluate the background noise properties.
statsCtrl : `lsst.afw.math.StatisticsControl`
    Statistics control object for coaddition.
bufferSize : `int`
    Number of additional pixels to exclude
    from the edges of the bounding box.
convergenceMaskPlanes : `list` of `str`, or `str`
    Mask planes to use to calculate convergence.
mask : `lsst.afw.image.Mask`, Optional
    Optional alternate mask
bbox : `lsst.afw.geom.Box2I`, optional
    Sub-region of the masked image to calculate the noise level over.

Returns
-------
noiseCutoff : `float`
    The threshold value to treat pixels as noise in an image..

Definition at line 613 of file dcrModel.py.

614  convergenceMaskPlanes="DETECTED", mask=None, bbox=None):
615  """Helper function to calculate the background noise level of an image.
616 
617  Parameters
618  ----------
619  image : `lsst.afw.image.Image`
620  The input image to evaluate the background noise properties.
621  statsCtrl : `lsst.afw.math.StatisticsControl`
622  Statistics control object for coaddition.
623  bufferSize : `int`
624  Number of additional pixels to exclude
625  from the edges of the bounding box.
626  convergenceMaskPlanes : `list` of `str`, or `str`
627  Mask planes to use to calculate convergence.
628  mask : `lsst.afw.image.Mask`, Optional
629  Optional alternate mask
630  bbox : `lsst.afw.geom.Box2I`, optional
631  Sub-region of the masked image to calculate the noise level over.
632 
633  Returns
634  -------
635  noiseCutoff : `float`
636  The threshold value to treat pixels as noise in an image..
637  """
638  if bbox is None:
639  bbox = self.bbox
640  if mask is None:
641  mask = self.mask[bbox]
642  bboxShrink = geom.Box2I(bbox)
643  bboxShrink.grow(-bufferSize)
644  convergeMask = mask.getPlaneBitMask(convergenceMaskPlanes)
645 
646  backgroundPixels = mask[bboxShrink].array & (statsCtrl.getAndMask() | convergeMask) == 0
647  noiseCutoff = np.std(image[bboxShrink].array[backgroundPixels])
648  return noiseCutoff
649 
An integer coordinate rectangle.
Definition: Box.h:55

◆ conditionDcrModel()

def lsst.ip.diffim.dcrModel.DcrModel.conditionDcrModel (   self,
  modelImages,
  bbox,
  gain = 1. 
)
Average two iterations' solutions to reduce oscillations.

Parameters
----------
modelImages : `list` of `lsst.afw.image.Image`
    The new DCR model images from the current iteration.
    The values will be modified in place.
bbox : `lsst.afw.geom.Box2I`
    Sub-region of the coadd
gain : `float`, optional
    Relative weight to give the new solution when updating the model.
    Defaults to 1.0, which gives equal weight to both solutions.

Definition at line 501 of file dcrModel.py.

501  def conditionDcrModel(self, modelImages, bbox, gain=1.):
502  """Average two iterations' solutions to reduce oscillations.
503 
504  Parameters
505  ----------
506  modelImages : `list` of `lsst.afw.image.Image`
507  The new DCR model images from the current iteration.
508  The values will be modified in place.
509  bbox : `lsst.afw.geom.Box2I`
510  Sub-region of the coadd
511  gain : `float`, optional
512  Relative weight to give the new solution when updating the model.
513  Defaults to 1.0, which gives equal weight to both solutions.
514  """
515  # Calculate weighted averages of the images.
516  for model, newModel in zip(self, modelImages):
517  newModel *= gain
518  newModel += model[bbox]
519  newModel /= 1. + gain
520 

◆ effectiveWavelength()

def lsst.ip.diffim.dcrModel.DcrModel.effectiveWavelength (   self)
Return the effective wavelength of the model.

Returns
-------
effectiveWavelength : `float`
    The effective wavelength of the current filter, in nanometers.

Definition at line 270 of file dcrModel.py.

270  def effectiveWavelength(self):
271  """Return the effective wavelength of the model.
272 
273  Returns
274  -------
275  effectiveWavelength : `float`
276  The effective wavelength of the current filter, in nanometers.
277  """
278  return self._effectiveWavelength
279 

◆ filter()

def lsst.ip.diffim.dcrModel.DcrModel.filter (   self)
Return the filter label for the model.

Returns
-------
filterLabel : `lsst.afw.image.FilterLabel`
    The filter used for the input observations.

Definition at line 281 of file dcrModel.py.

281  def filter(self):
282  """Return the filter label for the model.
283 
284  Returns
285  -------
286  filterLabel : `lsst.afw.image.FilterLabel`
287  The filter used for the input observations.
288  """
289  return self._filterLabel
290 

◆ fromDataRef()

def lsst.ip.diffim.dcrModel.DcrModel.fromDataRef (   cls,
  dataRef,
  effectiveWavelength,
  bandwidth,
  datasetType = "dcrCoadd",
  numSubfilters = None,
**  kwargs 
)
Load an existing DcrModel from a Gen 2 repository.

Parameters
----------
dataRef : `lsst.daf.persistence.ButlerDataRef`
    Data reference defining the patch for coaddition and the
    reference Warp
effectiveWavelength : `float`
    The effective wavelengths of the current filter, in nanometers.
bandwidth : `float`
    The bandwidth of the current filter, in nanometers.
datasetType : `str`, optional
    Name of the DcrModel in the registry {"dcrCoadd", "dcrCoadd_sub"}
numSubfilters : `int`
    Number of sub-filters used to model chromatic effects within a
    band.
**kwargs
    Additional keyword arguments to pass to look up the model in the
    data registry.
    Common keywords and their types include: ``tract``:`str`,
    ``patch``:`str`, ``bbox``:`lsst.afw.geom.Box2I`

Returns
-------
dcrModel : `lsst.pipe.tasks.DcrModel`
    Best fit model of the true sky after correcting chromatic effects.

Definition at line 115 of file dcrModel.py.

116  **kwargs):
117  """Load an existing DcrModel from a Gen 2 repository.
118 
119  Parameters
120  ----------
121  dataRef : `lsst.daf.persistence.ButlerDataRef`
122  Data reference defining the patch for coaddition and the
123  reference Warp
124  effectiveWavelength : `float`
125  The effective wavelengths of the current filter, in nanometers.
126  bandwidth : `float`
127  The bandwidth of the current filter, in nanometers.
128  datasetType : `str`, optional
129  Name of the DcrModel in the registry {"dcrCoadd", "dcrCoadd_sub"}
130  numSubfilters : `int`
131  Number of sub-filters used to model chromatic effects within a
132  band.
133  **kwargs
134  Additional keyword arguments to pass to look up the model in the
135  data registry.
136  Common keywords and their types include: ``tract``:`str`,
137  ``patch``:`str`, ``bbox``:`lsst.afw.geom.Box2I`
138 
139  Returns
140  -------
141  dcrModel : `lsst.pipe.tasks.DcrModel`
142  Best fit model of the true sky after correcting chromatic effects.
143  """
144  modelImages = []
145  filterLabel = None
146  psf = None
147  mask = None
148  variance = None
149  photoCalib = None
150  if "subfilter" in kwargs:
151  kwargs.pop("subfilter")
152  for subfilter in range(numSubfilters):
153  dcrCoadd = dataRef.get(datasetType, subfilter=subfilter,
154  numSubfilters=numSubfilters, **kwargs)
155  if filterLabel is None:
156  filterLabel = dcrCoadd.getFilterLabel()
157  if psf is None:
158  psf = dcrCoadd.getPsf()
159  if mask is None:
160  mask = dcrCoadd.mask
161  if variance is None:
162  variance = dcrCoadd.variance
163  if photoCalib is None:
164  photoCalib = dcrCoadd.getPhotoCalib()
165  modelImages.append(dcrCoadd.image)
166  return cls(modelImages, effectiveWavelength, bandwidth, filterLabel, psf, mask, variance, photoCalib)
167 

◆ fromImage()

def lsst.ip.diffim.dcrModel.DcrModel.fromImage (   cls,
  maskedImage,
  dcrNumSubfilters,
  effectiveWavelength,
  bandwidth,
  filterLabel = None,
  psf = None,
  photoCalib = None 
)
Initialize a DcrModel by dividing a coadd between the subfilters.

Parameters
----------
maskedImage : `lsst.afw.image.MaskedImage`
    Input coadded image to divide equally between the subfilters.
dcrNumSubfilters : `int`
    Number of sub-filters used to model chromatic effects within a
    band.
effectiveWavelength : `float`
    The effective wavelengths of the current filter, in nanometers.
bandwidth : `float`
    The bandwidth of the current filter, in nanometers.
filterLabel : `lsst.afw.image.FilterLabel`, optional
    The filter label, set in the current instruments' obs package.
    Required for any calculation of DCR, including making matched
    templates.
psf : `lsst.afw.detection.Psf`, optional
    Point spread function (PSF) of the model.
    Required if the ``DcrModel`` will be persisted.
photoCalib : `lsst.afw.image.PhotoCalib`, optional
    Calibration to convert instrumental flux and
    flux error to nanoJansky.

Returns
-------
dcrModel : `lsst.pipe.tasks.DcrModel`
    Best fit model of the true sky after correcting chromatic effects.

Definition at line 65 of file dcrModel.py.

66  filterLabel=None, psf=None, photoCalib=None):
67  """Initialize a DcrModel by dividing a coadd between the subfilters.
68 
69  Parameters
70  ----------
71  maskedImage : `lsst.afw.image.MaskedImage`
72  Input coadded image to divide equally between the subfilters.
73  dcrNumSubfilters : `int`
74  Number of sub-filters used to model chromatic effects within a
75  band.
76  effectiveWavelength : `float`
77  The effective wavelengths of the current filter, in nanometers.
78  bandwidth : `float`
79  The bandwidth of the current filter, in nanometers.
80  filterLabel : `lsst.afw.image.FilterLabel`, optional
81  The filter label, set in the current instruments' obs package.
82  Required for any calculation of DCR, including making matched
83  templates.
84  psf : `lsst.afw.detection.Psf`, optional
85  Point spread function (PSF) of the model.
86  Required if the ``DcrModel`` will be persisted.
87  photoCalib : `lsst.afw.image.PhotoCalib`, optional
88  Calibration to convert instrumental flux and
89  flux error to nanoJansky.
90 
91  Returns
92  -------
93  dcrModel : `lsst.pipe.tasks.DcrModel`
94  Best fit model of the true sky after correcting chromatic effects.
95  """
96  # NANs will potentially contaminate the entire image,
97  # depending on the shift or convolution type used.
98  model = maskedImage.image.clone()
99  mask = maskedImage.mask.clone()
100  # We divide the variance by N and not N**2 because we will assume each
101  # subfilter is independent. That means that the significance of
102  # detected sources will be lower by a factor of sqrt(N) in the
103  # subfilter images, but we will recover it when we combine the
104  # subfilter images to construct matched templates.
105  variance = maskedImage.variance.clone()
106  variance /= dcrNumSubfilters
107  model /= dcrNumSubfilters
108  modelImages = [model, ]
109  for subfilter in range(1, dcrNumSubfilters):
110  modelImages.append(model.clone())
111  return cls(modelImages, effectiveWavelength, bandwidth,
112  filterLabel=filterLabel, psf=psf, mask=mask, variance=variance, photoCalib=photoCalib)
113 

◆ fromQuantum()

def lsst.ip.diffim.dcrModel.DcrModel.fromQuantum (   cls,
  availableCoaddRefs,
  effectiveWavelength,
  bandwidth 
)
Load an existing DcrModel from a Gen 3 repository.

Parameters
----------
availableCoaddRefs : `dict` [`int`, `lsst.daf.butler.DeferredDatasetHandle`]
    Dictionary of spatially relevant retrieved coadd patches,
    indexed by their sequential patch number.
effectiveWavelength : `float`
    The effective wavelengths of the current filter, in nanometers.
bandwidth : `float`
    The bandwidth of the current filter, in nanometers.

Returns
-------
dcrModel : `lsst.pipe.tasks.DcrModel`
    Best fit model of the true sky after correcting chromatic effects.

Definition at line 169 of file dcrModel.py.

169  def fromQuantum(cls, availableCoaddRefs, effectiveWavelength, bandwidth):
170  """Load an existing DcrModel from a Gen 3 repository.
171 
172  Parameters
173  ----------
174  availableCoaddRefs : `dict` [`int`, `lsst.daf.butler.DeferredDatasetHandle`]
175  Dictionary of spatially relevant retrieved coadd patches,
176  indexed by their sequential patch number.
177  effectiveWavelength : `float`
178  The effective wavelengths of the current filter, in nanometers.
179  bandwidth : `float`
180  The bandwidth of the current filter, in nanometers.
181 
182  Returns
183  -------
184  dcrModel : `lsst.pipe.tasks.DcrModel`
185  Best fit model of the true sky after correcting chromatic effects.
186  """
187  filterLabel = None
188  psf = None
189  mask = None
190  variance = None
191  photoCalib = None
192  modelImages = [None]*len(availableCoaddRefs)
193 
194  for coaddRef in availableCoaddRefs:
195  subfilter = coaddRef.dataId["subfilter"]
196  dcrCoadd = coaddRef.get()
197  if filterLabel is None:
198  filterLabel = dcrCoadd.getFilterLabel()
199  if psf is None:
200  psf = dcrCoadd.getPsf()
201  if mask is None:
202  mask = dcrCoadd.mask
203  if variance is None:
204  variance = dcrCoadd.variance
205  if photoCalib is None:
206  photoCalib = dcrCoadd.getPhotoCalib()
207  modelImages[subfilter] = dcrCoadd.image
208  return cls(modelImages, effectiveWavelength, bandwidth, filterLabel, psf, mask, variance, photoCalib)
209 

◆ getReferenceImage()

def lsst.ip.diffim.dcrModel.DcrModel.getReferenceImage (   self,
  bbox = None 
)
Calculate a reference image from the average of the subfilter
images.

Parameters
----------
bbox : `lsst.afw.geom.Box2I`, optional
    Sub-region of the coadd. Returns the entire image if `None`.

Returns
-------
refImage : `numpy.ndarray`
    The reference image with no chromatic effects applied.

Definition at line 346 of file dcrModel.py.

346  def getReferenceImage(self, bbox=None):
347  """Calculate a reference image from the average of the subfilter
348  images.
349 
350  Parameters
351  ----------
352  bbox : `lsst.afw.geom.Box2I`, optional
353  Sub-region of the coadd. Returns the entire image if `None`.
354 
355  Returns
356  -------
357  refImage : `numpy.ndarray`
358  The reference image with no chromatic effects applied.
359  """
360  bbox = bbox or self.bbox
361  return np.mean([model[bbox].array for model in self], axis=0)
362 

◆ mask()

def lsst.ip.diffim.dcrModel.DcrModel.mask (   self)
Return the common mask of each subfilter image.

Returns
-------
mask : `lsst.afw.image.Mask`
    Mask plane of the DCR model.

Definition at line 325 of file dcrModel.py.

325  def mask(self):
326  """Return the common mask of each subfilter image.
327 
328  Returns
329  -------
330  mask : `lsst.afw.image.Mask`
331  Mask plane of the DCR model.
332  """
333  return self._mask
334 
afw::table::Key< afw::table::Array< MaskPixelT > > mask

◆ psf()

def lsst.ip.diffim.dcrModel.DcrModel.psf (   self)
Return the psf of the model.

Returns
-------
psf : `lsst.afw.detection.Psf`
    Point spread function (PSF) of the model.

Definition at line 303 of file dcrModel.py.

303  def psf(self):
304  """Return the psf of the model.
305 
306  Returns
307  -------
308  psf : `lsst.afw.detection.Psf`
309  Point spread function (PSF) of the model.
310  """
311  return self._psf
312 
Key< int > psf
Definition: Exposure.cc:65

◆ regularizeModelFreq()

def lsst.ip.diffim.dcrModel.DcrModel.regularizeModelFreq (   self,
  modelImages,
  bbox,
  statsCtrl,
  regularizationFactor,
  regularizationWidth = 2,
  mask = None,
  convergenceMaskPlanes = "DETECTED" 
)
Restrict large variations in the model between subfilters.

Parameters
----------
modelImages : `list` of `lsst.afw.image.Image`
    The new DCR model images from the current iteration.
    The values will be modified in place.
bbox : `lsst.afw.geom.Box2I`
    Sub-region to coadd
statsCtrl : `lsst.afw.math.StatisticsControl`
    Statistics control object for coaddition.
regularizationFactor : `float`
    Maximum relative change of the model allowed between subfilters.
regularizationWidth : `int`, optional
    Minimum radius of a region to include in regularization, in pixels.
mask : `lsst.afw.image.Mask`, optional
    Optional alternate mask
convergenceMaskPlanes : `list` of `str`, or `str`, optional
    Mask planes to use to calculate convergence.

Notes
-----
This implementation of frequency regularization restricts each
subfilter image to be a smoothly-varying function times a reference
image.

Definition at line 547 of file dcrModel.py.

548  regularizationWidth=2, mask=None, convergenceMaskPlanes="DETECTED"):
549  """Restrict large variations in the model between subfilters.
550 
551  Parameters
552  ----------
553  modelImages : `list` of `lsst.afw.image.Image`
554  The new DCR model images from the current iteration.
555  The values will be modified in place.
556  bbox : `lsst.afw.geom.Box2I`
557  Sub-region to coadd
558  statsCtrl : `lsst.afw.math.StatisticsControl`
559  Statistics control object for coaddition.
560  regularizationFactor : `float`
561  Maximum relative change of the model allowed between subfilters.
562  regularizationWidth : `int`, optional
563  Minimum radius of a region to include in regularization, in pixels.
564  mask : `lsst.afw.image.Mask`, optional
565  Optional alternate mask
566  convergenceMaskPlanes : `list` of `str`, or `str`, optional
567  Mask planes to use to calculate convergence.
568 
569  Notes
570  -----
571  This implementation of frequency regularization restricts each
572  subfilter image to be a smoothly-varying function times a reference
573  image.
574  """
575  # ``regularizationFactor`` is the maximum change between subfilter
576  # images, so the maximum difference between one subfilter image and the
577  # average will be the square root of that.
578  maxDiff = np.sqrt(regularizationFactor)
579  noiseLevel = self.calculateNoiseCutoff(modelImages[0], statsCtrl, bufferSize=5, mask=mask, bbox=bbox)
580  referenceImage = self.getReferenceImage(bbox)
581  badPixels = np.isnan(referenceImage) | (referenceImage <= 0.)
582  if np.sum(~badPixels) == 0:
583  # Skip regularization if there are no valid pixels
584  return
585  referenceImage[badPixels] = 0.
586  filterWidth = regularizationWidth
587  fwhm = 2.*filterWidth
588  # The noise should be lower in the smoothed image by
589  # sqrt(Nsmooth) ~ fwhm pixels
590  noiseLevel /= fwhm
591  smoothRef = ndimage.filters.gaussian_filter(referenceImage, filterWidth, mode='constant')
592  # Add a three sigma offset to both the reference and model to prevent
593  # dividing by zero. Note that this will also slightly suppress faint
594  # variations in color.
595  smoothRef += 3.*noiseLevel
596 
597  lowThreshold = smoothRef/maxDiff
598  highThreshold = smoothRef*maxDiff
599  for model in modelImages:
600  self.applyImageThresholds(model.array,
601  highThreshold=highThreshold,
602  lowThreshold=lowThreshold,
603  regularizationWidth=regularizationWidth)
604  smoothModel = ndimage.filters.gaussian_filter(model.array, filterWidth, mode='constant')
605  smoothModel += 3.*noiseLevel
606  relativeModel = smoothModel/smoothRef
607  # Now sharpen the smoothed relativeModel using an alpha of 3.
608  alpha = 3.
609  relativeModel2 = ndimage.filters.gaussian_filter(relativeModel, filterWidth/alpha)
610  relativeModel += alpha*(relativeModel - relativeModel2)
611  model.array = relativeModel*referenceImage
612 

◆ regularizeModelIter()

def lsst.ip.diffim.dcrModel.DcrModel.regularizeModelIter (   self,
  subfilter,
  newModel,
  bbox,
  regularizationFactor,
  regularizationWidth = 2 
)
Restrict large variations in the model between iterations.

Parameters
----------
subfilter : `int`
    Index of the current subfilter within the full band.
newModel : `lsst.afw.image.Image`
    The new DCR model for one subfilter from the current iteration.
    Values in ``newModel`` that are extreme compared with the last
    iteration are modified in place.
bbox : `lsst.afw.geom.Box2I`
    Sub-region to coadd
regularizationFactor : `float`
    Maximum relative change of the model allowed between iterations.
regularizationWidth : int, optional
    Minimum radius of a region to include in regularization, in pixels.

Definition at line 521 of file dcrModel.py.

522  regularizationWidth=2):
523  """Restrict large variations in the model between iterations.
524 
525  Parameters
526  ----------
527  subfilter : `int`
528  Index of the current subfilter within the full band.
529  newModel : `lsst.afw.image.Image`
530  The new DCR model for one subfilter from the current iteration.
531  Values in ``newModel`` that are extreme compared with the last
532  iteration are modified in place.
533  bbox : `lsst.afw.geom.Box2I`
534  Sub-region to coadd
535  regularizationFactor : `float`
536  Maximum relative change of the model allowed between iterations.
537  regularizationWidth : int, optional
538  Minimum radius of a region to include in regularization, in pixels.
539  """
540  refImage = self[subfilter][bbox].array
541  highThreshold = np.abs(refImage)*regularizationFactor
542  lowThreshold = refImage/regularizationFactor
543  newImage = newModel.array
544  self.applyImageThresholds(newImage, highThreshold=highThreshold, lowThreshold=lowThreshold,
545  regularizationWidth=regularizationWidth)
546 

◆ variance()

def lsst.ip.diffim.dcrModel.DcrModel.variance (   self)
Return the common variance of each subfilter image.

Returns
-------
variance : `lsst.afw.image.Image`
    Variance plane of the DCR model.

Definition at line 336 of file dcrModel.py.

336  def variance(self):
337  """Return the common variance of each subfilter image.
338 
339  Returns
340  -------
341  variance : `lsst.afw.image.Image`
342  Variance plane of the DCR model.
343  """
344  return self._variance
345 
afw::table::Key< afw::table::Array< VariancePixelT > > variance

Member Data Documentation

◆ dcrNumSubfilters

lsst.ip.diffim.dcrModel.DcrModel.dcrNumSubfilters

Definition at line 54 of file dcrModel.py.

◆ modelImages

lsst.ip.diffim.dcrModel.DcrModel.modelImages

Definition at line 55 of file dcrModel.py.

◆ photoCalib

lsst.ip.diffim.dcrModel.DcrModel.photoCalib

Definition at line 62 of file dcrModel.py.


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