22__all__ = [
"IsrStatisticsTaskConfig",
"IsrStatisticsTask"]
34 """Image statistics options.
36 doCtiStatistics = pexConfig.Field(
38 doc="Measure CTI statistics from image and overscans?",
41 stat = pexConfig.Field(
44 doc=
"Statistic name to use to measure regions.",
46 nSigmaClip = pexConfig.Field(
49 doc=
"Clipping threshold for background",
51 nIter = pexConfig.Field(
54 doc=
"Clipping iterations for background",
56 badMask = pexConfig.ListField(
58 default=[
"BAD",
"INTRP",
"SAT"],
59 doc=
"Mask planes to ignore when identifying source pixels."
64 """Task to measure arbitrary statistics on ISR processed exposures.
66 The goal is to wrap a number of optional measurements that are
67 useful
for calibration production
and detector stability.
69 ConfigClass = IsrStatisticsTaskConfig
70 _DefaultName = "isrStatistics"
72 def __init__(self, statControl=None, **kwargs):
75 afwImage.Mask.getPlaneBitMask(self.config.badMask))
78 def run(self, inputExp, ptc=None, overscanResults=None, **kwargs):
79 """Task to run arbitrary statistics.
81 The statistics should be measured by individual methods, and
82 add to the dictionary
in the
return struct.
87 The exposure to measure.
88 ptc : `lsst.ip.isr.PtcDataset`, optional
89 A PTC object containing gains to use.
90 overscanResults : `list` [`lsst.pipe.base.Struct`], optional
91 List of overscan results. Expected fields are:
94 Value
or fit subtracted
from the amplifier image data
97 Value
or fit subtracted
from the overscan image data
100 Image of the overscan region
with the overscan
102 quantity
is used to estimate the amplifier read noise
107 resultStruct : `lsst.pipe.base.Struct`
108 Contains the measured statistics
as a dict stored
in a
109 field named ``results``.
114 Raised
if the amplifier gains could
not be found.
117 detector = inputExp.getDetector()
120 elif detector
is not None:
121 gains = {amp.getName(): amp.getGain()
for amp
in detector.getAmplifiers()}
123 raise RuntimeError(
"No source of gains provided.")
124 if self.config.doCtiStatistics:
125 ctiResults = self.
measureCti(inputExp, overscanResults, gains)
127 return pipeBase.Struct(
128 results={
'CTI': ctiResults, },
132 """Task to measure CTI statistics.
138 overscans : `list` [`lsst.pipe.base.Struct`]
139 List of overscan results. Expected fields are:
142 Value or fit subtracted
from the amplifier image data
145 Value
or fit subtracted
from the overscan image data
148 Image of the overscan region
with the overscan
150 quantity
is used to estimate the amplifier read noise
152 gains : `dict` [`str` `float`]
153 Dictionary of per-amplifier gains, indexed by amplifier name.
157 outputStats : `dict` [`str`, [`dict` [`str`,`float]]
158 Dictionary of measurements, keyed by amplifier name
and
163 detector = inputExp.getDetector()
164 image = inputExp.image
167 assert len(overscans) == len(detector.getAmplifiers())
169 for ampIter, amp
in enumerate(detector.getAmplifiers()):
171 gain = gains[amp.getName()]
172 readoutCorner = amp.getReadoutCorner()
174 dataRegion = image[amp.getBBox()]
188 if readoutCorner
in (ReadoutCorner.LR, ReadoutCorner.UR):
189 ampStats[
'FIRST_MEAN'] = pixelZ
190 ampStats[
'LAST_MEAN'] = pixelA
192 ampStats[
'FIRST_MEAN'] = pixelA
193 ampStats[
'LAST_MEAN'] = pixelZ
196 if overscans[ampIter]
is None:
199 self.log.warn(
"No overscan information available for ISR statistics for amp %s.",
201 nCols = amp.getSerialOverscanBBox().getWidth()
202 ampStats[
'OVERSCAN_COLUMNS'] = np.full((nCols, ), np.nan)
203 ampStats[
'OVERSCAN_VALUES'] = np.full((nCols, ), np.nan)
205 overscanImage = overscans[ampIter].overscanImage
208 for column
in range(0, overscanImage.getWidth()):
211 columns.append(column)
212 values.append(gain * osMean)
216 if readoutCorner
in (ReadoutCorner.LR, ReadoutCorner.UR):
217 ampStats[
'OVERSCAN_COLUMNS'] =
list(reversed(columns))
218 ampStats[
'OVERSCAN_VALUES'] =
list(reversed(values))
220 ampStats[
'OVERSCAN_COLUMNS'] = columns
221 ampStats[
'OVERSCAN_VALUES'] = values
223 outputStats[amp.getName()] = ampStats
A class to contain the data, WCS, and other information needed to describe an image of the sky.
A class to represent a 2-dimensional array of pixels.
Pass parameters to a Statistics object.
def __init__(self, statControl=None, **kwargs)
def measureCti(self, inputExp, overscans, gains)
daf::base::PropertyList * list
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)
Property stringToStatisticsProperty(std::string const property)
Conversion function to switch a string to a Property (see Statistics.h)