LSST Applications g0265f82a02+0e5473021a,g02d81e74bb+0dd8ce4237,g1470d8bcf6+3ea6592b6f,g2079a07aa2+86d27d4dc4,g2305ad1205+5ca4c0b359,g295015adf3+d10818ec9d,g2a9a014e59+6f9be1b9cd,g2bbee38e9b+0e5473021a,g337abbeb29+0e5473021a,g3ddfee87b4+703ba97ebf,g487adcacf7+4fa16da234,g50ff169b8f+96c6868917,g52b1c1532d+585e252eca,g591dd9f2cf+ffa42b374e,g5a732f18d5+53520f316c,g64a986408d+0dd8ce4237,g858d7b2824+0dd8ce4237,g8a8a8dda67+585e252eca,g99cad8db69+d39438377f,g9ddcbc5298+9a081db1e4,ga1e77700b3+15fc3df1f7,ga8c6da7877+f1d96605c8,gb0e22166c9+60f28cb32d,gb6a65358fc+0e5473021a,gba4ed39666+c2a2e4ac27,gbb8dafda3b+e5339d463f,gc120e1dc64+da31e9920e,gc28159a63d+0e5473021a,gcf0d15dbbd+703ba97ebf,gdaeeff99f8+f9a426f77a,ge6526c86ff+889fc9d533,ge79ae78c31+0e5473021a,gee10cc3b42+585e252eca,gf18bd8381d+7268b93478,gff1a9f87cc+0dd8ce4237,w.2024.16
LSST Data Management Base Package
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | Protected Member Functions | Static Protected Attributes | List of all members
lsst.pipe.tasks.interpImage.InterpImageTask Class Reference
Inheritance diagram for lsst.pipe.tasks.interpImage.InterpImageTask:

Public Member Functions

 run (self, image, planeName=None, fwhmPixels=None, defects=None)
 
 transposeContext (self, maskedImage, defects)
 
 interpolateImage (self, maskedImage, psf, defectList, fallbackValue)
 

Static Public Attributes

 ConfigClass = InterpImageConfig
 

Protected Member Functions

 _setFallbackValue (self, mi=None)
 

Static Protected Attributes

str _DefaultName = "interpImage"
 

Detailed Description

Interpolate over bad image pixels

Definition at line 85 of file interpImage.py.

Member Function Documentation

◆ _setFallbackValue()

lsst.pipe.tasks.interpImage.InterpImageTask._setFallbackValue ( self,
mi = None )
protected
Set the edge fallbackValue for interpolation

Parameters
----------
mi : `lsst.afw.image.MaskedImage`, optional
    Input maskedImage on which to calculate the statistics
    Must be provided if fallbackValueType != "USER".

Returns
-------
fallbackValue : `float`
    The value set/computed based on the fallbackValueType
    and negativeFallbackAllowed config parameters.

Definition at line 91 of file interpImage.py.

91 def _setFallbackValue(self, mi=None):
92 """Set the edge fallbackValue for interpolation
93
94 Parameters
95 ----------
96 mi : `lsst.afw.image.MaskedImage`, optional
97 Input maskedImage on which to calculate the statistics
98 Must be provided if fallbackValueType != "USER".
99
100 Returns
101 -------
102 fallbackValue : `float`
103 The value set/computed based on the fallbackValueType
104 and negativeFallbackAllowed config parameters.
105 """
106 if self.config.fallbackValueType != 'USER':
107 assert mi, "No maskedImage provided"
108 if self.config.fallbackValueType == 'MEAN':
109 fallbackValue = afwMath.makeStatistics(mi, afwMath.MEAN).getValue()
110 elif self.config.fallbackValueType == 'MEDIAN':
111 fallbackValue = afwMath.makeStatistics(mi, afwMath.MEDIAN).getValue()
112 elif self.config.fallbackValueType == 'MEANCLIP':
113 fallbackValue = afwMath.makeStatistics(mi, afwMath.MEANCLIP).getValue()
114 elif self.config.fallbackValueType == 'USER':
115 fallbackValue = self.config.fallbackUserValue
116 else:
117 raise NotImplementedError("%s : %s not implemented" %
118 ("fallbackValueType", self.config.fallbackValueType))
119
120 if not self.config.negativeFallbackAllowed and fallbackValue < 0.0:
121 self.log.warning("Negative interpolation edge fallback value computed but "
122 "negativeFallbackAllowed is False: setting fallbackValue to 0.0")
123 fallbackValue = max(fallbackValue, 0.0)
124
125 self.log.info("fallbackValueType %s has been set to %.4f",
126 self.config.fallbackValueType, fallbackValue)
127
128 return fallbackValue
129
int max
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:361

◆ interpolateImage()

