22 __all__ = [
"BackgroundList"]
29 from .
import mathLib
as afwMath
33 """A list-like class to contain a list of (`lsst.afw.math.Background`, 34 `lsst.afw.math.Interpolate.Style`, `~lsst.afw.math.UndersampleStyle`) 39 *args : `tuple` or `~lsst.afw.math.Background` 40 A sequence of arguments, each of which becomes an element of the list. 41 In deference to the deprecated-but-not-yet-removed 42 `~lsst.afw.math.Background.getImageF()` API, we also accept a single 43 `lsst.afw.math.Background` and extract the ``interpStyle`` and 44 ``undersampleStyle`` from the as-used values. 64 bkgd, interpStyle, undersampleStyle, approxStyle, \
65 approxOrderX, approxOrderY, approxWeighting = val
66 if interpStyle
is None or undersampleStyle
is None:
67 interpStyle = bkgd.getAsUsedInterpStyle()
68 undersampleStyle = bkgd.getAsUsedUndersampleStyle()
69 actrl = bkgd.getBackgroundControl().getApproximateControl()
70 approxStyle = actrl.getStyle()
71 approxOrderX = actrl.getOrderX()
72 approxOrderY = actrl.getOrderY()
73 approxWeighting = actrl.getWeighting()
74 self.
_backgrounds[i] = (bkgd, interpStyle, undersampleStyle,
75 approxStyle, approxOrderX, approxOrderY, approxWeighting)
86 bkgd, interpStyle, undersampleStyle, approxStyle, \
87 approxOrderX, approxOrderY, approxWeighting = val
91 undersampleStyle =
None 95 approxWeighting =
None 97 bgInfo = (bkgd, interpStyle, undersampleStyle, approxStyle,
98 approxOrderX, approxOrderY, approxWeighting)
102 """Return a shallow copy 104 Shallow copies do not share backgrounds that are appended after copying, 105 but do share changes to contained background objects. 110 """Save our list of Backgrounds to a file. 117 Flags to control details of writing; currently unused, but present 118 for consistency with `lsst.afw.table.BaseCatalog.writeFits`. 121 for i, bkgd
in enumerate(self):
122 (bkgd, interpStyle, undersampleStyle, approxStyle, approxOrderX, approxOrderY,
123 approxWeighting) = bkgd
125 statsImage = bkgd.getStatsImage()
128 md.set(
"INTERPSTYLE", int(interpStyle))
129 md.set(
"UNDERSAMPLESTYLE", int(undersampleStyle))
130 md.set(
"APPROXSTYLE", int(approxStyle))
131 md.set(
"APPROXORDERX", approxOrderX)
132 md.set(
"APPROXORDERY", approxOrderY)
133 md.set(
"APPROXWEIGHTING", approxWeighting)
134 bbox = bkgd.getImageBBox()
135 md.set(
"BKGD_X0", bbox.getMinX())
136 md.set(
"BKGD_Y0", bbox.getMinY())
137 md.set(
"BKGD_WIDTH", bbox.getWidth())
138 md.set(
"BKGD_HEIGHT", bbox.getHeight())
140 statsImage.getImage().
writeFits(fileName, md,
"w" if i == 0
else "a")
141 statsImage.getMask().
writeFits(fileName, md,
"a")
142 statsImage.getVariance().
writeFits(fileName, md,
"a")
146 """Read our list of Backgrounds from a file. 153 First Header/Data Unit to attempt to read from 155 Flags to control details of reading; currently unused, but present 156 for consistency with `lsst.afw.table.BaseCatalog.readFits`. 162 if not isinstance(fileName, MemFileManager)
and not os.path.exists(fileName):
163 raise RuntimeError(
"File not found: %s" % fileName)
167 f =
Fits(fileName,
'r') 168 nHdus = f.countHdus() 171 raise RuntimeError(f
"BackgroundList FITS file {fileName} has {nHdus} HDUs;" 172 f
"expected a multiple of 3 (compression is not supported).")
174 for hdu
in range(0, nHdus, 3):
181 statsImage = afwImage.MaskedImageF(imageReader.read(), maskReader.read(), varianceReader.read())
182 md = imageReader.readMetadata()
186 width = md[
"BKGD_WIDTH"]
187 height = md[
"BKGD_HEIGHT"]
190 interpStyle = afwMath.Interpolate.Style(md[
"INTERPSTYLE"])
197 approxStyle = md.get(
"APPROXSTYLE", afwMath.ApproximateControl.UNKNOWN)
198 approxStyle = afwMath.ApproximateControl.Style(approxStyle)
199 approxOrderX = md.get(
"APPROXORDERX", 1)
200 approxOrderY = md.get(
"APPROXORDERY", -1)
201 approxWeighting = md.get(
"APPROXWEIGHTING",
True)
204 bctrl = bkgd.getBackgroundControl()
205 bctrl.setInterpStyle(interpStyle)
206 bctrl.setUndersampleStyle(undersampleStyle)
208 bctrl.setApproximateControl(actrl)
209 bgInfo = (bkgd, interpStyle, undersampleStyle, approxStyle,
210 approxOrderX, approxOrderY, approxWeighting)
216 """Compute and return a full-resolution image from our list of 217 (Background, interpStyle, undersampleStyle). 221 for (bkgd, interpStyle, undersampleStyle, approxStyle,
222 approxOrderX, approxOrderY, approxWeighting)
in self:
224 if approxStyle != afwMath.ApproximateControl.UNKNOWN:
225 bkgdImage = bkgd.getImageF()
227 bkgdImage = bkgd.getImageF(interpStyle, undersampleStyle)
229 if approxStyle != afwMath.ApproximateControl.UNKNOWN:
230 bkgdImage += bkgd.getImageF()
232 bkgdImage += bkgd.getImageF(interpStyle, undersampleStyle)
A FITS reader class for Masks.
def __getitem__(self, args)
def writeFits(self, fileName, flags=0)
Class for storing ordered metadata with comments.
A FITS reader class for regular Images.
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Control how to make an approximation.
def readFits(fileName, hdu=0, flags=0)
A class to evaluate image background levels.
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects...
An integer coordinate rectangle.