27 import lsst.pex.config
as pexConfig
31 meshX = pexConfig.Field(
33 doc=
"Mesh size in X for flatness statistics",
36 meshY = pexConfig.Field(
38 doc=
"Mesh size in Y for flatness statistics",
41 doClip = pexConfig.Field(
43 doc=
"Clip outliers for flatness statistics?",
46 clipSigma = pexConfig.Field(
48 doc=
"Number of sigma deviant a pixel must be to be clipped from flatness statistics.",
51 nIter = pexConfig.Field(
53 doc=
"Number of iterations used for outlier clipping in flatness statistics.",
59 saveStats = pexConfig.Field(
61 doc=
"Calculate ISR statistics while processing?",
65 flatness = pexConfig.ConfigField(
66 dtype=IsrQaFlatnessConfig,
67 doc=
"Flatness statistics configuration.",
70 doWriteOss = pexConfig.Field(
72 doc=
"Write overscan subtracted image?",
75 doThumbnailOss = pexConfig.Field(
77 doc=
"Write overscan subtracted thumbnail?",
81 doWriteFlattened = pexConfig.Field(
83 doc=
"Write image after flat-field correction?",
86 doThumbnailFlattened = pexConfig.Field(
88 doc=
"Write thumbnail after flat-field correction?",
92 thumbnailBinning = pexConfig.Field(
94 doc=
"Thumbnail binning factor.",
97 thumbnailStdev = pexConfig.Field(
99 doc=
"Number of sigma below the background to set the thumbnail minimum.",
102 thumbnailRange = pexConfig.Field(
104 doc=
"Total range in sigma for thumbnail mapping.",
107 thumbnailQ = pexConfig.Field(
109 doc=
"Softening parameter for thumbnail mapping.",
112 thumbnailSatBorder = pexConfig.Field(
114 doc=
"Width of border around saturated pixels in thumbnail.",
120 """Create a snapshot thumbnail from input exposure.
122 The output thumbnail image is constructed based on the parameters
123 in the configuration file. Currently, the asinh mapping is the
124 only mapping method used.
128 exposure : `lsst.afw.image.Exposure`
129 The exposure to be converted into a thumbnail.
130 isrQaConfig : `Config`
131 Configuration object containing all parameters to control the
132 thumbnail generation.
136 rgbImage : `numpy.ndarray`
137 Binned and scaled version of the exposure, converted to an
138 integer array to allow it to be written as PNG.
140 if isrQaConfig
is not None:
141 binning = isrQaConfig.thumbnailBinning
142 binnedImage =
afwMath.binImage(exposure.getMaskedImage(), binning, binning, afwMath.MEAN)
145 statsCtrl.setAndMask(binnedImage.getMask().getPlaneBitMask([
"SAT",
"BAD",
"INTRP"]))
147 afwMath.MEDIAN | afwMath.STDEVCLIP | afwMath.MAX, statsCtrl)
149 low = stats.getValue(afwMath.MEDIAN) - isrQaConfig.thumbnailStdev*stats.getValue(afwMath.STDEVCLIP)
151 if isrQaConfig.thumbnailSatBorder:
152 afwRGB.replaceSaturatedPixels(binnedImage, binnedImage, binnedImage,
153 isrQaConfig.thumbnailSatBorder, stats.getValue(afwMath.MAX))
155 asinhMap = afwRGB.AsinhMapping(low, isrQaConfig.thumbnailRange, Q=isrQaConfig.thumbnailQ)
156 rgbImage = asinhMap.makeRgbImage(binnedImage)
162 """Write snapshot thumbnail to disk.
166 dataRef : `daf.persistence.butlerSubset.ButlerDataRef`
167 Butler dataref to use to construct the output filename.
168 thumb : `numpy.ndarray`
169 Binned and scaled image to be written as a PNG.
171 String containing the dataset for this thumbnail.
176 Raised if the output directory cannot be created and does not
179 filename = dataRef.get(dataset +
"_filename")[0]
180 directory = os.path.dirname(filename)
181 if not os.path.exists(directory):
183 os.makedirs(directory)
186 if e.errno != errno.EEXIST:
188 afwRGB.writeRGB(filename, thumb)