LSST Applications 24.1.5,g02d81e74bb+fa3a7a026e,g180d380827+a53a32eff8,g2079a07aa2+86d27d4dc4,g2305ad1205+c0501b3732,g295015adf3+7d3e92f0ec,g2bbee38e9b+0e5473021a,g337abbeb29+0e5473021a,g33d1c0ed96+0e5473021a,g3a166c0a6a+0e5473021a,g3ddfee87b4+5dd1654d75,g48712c4677+3bf1020dcb,g487adcacf7+065c13d9cf,g50ff169b8f+96c6868917,g52b1c1532d+585e252eca,g591dd9f2cf+d7ac436cfb,g5a732f18d5+53520f316c,g64a986408d+fa3a7a026e,g858d7b2824+fa3a7a026e,g8a8a8dda67+585e252eca,g99cad8db69+a5a909b84f,g9ddcbc5298+9a081db1e4,ga1e77700b3+15fc3df1f7,ga8c6da7877+4cf350ccb2,gb0e22166c9+60f28cb32d,gba4ed39666+c2a2e4ac27,gbb8dafda3b+f991a0b59f,gc120e1dc64+9ccbfdb8be,gc28159a63d+0e5473021a,gcf0d15dbbd+5dd1654d75,gd96a1ce819+42fd0ee607,gdaeeff99f8+f9a426f77a,ge6526c86ff+0d71447b4b,ge79ae78c31+0e5473021a,gee10cc3b42+585e252eca,gff1a9f87cc+fa3a7a026e
LSST Data Management Base Package
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Protected Attributes | List of all members
lsst.ip.diffim.dcrModel.DcrModel Class Reference

Public Member Functions

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

Public Attributes

 dcrNumSubfilters
 
 modelImages
 
 photoCalib
 
 psf
 
 filter
 

Protected Attributes

 _filterLabel
 
 _effectiveWavelength
 
 _bandwidth
 
 _psf
 
 _bbox
 
 _wcs
 
 _mask
 
 _variance
 

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__()

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

Definition at line 52 of file dcrModel.py.

53 bbox=None, wcs=None, 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._bbox = bbox
61 self._wcs = wcs
62 self._mask = mask
63 self._variance = variance
64 self.photoCalib = photoCalib
65

Member Function Documentation

◆ __getitem__()

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 181 of file dcrModel.py.

181 def __getitem__(self, subfilter):
182 """Iterate over the subfilters of the DCR model.
183
184 Parameters
185 ----------
186 subfilter : `int`
187 Index of the current ``subfilter`` within the full band.
188 Negative indices are allowed, and count in reverse order
189 from the highest ``subfilter``.
190
191 Returns
192 -------
193 modelImage : `lsst.afw.image.Image`
194 The DCR model for the given ``subfilter``.
195
196 Raises
197 ------
198 IndexError
199 If the requested ``subfilter`` is greater or equal to the number
200 of subfilters in the model.
201 """
202 if np.abs(subfilter) >= len(self):
203 raise IndexError("subfilter out of bounds.")
204 return self.modelImages[subfilter]
205

◆ __len__()

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 171 of file dcrModel.py.

171 def __len__(self):
172 """Return the number of subfilters.
173
174 Returns
175 -------
176 dcrNumSubfilters : `int`
177 The number of DCR subfilters in the model.
178 """
179 return self.dcrNumSubfilters
180

◆ __setitem__()

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 206 of file dcrModel.py.

206 def __setitem__(self, subfilter, maskedImage):
207 """Update the model image for one subfilter.
208
209 Parameters
210 ----------
211 subfilter : `int`
212 Index of the current subfilter within the full band.
213 maskedImage : `lsst.afw.image.Image`
214 The DCR model to set for the given ``subfilter``.
215
216 Raises
217 ------
218 IndexError
219 If the requested ``subfilter`` is greater or equal to the number
220 of subfilters in the model.
221 ValueError
222 If the bounding box of the new image does not match.
223 """
224 if np.abs(subfilter) >= len(self):
225 raise IndexError("subfilter out of bounds.")
226 if maskedImage.getBBox() != self.bbox:
227 raise ValueError("The bounding box of a subfilter must not change.")
228 self.modelImages[subfilter] = maskedImage
229

