22 __all__ = [
"BackgroundList"]
29 from .interpolate
import Interpolate
30 from .approximate
import ApproximateControl
31 from .background
import BackgroundMI
32 from .background
import UndersampleStyle
36 """A list-like class to contain a list of (`lsst.afw.math.Background`,
37 `lsst.afw.math.Interpolate.Style`, `~lsst.afw.math.UndersampleStyle`)
42 *args : `tuple` or `~lsst.afw.math.Background`
43 A sequence of arguments, each of which becomes an element of the list.
44 We also accept a single `lsst.afw.math.Background` and extract the
45 ``interpStyle`` and ``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_backgrounds[i] = (bkgd, interpStyle, undersampleStyle,
76 approxStyle, approxOrderX, approxOrderY, approxWeighting)
87 bkgd, interpStyle, undersampleStyle, approxStyle, \
88 approxOrderX, approxOrderY, approxWeighting = val
92 undersampleStyle =
None
96 approxWeighting =
None
98 bgInfo = (bkgd, interpStyle, undersampleStyle, approxStyle,
99 approxOrderX, approxOrderY, approxWeighting)
103 """Return a shallow copy
105 Shallow copies do not share backgrounds that are appended after copying,
106 but do share changes to contained background objects.
111 """Save our list of Backgrounds to a file.
118 Flags to control details of writing; currently unused, but present
119 for consistency with `lsst.afw.table.BaseCatalog.writeFits`.
122 for i, bkgd
in enumerate(self):
123 (bkgd, interpStyle, undersampleStyle, approxStyle, approxOrderX, approxOrderY,
124 approxWeighting) = bkgd
126 statsImage = bkgd.getStatsImage()
129 md.set(
"INTERPSTYLE", int(interpStyle))
130 md.set(
"UNDERSAMPLESTYLE", int(undersampleStyle))
131 md.set(
"APPROXSTYLE", int(approxStyle))
132 md.set(
"APPROXORDERX", approxOrderX)
133 md.set(
"APPROXORDERY", approxOrderY)
134 md.set(
"APPROXWEIGHTING", approxWeighting)
135 bbox = bkgd.getImageBBox()
136 md.set(
"BKGD_X0", bbox.getMinX())
137 md.set(
"BKGD_Y0", bbox.getMinY())
138 md.set(
"BKGD_WIDTH", bbox.getWidth())
139 md.set(
"BKGD_HEIGHT", bbox.getHeight())
141 statsImage.getImage().
writeFits(fileName, md,
"w" if i == 0
else "a")
142 statsImage.getMask().
writeFits(fileName, md,
"a")
143 statsImage.getVariance().
writeFits(fileName, md,
"a")
147 """Read our list of Backgrounds from a file.
154 First Header/Data Unit to attempt to read from
156 Flags to control details of reading; currently unused, but present
157 for consistency with `lsst.afw.table.BaseCatalog.readFits`.
163 if not isinstance(fileName, MemFileManager)
and not os.path.exists(fileName):
164 raise RuntimeError(f
"File not found: {fileName}")
168 f =
Fits(fileName,
'r')
169 nHdus = f.countHdus()
172 raise RuntimeError(f
"BackgroundList FITS file {fileName} has {nHdus} HDUs;"
173 f
"expected a multiple of 3 (compression is not supported).")
175 for hdu
in range(0, nHdus, 3):
182 statsImage = afwImage.MaskedImageF(imageReader.read(), maskReader.read(), varianceReader.read())
183 md = imageReader.readMetadata()
187 width = md[
"BKGD_WIDTH"]
188 height = md[
"BKGD_HEIGHT"]
191 interpStyle = Interpolate.Style(md[
"INTERPSTYLE"])
198 approxStyle = md.get(
"APPROXSTYLE", ApproximateControl.UNKNOWN)
199 approxStyle = ApproximateControl.Style(approxStyle)
200 approxOrderX = md.get(
"APPROXORDERX", 1)
201 approxOrderY = md.get(
"APPROXORDERY", -1)
202 approxWeighting = md.get(
"APPROXWEIGHTING",
True)
204 bkgd = BackgroundMI(imageBBox, statsImage)
205 bctrl = bkgd.getBackgroundControl()
206 bctrl.setInterpStyle(interpStyle)
207 bctrl.setUndersampleStyle(undersampleStyle)
208 actrl = ApproximateControl(approxStyle, approxOrderX, approxOrderY, approxWeighting)
209 bctrl.setApproximateControl(actrl)
210 bgInfo = (bkgd, interpStyle, undersampleStyle, approxStyle,
211 approxOrderX, approxOrderY, approxWeighting)
217 """Compute and return a full-resolution image from our list of
218 (Background, interpStyle, undersampleStyle).
222 for (bkgd, interpStyle, undersampleStyle, approxStyle,
223 approxOrderX, approxOrderY, approxWeighting)
in self:
225 if approxStyle != ApproximateControl.UNKNOWN:
226 bkgdImage = bkgd.getImageF()
228 bkgdImage = bkgd.getImageF(interpStyle, undersampleStyle)
230 if approxStyle != ApproximateControl.UNKNOWN:
231 bkgdImage += bkgd.getImageF()
233 bkgdImage += bkgd.getImageF(interpStyle, undersampleStyle)
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
A FITS reader class for regular Images.
A FITS reader class for Masks.
def __getitem__(self, *args)
def readFits(fileName, hdu=0, flags=0)
def writeFits(self, fileName, flags=0)
def __init__(self, *args)
Class for storing ordered metadata with comments.
An integer coordinate rectangle.
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects.