22 __all__ = [
"BackgroundList"]
30 from .
import mathLib
as afwMath
34 """A list-like class to contain a list of (`lsst.afw.math.Background`, 35 `lsst.afw.math.Interpolate.Style`, `~lsst.afw.math.UndersampleStyle`) 40 *args : `tuple` or `~lsst.afw.math.Background` 41 A sequence of arguments, each of which becomes an element of the list. 42 In deference to the deprecated-but-not-yet-removed 43 `~lsst.afw.math.Background.getImageF()` API, we also accept a single 44 `lsst.afw.math.Background` and extract the ``interpStyle`` and 45 ``undersampleStyle`` from the as-used values. 65 bkgd, interpStyle, undersampleStyle, approxStyle, \
66 approxOrderX, approxOrderY, approxWeighting = val
67 if interpStyle
is None or undersampleStyle
is None:
68 interpStyle = bkgd.getAsUsedInterpStyle()
69 undersampleStyle = bkgd.getAsUsedUndersampleStyle()
70 actrl = bkgd.getBackgroundControl().getApproximateControl()
71 approxStyle = actrl.getStyle()
72 approxOrderX = actrl.getOrderX()
73 approxOrderY = actrl.getOrderY()
74 approxWeighting = actrl.getWeighting()
75 self.
_backgrounds[i] = (bkgd, interpStyle, undersampleStyle,
76 approxStyle, approxOrderX, approxOrderY, approxWeighting)
87 bkgd, interpStyle, undersampleStyle, approxStyle, \
88 approxOrderX, approxOrderY, approxWeighting = val
90 warnings.warn(
"Passing Background objects to BackgroundList is deprecated; " 91 "use a (Background, Interpolation.Style, UndersampleStyle, " 92 "ApproximateControl.Style, int, int, bool) tuple instead.",
93 category=FutureWarning, stacklevel=2)
96 undersampleStyle =
None 100 approxWeighting =
None 102 bgInfo = (bkgd, interpStyle, undersampleStyle, approxStyle,
103 approxOrderX, approxOrderY, approxWeighting)
107 """Return a shallow copy 109 Shallow copies do not share backgrounds that are appended after copying, 110 but do share changes to contained background objects. 115 """Save our list of Backgrounds to a file. 122 Flags to control details of writing; currently unused, but present 123 for consistency with `lsst.afw.table.BaseCatalog.writeFits`. 126 for i, bkgd
in enumerate(self):
127 (bkgd, interpStyle, undersampleStyle, approxStyle, approxOrderX, approxOrderY,
128 approxWeighting) = bkgd
130 statsImage = bkgd.getStatsImage()
133 md.set(
"INTERPSTYLE", int(interpStyle))
134 md.set(
"UNDERSAMPLESTYLE", int(undersampleStyle))
135 md.set(
"APPROXSTYLE", int(approxStyle))
136 md.set(
"APPROXORDERX", approxOrderX)
137 md.set(
"APPROXORDERY", approxOrderY)
138 md.set(
"APPROXWEIGHTING", approxWeighting)
139 bbox = bkgd.getImageBBox()
140 md.set(
"BKGD_X0", bbox.getMinX())
141 md.set(
"BKGD_Y0", bbox.getMinY())
142 md.set(
"BKGD_WIDTH", bbox.getWidth())
143 md.set(
"BKGD_HEIGHT", bbox.getHeight())
145 statsImage.getImage().
writeFits(fileName, md,
"w" if i == 0
else "a")
146 statsImage.getMask().
writeFits(fileName, md,
"a")
147 statsImage.getVariance().
writeFits(fileName, md,
"a")
151 """Read our list of Backgrounds from a file. 158 First Header/Data Unit to attempt to read from 160 Flags to control details of reading; currently unused, but present 161 for consistency with `lsst.afw.table.BaseCatalog.readFits`. 167 if not isinstance(fileName, MemFileManager)
and not os.path.exists(fileName):
168 raise RuntimeError(
"File not found: %s" % fileName)
172 f =
Fits(fileName,
'r') 173 nHdus = f.countHdus() 176 raise RuntimeError(f
"BackgroundList FITS file {fileName} has {nHdus} HDUs;" 177 f
"expected a multiple of 3 (compression is not supported).")
179 for hdu
in range(0, nHdus, 3):
186 statsImage = afwImage.MaskedImageF(imageReader.read(), maskReader.read(), varianceReader.read())
187 md = imageReader.readMetadata()
191 width = md[
"BKGD_WIDTH"]
192 height = md[
"BKGD_HEIGHT"]
195 interpStyle = afwMath.Interpolate.Style(md[
"INTERPSTYLE"])
202 approxStyle = md.get(
"APPROXSTYLE", afwMath.ApproximateControl.UNKNOWN)
203 approxStyle = afwMath.ApproximateControl.Style(approxStyle)
204 approxOrderX = md.get(
"APPROXORDERX", 1)
205 approxOrderY = md.get(
"APPROXORDERY", -1)
206 approxWeighting = md.get(
"APPROXWEIGHTING",
True)
209 bctrl = bkgd.getBackgroundControl()
210 bctrl.setInterpStyle(interpStyle)
211 bctrl.setUndersampleStyle(undersampleStyle)
213 bctrl.setApproximateControl(actrl)
214 bgInfo = (bkgd, interpStyle, undersampleStyle, approxStyle,
215 approxOrderX, approxOrderY, approxWeighting)
221 """Compute and return a full-resolution image from our list of 222 (Background, interpStyle, undersampleStyle). 226 for (bkgd, interpStyle, undersampleStyle, approxStyle,
227 approxOrderX, approxOrderY, approxWeighting)
in self:
229 bkgdImage = bkgd.getImageF(interpStyle, undersampleStyle)
231 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.