◆ applyImageThresholds()

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 623 of file dcrModel.py.

623 def applyImageThresholds(self, image, highThreshold=None, lowThreshold=None, regularizationWidth=2):
624 """Restrict image values to be between upper and lower limits.
625
626 This method flags all pixels in an image that are outside of the given
627 threshold values. The threshold values are taken from a reference
628 image, so noisy pixels are likely to get flagged. In order to exclude
629 those noisy pixels, the array of flags is eroded and dilated, which
630 removes isolated pixels outside of the thresholds from the list of
631 pixels to be modified. Pixels that remain flagged after this operation
632 have their values set to the appropriate upper or lower threshold
633 value.
634
635 Parameters
636 ----------
637 image : `numpy.ndarray`
638 The image to apply the thresholds to.
639 The values will be modified in place.
640 highThreshold : `numpy.ndarray`, optional
641 Array of upper limit values for each pixel of ``image``.
642 lowThreshold : `numpy.ndarray`, optional
643 Array of lower limit values for each pixel of ``image``.
644 regularizationWidth : `int`, optional
645 Minimum radius of a region to include in regularization, in pixels.
646 """
647 # Generate the structure for binary erosion and dilation, which is used
648 # to remove noise-like pixels. Groups of pixels with a radius smaller
649 # than ``regularizationWidth`` will be excluded from regularization.
650 filterStructure = ndimage.iterate_structure(ndimage.generate_binary_structure(2, 1),
651 regularizationWidth)
652 if highThreshold is not None:
653 highPixels = image > highThreshold
654 if regularizationWidth > 0:
655 # Erode and dilate ``highPixels`` to exclude noisy pixels.
656 highPixels = ndimage.binary_opening(highPixels, structure=filterStructure)
657 image[highPixels] = highThreshold[highPixels]
658 if lowThreshold is not None:
659 lowPixels = image < lowThreshold
660 if regularizationWidth > 0:
661 # Erode and dilate ``lowPixels`` to exclude noisy pixels.
662 lowPixels = ndimage.binary_opening(lowPixels, structure=filterStructure)
663 image[lowPixels] = lowThreshold[lowPixels]
664
665

◆ assign()

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 335 of file dcrModel.py.

335 def assign(self, dcrSubModel, bbox=None):
336 """Update a sub-region of the ``DcrModel`` with new values.
337
338 Parameters
339 ----------
340 dcrSubModel : `lsst.pipe.tasks.DcrModel`
341 New model of the true scene after correcting chromatic effects.
342 bbox : `lsst.afw.geom.Box2I`, optional
343 Sub-region of the coadd.
344 Defaults to the bounding box of ``dcrSubModel``.
345
346 Raises
347 ------
348 ValueError
349 If the new model has a different number of subfilters.
350 """
351 if len(dcrSubModel) != len(self):
352 raise ValueError("The number of DCR subfilters must be the same "
353 "between the old and new models.")
354 bbox = bbox or self.bbox
355 for model, subModel in zip(self, dcrSubModel):
356 model.assign(subModel[bbox], bbox)
357

◆ bandwidth()

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 253 of file dcrModel.py.

253 def bandwidth(self):
254 """Return the bandwidth of the model.
255
256 Returns
257 -------
258 bandwidth : `float`
259 The bandwidth of the current filter, in nanometers.
260 """
261 return self._bandwidth
262

◆ bbox()

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 275 of file dcrModel.py.

275 def bbox(self):
276 """Return the common bounding box of each subfilter image.
277
278 Returns
279 -------
280 bbox : `lsst.afw.geom.Box2I`
281 Bounding box of the DCR model.
282 """
283 return self._bbox
284
AmpInfoBoxKey bbox
Definition Amplifier.cc:117

