28 __all__ = [
"InterpImageConfig",
"InterpImageTask"]
31 """Config for InterpImageTask
33 modelPsf = measAlg.GaussianPsfFactory.makeField(doc =
"Model Psf factory")
35 useFallbackValueAtEdge = pexConfig.Field(
37 doc =
"Smoothly taper to the fallback value at the edge of the image?",
40 fallbackValueType = pexConfig.ChoiceField(
42 doc =
"Type of statistic to calculate edge fallbackValue for interpolation",
46 "MEANCLIP":
"clipped mean",
47 "USER":
"user value set in fallbackUserValue config",
51 fallbackUserValue = pexConfig.Field(
53 doc =
"If fallbackValueType is 'USER' then use this as the fallbackValue; ignored otherwise",
56 negativeFallbackAllowed = pexConfig.Field(
58 doc = (
"Allow negative values for egde interpolation fallbackValue? If False, set "
59 "fallbackValue to max(fallbackValue, 0.0)"),
64 pexConfig.Config.validate(self)
68 raise ValueError(
"User supplied fallbackValue is negative (%.2f) but "
72 """Interpolate over bad image pixels
74 ConfigClass = InterpImageConfig
75 _DefaultName =
"interpImage"
78 """Set the edge fallbackValue for interpolation
80 \param[in] mi input maksedImage on which to calculate the statistics
81 Must be provided if fallbackValueType != "USER".
83 \return fallbackValue The value set/computed based on the fallbackValueType
84 and negativeFallbackAllowed config parameters
86 if self.config.fallbackValueType !=
'USER':
87 assert mi,
"No maskedImage provided"
88 if self.config.fallbackValueType ==
'MEAN':
90 elif self.config.fallbackValueType ==
'MEDIAN':
92 elif self.config.fallbackValueType ==
'MEANCLIP':
94 elif self.config.fallbackValueType ==
'USER':
95 fallbackValue = self.config.fallbackUserValue
97 raise NotImplementedError(
"%s : %s not implemented" %
98 (
"fallbackValueType", self.config.fallbackValueType))
100 if not self.config.negativeFallbackAllowed
and fallbackValue < 0.0:
101 self.log.warn(
"Negative interpolation edge fallback value computed but "
102 "negativeFallbackAllowed is False: setting fallbackValue to 0.0")
103 fallbackValue = max(fallbackValue, 0.0)
105 self.log.info(
"fallbackValueType %s has been set to %.4f" %
106 (self.config.fallbackValueType, fallbackValue))
111 def run(self, image, planeName=None, fwhmPixels=None, defects=None):
112 """!Interpolate in place over pixels in a maskedImage marked as bad
114 Pixels to be interpolated are set by either a mask planeName provided
115 by the caller OR a defects list of type measAlg.DefectListT. If both
116 are provided an exception is raised.
118 Note that the interpolation code in meas_algorithms currently doesn't
119 use the input PSF (though it's a required argument), so it's not
120 important to set the input PSF parameters exactly. This PSF is set
121 here as the psf attached to the "image" (i.e if the image passed in
122 is an Exposure). Otherwise, a psf model is created using
123 measAlg.GaussianPsfFactory with the value of fwhmPixels (the value
124 passed in by the caller, or the default defaultFwhm set in
125 measAlg.GaussianPsfFactory if None).
127 \param[in,out] image MaskedImage OR Exposure to be interpolated
128 \param[in] planeName name of mask plane over which to interpolate
129 If None, must provide a defects list.
130 \param[in] fwhmPixels FWHM of core star (pixels)
131 If None the default is used, where the default
132 is set to the exposure psf if available
133 \param[in] defects List of defects of type measAlg.DefectListT
134 over which to interpolate.
137 maskedImage = image.getMaskedImage()
138 except AttributeError:
142 if planeName
is None:
144 raise ValueError(
"No defects or plane name provided")
147 planeName =
"defects"
149 if defects
is not None:
150 raise ValueError(
"Provide EITHER a planeName OR a list of defects, not both")
151 if not maskedImage.getMask().getMaskPlaneDict().has_key(planeName):
152 raise ValueError(
"maskedImage does not contain mask plane %s" % planeName)
153 defectList = ipIsr.getDefectListFromMask(maskedImage, planeName, growFootprints=0)
158 self.log.info(
"Setting psf for interpolation from image")
159 except AttributeError:
160 self.log.info(
"Creating psf model for interpolation from fwhm(pixels) = %s" %
161 (str(fwhmPixels)
if fwhmPixels
is not None else
162 (str(self.config.modelPsf.defaultFwhm)) +
" [default]"))
163 psf = self.config.modelPsf.apply(fwhm=fwhmPixels)
166 if self.config.useFallbackValueAtEdge:
170 self.config.useFallbackValueAtEdge)
172 self.log.info(
"Interpolated over %d %s pixels." % (len(defectList), planeName))
void interpolateOverDefects(MaskedImageT &image, lsst::afw::detection::Psf const &psf, std::vector< Defect::Ptr > &badList, double fallbackValue=0.0, bool useFallbackValueAtEdge=false)
Process a set of known bad pixels in an image.
def run
Interpolate in place over pixels in a maskedImage marked as bad.
tuple useFallbackValueAtEdge
Statistics makeStatistics(afwImage::Mask< afwImage::MaskPixel > const &msk, int const flags, StatisticsControl const &sctrl)
Specialization to handle Masks.
tuple negativeFallbackAllowed