lsst.pipe.tasks.interpImage.InterpImageTask.interpolateImage ( self,
maskedImage,
psf,
defectList,
fallbackValue )
Interpolate over defects in an image

Parameters
----------
maskedImage : `lsst.afw.image.MaskedImage`
    Image on which to perform interpolation.
psf : `lsst.afw.detection.Psf`
    Point-spread function; currently unused.
defectList : `lsst.meas.algorithms.Defects`
    List of defects to interpolate over.
fallbackValue : `float`
    Value to set when interpolation fails.

Definition at line 251 of file interpImage.py.

251 def interpolateImage(self, maskedImage, psf, defectList, fallbackValue):
252 """Interpolate over defects in an image
253
254 Parameters
255 ----------
256 maskedImage : `lsst.afw.image.MaskedImage`
257 Image on which to perform interpolation.
258 psf : `lsst.afw.detection.Psf`
259 Point-spread function; currently unused.
260 defectList : `lsst.meas.algorithms.Defects`
261 List of defects to interpolate over.
262 fallbackValue : `float`
263 Value to set when interpolation fails.
264 """
265 if not defectList:
266 return
267 with self.transposeContext(maskedImage, defectList) as (image, defects):
268 measAlg.interpolateOverDefects(image, psf, defects, fallbackValue,
269 self.config.useFallbackValueAtEdge)

◆ run()

lsst.pipe.tasks.interpImage.InterpImageTask.run ( self,
image,
planeName = None,
fwhmPixels = None,
defects = None )
Interpolate in place over pixels in a maskedImage marked as bad

Pixels to be interpolated are set by either a mask planeName provided
by the caller OR a defects list of type `~lsst.meas.algorithms.Defects`
If both are provided an exception is raised.