◆ buildMatchedExposure()

lsst.ip.diffim.dcrModel.DcrModel.buildMatchedExposure ( self,
exposure = None,
visitInfo = None,
bbox = 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, or use the entire coadd if not supplied.
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 426 of file dcrModel.py.

427 visitInfo=None, bbox=None, mask=None):
428 """Wrapper to create an exposure from a template image.
429
430 Parameters
431 ----------
432 exposure : `lsst.afw.image.Exposure`, optional
433 The input exposure to build a matched template for.
434 May be omitted if all of the metadata is supplied separately
435 visitInfo : `lsst.afw.image.VisitInfo`, optional
436 Metadata for the exposure. Ignored if ``exposure`` is set.
437 bbox : `lsst.afw.geom.Box2I`, optional
438 Sub-region of the coadd, or use the entire coadd if not supplied.
439 mask : `lsst.afw.image.Mask`, optional
440 reference mask to use for the template image.
441
442 Returns
443 -------
444 templateExposure : `lsst.afw.image.exposureF`
445 The DCR-matched template
446
447 Raises
448 ------
449 RuntimeError
450 If no `photcCalib` is set.
451 """
452 if bbox is None:
453 bbox = self.bbox
454 templateImage = self.buildMatchedTemplate(exposure=exposure, visitInfo=visitInfo,
455 bbox=bbox, mask=mask)
456 maskedImage = afwImage.MaskedImageF(bbox)
457 maskedImage.image = templateImage[bbox]
458 maskedImage.mask = self.mask[bbox]
459 maskedImage.variance = self.variance[bbox]
460 # The variance of the stacked image will be `dcrNumSubfilters`
461 # times the variance of the individual subfilters.
462 maskedImage.variance *= self.dcrNumSubfilters
463 templateExposure = afwImage.ExposureF(bbox, self.wcs)
464 templateExposure.setMaskedImage(maskedImage[bbox])
465 templateExposure.setPsf(self.psf)
466 templateExposure.setFilter(self.filter)
467 if self.photoCalib is None:
468 raise RuntimeError("No PhotoCalib set for the DcrModel. "
469 "If the DcrModel was created from a masked image"
470 " you must also specify the photoCalib.")
471 templateExposure.setPhotoCalib(self.photoCalib)
472 return templateExposure
473

◆ buildMatchedTemplate()

