22 __all__ = [
"BackgroundList"]
28 from lsst.afw.fits import FitsError, MemFileManager, reduceToFits, Fits, DEFAULT_HDU
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 if hdu == DEFAULT_HDU:
173 fits =
Fits(fileName,
"r") 175 if fits.checkCompressedImagePhu():
183 img = afwImage.ImageF(fileName, hdu, md)
190 var = afwImage.ImageF(fileName, hdu)
194 x0 = md.getScalar(
"BKGD_X0")
195 y0 = md.getScalar(
"BKGD_Y0")
196 width = md.getScalar(
"BKGD_WIDTH")
197 height = md.getScalar(
"BKGD_HEIGHT")
201 interpStyle = afwMath.Interpolate.Style(md.getScalar(
"INTERPSTYLE"))
203 md.getScalar(
"UNDERSAMPLESTYLE"))
209 approxStyle = md.getScalar(
"APPROXSTYLE")
if "APPROXSTYLE" in md.names() \
210 else afwMath.ApproximateControl.UNKNOWN
211 approxStyle = afwMath.ApproximateControl.Style(approxStyle)
212 approxOrderX = md.getScalar(
213 "APPROXORDERX")
if "APPROXORDERX" in md.names()
else 1
214 approxOrderY = md.getScalar(
215 "APPROXORDERY")
if "APPROXORDERY" in md.names()
else -1
216 approxWeighting = md.getScalar(
217 "APPROXWEIGHTING")
if "APPROXWEIGHTING" in md.names()
else True 220 bctrl = bkgd.getBackgroundControl()
221 bctrl.setInterpStyle(interpStyle)
222 bctrl.setUndersampleStyle(undersampleStyle)
224 approxStyle, approxOrderX, approxOrderY, approxWeighting)
225 bctrl.setApproximateControl(actrl)
226 bgInfo = (bkgd, interpStyle, undersampleStyle, approxStyle,
227 approxOrderX, approxOrderY, approxWeighting)
233 """Compute and return a full-resolution image from our list of 234 (Background, interpStyle, undersampleStyle). 238 for (bkgd, interpStyle, undersampleStyle, approxStyle,
239 approxOrderX, approxOrderY, approxWeighting)
in self:
241 if approxStyle != afwMath.ApproximateControl.UNKNOWN:
242 bkgdImage = bkgd.getImageF()
244 bkgdImage = bkgd.getImageF(interpStyle, undersampleStyle)
246 if approxStyle != afwMath.ApproximateControl.UNKNOWN:
247 bkgdImage += bkgd.getImageF()
249 bkgdImage += bkgd.getImageF(interpStyle, undersampleStyle)
def __getitem__(self, args)
def writeFits(self, fileName, flags=0)
Class for storing ordered metadata with comments.
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
MaskedImage< ImagePixelT, MaskPixelT, VariancePixelT > * makeMaskedImage(typename std::shared_ptr< Image< ImagePixelT >> image, typename std::shared_ptr< Mask< MaskPixelT >> mask=Mask< MaskPixelT >(), typename std::shared_ptr< Image< VariancePixelT >> variance=Image< VariancePixelT >())
A function to return a MaskedImage of the correct type (cf.
Control how to make an approximation.
Represent a 2-dimensional array of bitmask pixels.
def readFits(fileName, hdu=0, flags=0)
A class to evaluate image background levels.
An integer coordinate rectangle.