Note that the interpolation code in meas_algorithms currently doesn't
use the input PSF (though it's a required argument), so it's not
important to set the input PSF parameters exactly.  This PSF is set
here as the psf attached to the "image" (i.e if the image passed in
is an Exposure).  Otherwise, a psf model is created using
measAlg.GaussianPsfFactory with the value of fwhmPixels (the value
passed in by the caller, or the default defaultFwhm set in
measAlg.GaussianPsfFactory if None).

Parameters
----------
image : `lsst.afw.image.MaskedImage` or `lsst.afw.image.exposure.Exposure`
    MaskedImage OR Exposure to be interpolated.
planeName : `str`, optional
    Name of mask plane over which to interpolate.
    If None, must provide a defects list.
fwhmPixels : `int`, optional
    FWHM of core star (pixels).
    If None the default is used, where the default
    is set to the exposure psf if available.
defects : `lsst.meas.algorithms.Defects`, optional
    List of defects of type ipIsr.Defects
    over which to interpolate.

Definition at line 131 of file interpImage.py.

131 def run(self, image, planeName=None, fwhmPixels=None, defects=None):
132 """Interpolate in place over pixels in a maskedImage marked as bad
133
134 Pixels to be interpolated are set by either a mask planeName provided
135 by the caller OR a defects list of type `~lsst.meas.algorithms.Defects`
136 If both are provided an exception is raised.
137
138 Note that the interpolation code in meas_algorithms currently doesn't
139 use the input PSF (though it's a required argument), so it's not
140 important to set the input PSF parameters exactly. This PSF is set
141 here as the psf attached to the "image" (i.e if the image passed in
142 is an Exposure). Otherwise, a psf model is created using
143 measAlg.GaussianPsfFactory with the value of fwhmPixels (the value
144 passed in by the caller, or the default defaultFwhm set in
145 measAlg.GaussianPsfFactory if None).
146
147 Parameters
148 ----------
149 image : `lsst.afw.image.MaskedImage` or `lsst.afw.image.exposure.Exposure`
150 MaskedImage OR Exposure to be interpolated.
151 planeName : `str`, optional
152 Name of mask plane over which to interpolate.
153 If None, must provide a defects list.
154 fwhmPixels : `int`, optional
155 FWHM of core star (pixels).
156 If None the default is used, where the default
157 is set to the exposure psf if available.
158 defects : `lsst.meas.algorithms.Defects`, optional
159 List of defects of type ipIsr.Defects
160 over which to interpolate.
161 """
162 try:
163 maskedImage = image.getMaskedImage()
164 except AttributeError:
165 maskedImage = image
166
167 # set defectList from defects OR mask planeName provided
168 if planeName is None:
169 if defects is None:
170 raise ValueError("No defects or plane name provided")
171 else:
172 if not isinstance(defects, ipIsr.Defects):
173 defectList = ipIsr.Defects(defects)
174 else:
175 defectList = defects
176 planeName = "defects"
177 else:
178 if defects is not None:
179 raise ValueError("Provide EITHER a planeName OR a list of defects, not both")
180 if planeName not in maskedImage.getMask().getMaskPlaneDict():
181 raise ValueError("maskedImage does not contain mask plane %s" % planeName)
182 defectList = ipIsr.Defects.fromMask(maskedImage, planeName)
183
184 # set psf from exposure if provided OR using modelPsf with fwhmPixels provided
185 try:
186 psf = image.getPsf()
187 self.log.info("Setting psf for interpolation from image")
188 except AttributeError:
189 self.log.info("Creating psf model for interpolation from fwhm(pixels) = %s",
190 str(fwhmPixels) if fwhmPixels is not None else
191 (str(self.config.modelPsf.defaultFwhm)) + " [default]")
192 psf = self.config.modelPsf.apply(fwhm=fwhmPixels)
193
194 fallbackValue = 0.0 # interpolateOverDefects needs this to be a float, regardless if it is used
195 if self.config.useFallbackValueAtEdge:
196 fallbackValue = self._setFallbackValue(maskedImage)
197
198 self.interpolateImage(maskedImage, psf, defectList, fallbackValue)
199
200 self.log.info("Interpolated over %d %s pixels.", len(defectList), planeName)
201

◆ transposeContext()

lsst.pipe.tasks.interpImage.InterpImageTask.transposeContext ( self,
maskedImage,
defects )
Context manager to potentially transpose an image

This applies the ``transpose`` configuration setting.

Transposing the image allows us to interpolate along columns instead
of rows, which is useful when the saturation trails are typically
oriented along rows on the warped/coadded images, instead of along
columns as they typically are in raw CCD images.

Parameters
----------
maskedImage : `lsst.afw.image.MaskedImage`
    Image on which to perform interpolation.
defects : `lsst.meas.algorithms.Defects`
    List of defects to interpolate over.

Yields
------
useImage : `lsst.afw.image.MaskedImage`
    Image to use for interpolation; it may have been transposed.
useDefects : `lsst.meas.algorithms.Defects`
    List of defects to use for interpolation; they may have been
    transposed.

Definition at line 203 of file interpImage.py.

203 def transposeContext(self, maskedImage, defects):
204 """Context manager to potentially transpose an image
205
206 This applies the ``transpose`` configuration setting.
207
208 Transposing the image allows us to interpolate along columns instead
209 of rows, which is useful when the saturation trails are typically
210 oriented along rows on the warped/coadded images, instead of along
211 columns as they typically are in raw CCD images.
212
213 Parameters
214 ----------
215 maskedImage : `lsst.afw.image.MaskedImage`
216 Image on which to perform interpolation.
217 defects : `lsst.meas.algorithms.Defects`
218 List of defects to interpolate over.
219
220 Yields
221 ------
222 useImage : `lsst.afw.image.MaskedImage`
223 Image to use for interpolation; it may have been transposed.
224 useDefects : `lsst.meas.algorithms.Defects`
225 List of defects to use for interpolation; they may have been
226 transposed.
227 """
228 def transposeImage(image):
229 """Transpose an image
230
231 Parameters
232 ----------
233 image : `Unknown`
234 """
235 transposed = image.array.T.copy() # Copy to force row-major; required for ndarray+pybind
236 return image.Factory(transposed, False, lsst.geom.Point2I(*reversed(image.getXY0())))
237
238 useImage = maskedImage
239 useDefects = defects
240 if self.config.transpose:
241 useImage = afwImage.makeMaskedImage(transposeImage(maskedImage.image),
242 transposeImage(maskedImage.mask),
243 transposeImage(maskedImage.variance))
244 useDefects = defects.transpose()
245 yield useImage, useDefects
246 if self.config.transpose:
247 maskedImage.image.array = useImage.image.array.T
248 maskedImage.mask.array = useImage.mask.array.T
249 maskedImage.variance.array = useImage.variance.array.T
250
MaskedImage< ImagePixelT, MaskPixelT, VariancePixelT > * makeMaskedImage(typename std::shared_ptr< Image< ImagePixelT > > image, typename std::shared_ptr< Mask< MaskPixelT > > mask=Mask< MaskPixelT >(), typename std::shared_ptr< Image< VariancePixelT > > variance=Image< VariancePixelT >())
A function to return a MaskedImage of the correct type (cf.

Member Data Documentation

◆ _DefaultName

str lsst.pipe.tasks.interpImage.InterpImageTask._DefaultName = "interpImage"
staticprotected

Definition at line 89 of file interpImage.py.

◆ ConfigClass

lsst.pipe.tasks.interpImage.InterpImageTask.ConfigClass = InterpImageConfig
static

Definition at line 88 of file interpImage.py.


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