lsst.ip.diffim.dcrModel.DcrModel.buildMatchedTemplate ( self,
exposure = None,
order = 3,
visitInfo = None,
bbox = 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, or use the entire coadd if not supplied.
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 ``visitInfo`` are set.

Definition at line 358 of file dcrModel.py.

360 splitSubfilters=True, splitThreshold=0., amplifyModel=1.):
361 """Create a DCR-matched template image for an exposure.
362
363 Parameters
364 ----------
365 exposure : `lsst.afw.image.Exposure`, optional
366 The input exposure to build a matched template for.
367 May be omitted if all of the metadata is supplied separately
368 order : `int`, optional
369 Interpolation order of the DCR shift.
370 visitInfo : `lsst.afw.image.VisitInfo`, optional
371 Metadata for the exposure. Ignored if ``exposure`` is set.
372 bbox : `lsst.afw.geom.Box2I`, optional
373 Sub-region of the coadd, or use the entire coadd if not supplied.
374 mask : `lsst.afw.image.Mask`, optional
375 reference mask to use for the template image.
376 splitSubfilters : `bool`, optional
377 Calculate DCR for two evenly-spaced wavelengths in each subfilter,
378 instead of at the midpoint. Default: True
379 splitThreshold : `float`, optional
380 Minimum DCR difference within a subfilter required to use
381 ``splitSubfilters``
382 amplifyModel : `float`, optional
383 Multiplication factor to amplify differences between model planes.
384 Used to speed convergence of iterative forward modeling.
385
386 Returns
387 -------
388 templateImage : `lsst.afw.image.ImageF`
389 The DCR-matched template
390
391 Raises
392 ------
393 ValueError
394 If neither ``exposure`` or ``visitInfo`` are set.
395 """
396 if self.effectiveWavelength is None or self.bandwidth is None:
397 raise ValueError("'effectiveWavelength' and 'bandwidth' must be set for the DcrModel in order "
398 "to calculate DCR.")
399 if exposure is not None:
400 visitInfo = exposure.getInfo().getVisitInfo()
401 elif visitInfo is None:
402 raise ValueError("Either exposure or visitInfo must be set.")
403 if bbox is None:
404 bbox = self.bbox
405 dcrShift = calculateDcr(visitInfo, self.wcs, self.effectiveWavelength, self.bandwidth, len(self),
406 splitSubfilters=splitSubfilters)
407 templateImage = afwImage.ImageF(bbox)
408 refModel = None
409 for subfilter, dcr in enumerate(dcrShift):
410 if self[subfilter] is None:
411 # It is possible to load only a single DCR subfilter at a time.
412 self.log.debug("Skipping missing DCR model subfilter %d", subfilter)
413 continue
414 if amplifyModel > 1:
415 if refModel is None:
416 # amplifyModel is only an option while constructing the DcrModel,
417 # and we don't want to calculate a reference image during image differencing.
418 refModel = self.getReferenceImage(bbox)
419 model = (self[subfilter][bbox].array - refModel)*amplifyModel + refModel
420 else:
421 model = self[subfilter][bbox].array
422 templateImage.array += applyDcr(model, dcr, splitSubfilters=splitSubfilters,
423 splitThreshold=splitThreshold, order=order)
424 return templateImage
425

◆ calculateNoiseCutoff()

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 586 of file dcrModel.py.

587 convergenceMaskPlanes="DETECTED", mask=None, bbox=None):
588 """Helper function to calculate the background noise level of an image.
589
590 Parameters
591 ----------
592 image : `lsst.afw.image.Image`
593 The input image to evaluate the background noise properties.
594 statsCtrl : `lsst.afw.math.StatisticsControl`
595 Statistics control object for coaddition.
596 bufferSize : `int`
597 Number of additional pixels to exclude
598 from the edges of the bounding box.
599 convergenceMaskPlanes : `list` of `str`, or `str`
600 Mask planes to use to calculate convergence.
601 mask : `lsst.afw.image.Mask`, Optional
602 Optional alternate mask
603 bbox : `lsst.afw.geom.Box2I`, optional
604 Sub-region of the masked image to calculate the noise level over.
605
606 Returns
607 -------
608 noiseCutoff : `float`
609 The threshold value to treat pixels as noise in an image..
610 """
611 if bbox is None:
612 bbox = self.bbox
613 if mask is None:
614 mask = self.mask[bbox]
615 bboxShrink = geom.Box2I(bbox)
616 bboxShrink.grow(-bufferSize)
617 convergeMask = mask.getPlaneBitMask(convergenceMaskPlanes)
618
619 backgroundPixels = mask[bboxShrink].array & (statsCtrl.getAndMask() | convergeMask) == 0
620 noiseCutoff = np.std(image[bboxShrink].array[backgroundPixels])
621 return noiseCutoff
622
An integer coordinate rectangle.
Definition Box.h:55

◆ conditionDcrModel()

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 474 of file dcrModel.py.

474 def conditionDcrModel(self, modelImages, bbox, gain=1.):
475 """Average two iterations' solutions to reduce oscillations.
476
477 Parameters
478 ----------
479 modelImages : `list` of `lsst.afw.image.Image`
480 The new DCR model images from the current iteration.
481 The values will be modified in place.
482 bbox : `lsst.afw.geom.Box2I`
483 Sub-region of the coadd
484 gain : `float`, optional
485 Relative weight to give the new solution when updating the model.
486 Defaults to 1.0, which gives equal weight to both solutions.
487 """
488 # Calculate weighted averages of the images.
489 for model, newModel in zip(self, modelImages):
490 newModel *= gain
491 newModel += model[bbox]
492 newModel /= 1. + gain
493

