26 from lsst.afw.fits import FitsError, MemFileManager, reduceToFits, Fits, DEFAULT_HDU
27 from .
import mathLib
as afwMath
31 """A list-like class to contain a list of (afwMath.Background, interpStyle, undersampleStyle) tuples 33 In deference to the deprecated-but-not-yet-removed Background.getImage() API, we also accept a single 34 afwMath.Background and extract the interpStyle and undersampleStyle from the as-used values 48 bkgd, interpStyle, undersampleStyle, approxStyle, \
49 approxOrderX, approxOrderY, approxWeighting = val
50 if interpStyle
is None or undersampleStyle
is None:
51 interpStyle = bkgd.getAsUsedInterpStyle()
52 undersampleStyle = bkgd.getAsUsedUndersampleStyle()
53 actrl = bkgd.getBackgroundControl().getApproximateControl()
54 approxStyle = actrl.getStyle()
55 approxOrderX = actrl.getOrderX()
56 approxOrderY = actrl.getOrderY()
57 approxWeighting = actrl.getWeighting()
58 self.
_backgrounds[i] = (bkgd, interpStyle, undersampleStyle,
59 approxStyle, approxOrderX, approxOrderY, approxWeighting)
70 bkgd, interpStyle, undersampleStyle, approxStyle, \
71 approxOrderX, approxOrderY, approxWeighting = val
75 undersampleStyle =
None 79 approxWeighting =
None 81 bgInfo = (bkgd, interpStyle, undersampleStyle, approxStyle,
82 approxOrderX, approxOrderY, approxWeighting)
86 """Return a shallow copy 88 Shallow copies do not share backgrounds that are appended after copying, 89 but do share changes to contained background objects. 94 """Save our list of Backgrounds to a file 95 @param fileName FITS file to write 96 @param flags Flags to control details of writing; currently unused, 97 but present for consistency with 98 afw.table.BaseCatalog.writeFits. 101 for i, bkgd
in enumerate(self):
102 (bkgd, interpStyle, undersampleStyle, approxStyle, approxOrderX, approxOrderY,
103 approxWeighting) = bkgd
105 statsImage = bkgd.getStatsImage()
108 md.set(
"INTERPSTYLE",
int(interpStyle))
109 md.set(
"UNDERSAMPLESTYLE",
int(undersampleStyle))
110 md.set(
"APPROXSTYLE",
int(approxStyle))
111 md.set(
"APPROXORDERX", approxOrderX)
112 md.set(
"APPROXORDERY", approxOrderY)
113 md.set(
"APPROXWEIGHTING", approxWeighting)
114 bbox = bkgd.getImageBBox()
115 md.set(
"BKGD_X0", bbox.getMinX())
116 md.set(
"BKGD_Y0", bbox.getMinY())
117 md.set(
"BKGD_WIDTH", bbox.getWidth())
118 md.set(
"BKGD_HEIGHT", bbox.getHeight())
120 statsImage.getImage().
writeFits(fileName, md,
"w" if i == 0
else "a")
121 statsImage.getMask().
writeFits(fileName, md,
"a")
122 statsImage.getVariance().
writeFits(fileName, md,
"a")
126 """Read a our list of Backgrounds from a file 127 @param fileName FITS file to read 128 @param hdu First Header/Data Unit to attempt to read from 129 @param flags Flags to control details of reading; currently unused, 130 but present for consistency with 131 afw.table.BaseCatalog.readFits. 135 if not isinstance(fileName, MemFileManager)
and not os.path.exists(fileName):
136 raise RuntimeError(
"File not found: %s" % fileName)
140 if hdu == DEFAULT_HDU:
146 fits =
Fits(fileName,
"r") 148 if fits.checkCompressedImagePhu():
156 img = afwImage.ImageF(fileName, hdu, md)
163 var = afwImage.ImageF(fileName, hdu)
167 x0 = md.getScalar(
"BKGD_X0")
168 y0 = md.getScalar(
"BKGD_Y0")
169 width = md.getScalar(
"BKGD_WIDTH")
170 height = md.getScalar(
"BKGD_HEIGHT")
174 interpStyle = afwMath.Interpolate.Style(md.getScalar(
"INTERPSTYLE"))
176 md.getScalar(
"UNDERSAMPLESTYLE"))
182 approxStyle = md.getScalar(
"APPROXSTYLE")
if "APPROXSTYLE" in md.names() \
183 else afwMath.ApproximateControl.UNKNOWN
184 approxStyle = afwMath.ApproximateControl.Style(approxStyle)
185 approxOrderX = md.getScalar(
186 "APPROXORDERX")
if "APPROXORDERX" in md.names()
else 1
187 approxOrderY = md.getScalar(
188 "APPROXORDERY")
if "APPROXORDERY" in md.names()
else -1
189 approxWeighting = md.getScalar(
190 "APPROXWEIGHTING")
if "APPROXWEIGHTING" in md.names()
else True 193 bctrl = bkgd.getBackgroundControl()
194 bctrl.setInterpStyle(interpStyle)
195 bctrl.setUndersampleStyle(undersampleStyle)
197 approxStyle, approxOrderX, approxOrderY, approxWeighting)
198 bctrl.setApproximateControl(actrl)
199 bgInfo = (bkgd, interpStyle, undersampleStyle, approxStyle,
200 approxOrderX, approxOrderY, approxWeighting)
207 Compute and return a full-resolution image from our list of 208 (Background, interpStyle, undersampleStyle) 212 for (bkgd, interpStyle, undersampleStyle, approxStyle,
213 approxOrderX, approxOrderY, approxWeighting)
in self:
215 if approxStyle != afwMath.ApproximateControl.UNKNOWN:
216 bkgdImage = bkgd.getImageF()
218 bkgdImage = bkgd.getImageF(interpStyle, undersampleStyle)
220 if approxStyle != afwMath.ApproximateControl.UNKNOWN:
221 bkgdImage += bkgd.getImageF()
223 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.