◆ effectiveWavelength()

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 231 of file dcrModel.py.

231 def effectiveWavelength(self):
232 """Return the effective wavelength of the model.
233
234 Returns
235 -------
236 effectiveWavelength : `float`
237 The effective wavelength of the current filter, in nanometers.
238 """
239 return self._effectiveWavelength
240

◆ filter()

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 242 of file dcrModel.py.

242 def filter(self):
243 """Return the filter label for the model.
244
245 Returns
246 -------
247 filterLabel : `lsst.afw.image.FilterLabel`
248 The filter used for the input observations.
249 """
250 return self._filterLabel
251

◆ fromImage()

lsst.ip.diffim.dcrModel.DcrModel.fromImage ( cls,
maskedImage,
dcrNumSubfilters,
effectiveWavelength,
bandwidth,
wcs = None,
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.
wcs : `lsst.afw.geom.SkyWcs`
    Coordinate system definition (wcs) for the exposure.
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 67 of file dcrModel.py.

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

◆ fromQuantum()

lsst.ip.diffim.dcrModel.DcrModel.fromQuantum ( cls,
availableCoaddRefs,
effectiveWavelength,
bandwidth,
numSubfilters )
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.
numSubfilters : `int`
    Number of subfilters in the DcrCoadd.

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

Definition at line 121 of file dcrModel.py.

121 def fromQuantum(cls, availableCoaddRefs, effectiveWavelength, bandwidth, numSubfilters):
122 """Load an existing DcrModel from a Gen 3 repository.
123
124 Parameters
125 ----------
126 availableCoaddRefs : `dict` [`int`, `lsst.daf.butler.DeferredDatasetHandle`]
127 Dictionary of spatially relevant retrieved coadd patches,
128 indexed by their sequential patch number.
129 effectiveWavelength : `float`
130 The effective wavelengths of the current filter, in nanometers.
131 bandwidth : `float`
132 The bandwidth of the current filter, in nanometers.
133 numSubfilters : `int`
134 Number of subfilters in the DcrCoadd.
135
136 Returns
137 -------
138 dcrModel : `lsst.pipe.tasks.DcrModel`
139 Best fit model of the true sky after correcting chromatic effects.
140 """
141 filterLabel = None
142 psf = None
143 bbox = None
144 wcs = None
145 mask = None
146 variance = None
147 photoCalib = None
148 modelImages = [None]*numSubfilters
149
150 for coaddRef in availableCoaddRefs:
151 subfilter = coaddRef.dataId["subfilter"]
152 dcrCoadd = coaddRef.get()
153 if filterLabel is None:
154 filterLabel = dcrCoadd.getFilter()
155 if psf is None:
156 psf = dcrCoadd.getPsf()
157 if bbox is None:
158 bbox = dcrCoadd.getBBox()
159 if wcs is None:
160 wcs = dcrCoadd.wcs
161 if mask is None:
162 mask = dcrCoadd.mask
163 if variance is None:
164 variance = dcrCoadd.variance
165 if photoCalib is None:
166 photoCalib = dcrCoadd.getPhotoCalib()
167 modelImages[subfilter] = dcrCoadd.image
168 return cls(modelImages, effectiveWavelength, bandwidth, filterLabel,
169 psf, bbox, wcs, mask, variance, photoCalib)
170

◆ getReferenceImage()

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 318 of file dcrModel.py.

318 def getReferenceImage(self, bbox=None):
319 """Calculate a reference image from the average of the subfilter
320 images.
321
322 Parameters
323 ----------
324 bbox : `lsst.afw.geom.Box2I`, optional
325 Sub-region of the coadd. Returns the entire image if `None`.
326
327 Returns
328 -------
329 refImage : `numpy.ndarray`
330 The reference image with no chromatic effects applied.
331 """
332 bbox = bbox or self.bbox
333 return np.mean([model[bbox].array for model in self], axis=0)
334

◆ mask()

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 297 of file dcrModel.py.

297 def mask(self):
298 """Return the common mask of each subfilter image.
299
300 Returns
301 -------
302 mask : `lsst.afw.image.Mask`
303 Mask plane of the DCR model.
304 """
305 return self._mask
306
afw::table::Key< afw::table::Array< MaskPixelT > > mask

◆ psf()

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 264 of file dcrModel.py.

264 def psf(self):
265 """Return the psf of the model.
266
267 Returns
268 -------
269 psf : `lsst.afw.detection.Psf`
270 Point spread function (PSF) of the model.
271 """
272 return self._psf
273
Key< int > psf
Definition Exposure.cc:65

◆ regularizeModelFreq()

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 520 of file dcrModel.py.

521 regularizationWidth=2, mask=None, convergenceMaskPlanes="DETECTED"):
522 """Restrict large variations in the model between subfilters.
523
524 Parameters
525 ----------
526 modelImages : `list` of `lsst.afw.image.Image`
527 The new DCR model images from the current iteration.
528 The values will be modified in place.
529 bbox : `lsst.afw.geom.Box2I`
530 Sub-region to coadd
531 statsCtrl : `lsst.afw.math.StatisticsControl`
532 Statistics control object for coaddition.
533 regularizationFactor : `float`
534 Maximum relative change of the model allowed between subfilters.
535 regularizationWidth : `int`, optional
536 Minimum radius of a region to include in regularization, in pixels.
537 mask : `lsst.afw.image.Mask`, optional
538 Optional alternate mask
539 convergenceMaskPlanes : `list` of `str`, or `str`, optional
540 Mask planes to use to calculate convergence.
541
542 Notes
543 -----
544 This implementation of frequency regularization restricts each
545 subfilter image to be a smoothly-varying function times a reference
546 image.
547 """
548 # ``regularizationFactor`` is the maximum change between subfilter
549 # images, so the maximum difference between one subfilter image and the
550 # average will be the square root of that.
551 maxDiff = np.sqrt(regularizationFactor)
552 noiseLevel = self.calculateNoiseCutoff(modelImages[0], statsCtrl, bufferSize=5, mask=mask, bbox=bbox)
553 referenceImage = self.getReferenceImage(bbox)
554 badPixels = np.isnan(referenceImage) | (referenceImage <= 0.)
555 if np.sum(~badPixels) == 0:
556 # Skip regularization if there are no valid pixels
557 return
558 referenceImage[badPixels] = 0.
559 filterWidth = regularizationWidth
560 fwhm = 2.*filterWidth
561 # The noise should be lower in the smoothed image by
562 # sqrt(Nsmooth) ~ fwhm pixels
563 noiseLevel /= fwhm
564 smoothRef = ndimage.gaussian_filter(referenceImage, filterWidth, mode='constant')
565 # Add a three sigma offset to both the reference and model to prevent
566 # dividing by zero. Note that this will also slightly suppress faint
567 # variations in color.
568 smoothRef += 3.*noiseLevel
569
570 lowThreshold = smoothRef/maxDiff
571 highThreshold = smoothRef*maxDiff
572 for model in modelImages:
573 self.applyImageThresholds(model.array,
574 highThreshold=highThreshold,
575 lowThreshold=lowThreshold,
576 regularizationWidth=regularizationWidth)
577 smoothModel = ndimage.gaussian_filter(model.array, filterWidth, mode='constant')
578 smoothModel += 3.*noiseLevel
579 relativeModel = smoothModel/smoothRef
580 # Now sharpen the smoothed relativeModel using an alpha of 3.
581 alpha = 3.
582 relativeModel2 = ndimage.gaussian_filter(relativeModel, filterWidth/alpha)
583 relativeModel += alpha*(relativeModel - relativeModel2)
584 model.array = relativeModel*referenceImage
585

◆ regularizeModelIter()

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 494 of file dcrModel.py.

495 regularizationWidth=2):
496 """Restrict large variations in the model between iterations.
497
498 Parameters
499 ----------
500 subfilter : `int`
501 Index of the current subfilter within the full band.
502 newModel : `lsst.afw.image.Image`
503 The new DCR model for one subfilter from the current iteration.
504 Values in ``newModel`` that are extreme compared with the last
505 iteration are modified in place.
506 bbox : `lsst.afw.geom.Box2I`
507 Sub-region to coadd
508 regularizationFactor : `float`
509 Maximum relative change of the model allowed between iterations.
510 regularizationWidth : int, optional
511 Minimum radius of a region to include in regularization, in pixels.
512 """
513 refImage = self[subfilter][bbox].array
514 highThreshold = np.abs(refImage)*regularizationFactor
515 lowThreshold = refImage/regularizationFactor
516 newImage = newModel.array
517 self.applyImageThresholds(newImage, highThreshold=highThreshold, lowThreshold=lowThreshold,
518 regularizationWidth=regularizationWidth)
519

◆ variance()

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 308 of file dcrModel.py.

308 def variance(self):
309 """Return the common variance of each subfilter image.
310
311 Returns
312 -------
313 variance : `lsst.afw.image.Image`
314 Variance plane of the DCR model.
315 """
316 return self._variance
317
afw::table::Key< afw::table::Array< VariancePixelT > > variance

◆ wcs()

lsst.ip.diffim.dcrModel.DcrModel.wcs ( self)
Return the WCS of each subfilter image.

Returns
-------
bbox : `lsst.afw.geom.SkyWcs`
    Coordinate system definition (wcs) for the exposure.

Definition at line 286 of file dcrModel.py.

286 def wcs(self):
287 """Return the WCS of each subfilter image.
288
289 Returns
290 -------
291 bbox : `lsst.afw.geom.SkyWcs`
292 Coordinate system definition (wcs) for the exposure.
293 """
294 return self._wcs
295
table::Key< table::Array< std::uint8_t > > wcs
Definition SkyWcs.cc:66

Member Data Documentation

◆ _bandwidth

lsst.ip.diffim.dcrModel.DcrModel._bandwidth
protected

Definition at line 58 of file dcrModel.py.

◆ _bbox

lsst.ip.diffim.dcrModel.DcrModel._bbox
protected

Definition at line 60 of file dcrModel.py.

◆ _effectiveWavelength

lsst.ip.diffim.dcrModel.DcrModel._effectiveWavelength
protected

Definition at line 57 of file dcrModel.py.

◆ _filterLabel

lsst.ip.diffim.dcrModel.DcrModel._filterLabel
protected

Definition at line 56 of file dcrModel.py.

◆ _mask

lsst.ip.diffim.dcrModel.DcrModel._mask
protected

Definition at line 62 of file dcrModel.py.

◆ _psf

lsst.ip.diffim.dcrModel.DcrModel._psf
protected

Definition at line 59 of file dcrModel.py.

◆ _variance

lsst.ip.diffim.dcrModel.DcrModel._variance
protected

Definition at line 63 of file dcrModel.py.

◆ _wcs

lsst.ip.diffim.dcrModel.DcrModel._wcs
protected

Definition at line 61 of file dcrModel.py.

◆ dcrNumSubfilters

lsst.ip.diffim.dcrModel.DcrModel.dcrNumSubfilters

Definition at line 54 of file dcrModel.py.

◆ filter

lsst.ip.diffim.dcrModel.DcrModel.filter

Definition at line 466 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 64 of file dcrModel.py.

◆ psf

lsst.ip.diffim.dcrModel.DcrModel.psf

Definition at line 465 of file dcrModel.py.


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