1 from __future__
import absolute_import, division, print_function
2 from builtins
import object
28 from lsst.afw.fits import FitsError, MemFileManager, reduceToFits, Fits
29 from .
import mathLib
as afwMath
33 """A list-like class to contain a list of (afwMath.Background, interpStyle, undersampleStyle) tuples 35 In deference to the deprecated-but-not-yet-removed Background.getImage() API, we also accept a single 36 afwMath.Background and extract the interpStyle and undersampleStyle from the as-used values 50 bkgd, interpStyle, undersampleStyle, approxStyle, \
51 approxOrderX, approxOrderY, approxWeighting = val
52 if interpStyle
is None or undersampleStyle
is None:
53 interpStyle = bkgd.getAsUsedInterpStyle()
54 undersampleStyle = bkgd.getAsUsedUndersampleStyle()
55 actrl = bkgd.getBackgroundControl().getApproximateControl()
56 approxStyle = actrl.getStyle()
57 approxOrderX = actrl.getOrderX()
58 approxOrderY = actrl.getOrderY()
59 approxWeighting = actrl.getWeighting()
60 self.
_backgrounds[i] = (bkgd, interpStyle, undersampleStyle,
61 approxStyle, approxOrderX, approxOrderY, approxWeighting)
72 bkgd, interpStyle, undersampleStyle, approxStyle, \
73 approxOrderX, approxOrderY, approxWeighting = val
77 undersampleStyle =
None 81 approxWeighting =
None 83 bgInfo = (bkgd, interpStyle, undersampleStyle, approxStyle,
84 approxOrderX, approxOrderY, approxWeighting)
88 """Return a shallow copy 90 Shallow copies do not share backgrounds that are appended after copying, 91 but do share changes to contained background objects. 96 """Save our list of Backgrounds to a file 97 @param fileName FITS file to write 98 @param flags Flags to control details of writing; currently unused, 99 but present for consistency with 100 afw.table.BaseCatalog.writeFits. 103 for i, bkgd
in enumerate(self):
104 (bkgd, interpStyle, undersampleStyle, approxStyle, approxOrderX, approxOrderY,
105 approxWeighting) = bkgd
107 statsImage = bkgd.getStatsImage()
109 md = dafBase.PropertyList()
110 md.set(
"INTERPSTYLE", int(interpStyle))
111 md.set(
"UNDERSAMPLESTYLE", int(undersampleStyle))
112 md.set(
"APPROXSTYLE", int(approxStyle))
113 md.set(
"APPROXORDERX", approxOrderX)
114 md.set(
"APPROXORDERY", approxOrderY)
115 md.set(
"APPROXWEIGHTING", approxWeighting)
116 bbox = bkgd.getImageBBox()
117 md.set(
"BKGD_X0", bbox.getMinX())
118 md.set(
"BKGD_Y0", bbox.getMinY())
119 md.set(
"BKGD_WIDTH", bbox.getWidth())
120 md.set(
"BKGD_HEIGHT", bbox.getHeight())
122 statsImage.getImage().
writeFits(fileName, md,
"w" if i == 0
else "a")
123 statsImage.getMask().
writeFits(fileName, md,
"a")
124 statsImage.getVariance().
writeFits(fileName, md,
"a")
128 """Read a our list of Backgrounds from a file 129 @param fileName FITS file to read 130 @param hdu First Header/Data Unit to attempt to read from 131 @param flags Flags to control details of reading; currently unused, 132 but present for consistency with 133 afw.table.BaseCatalog.readFits. 137 if not isinstance(fileName, MemFileManager)
and not os.path.exists(fileName):
138 raise RuntimeError(
"File not found: %s" % fileName)
149 fits =
Fits(fileName,
"r") 151 if fits.checkCompressedImagePhu():
157 md = dafBase.PropertyList()
159 img = afwImage.ImageF(fileName, hdu, md)
166 var = afwImage.ImageF(fileName, hdu)
170 x0 = md.get(
"BKGD_X0")
171 y0 = md.get(
"BKGD_Y0")
172 width = md.get(
"BKGD_WIDTH")
173 height = md.get(
"BKGD_HEIGHT")
177 interpStyle = afwMath.Interpolate.Style(md.get(
"INTERPSTYLE"))
179 md.get(
"UNDERSAMPLESTYLE"))
185 approxStyle = md.get(
"APPROXSTYLE")
if "APPROXSTYLE" in md.names() \
186 else afwMath.ApproximateControl.UNKNOWN
187 approxStyle = afwMath.ApproximateControl.Style(approxStyle)
188 approxOrderX = md.get(
189 "APPROXORDERX")
if "APPROXORDERX" in md.names()
else 1
190 approxOrderY = md.get(
191 "APPROXORDERY")
if "APPROXORDERY" in md.names()
else -1
192 approxWeighting = md.get(
193 "APPROXWEIGHTING")
if "APPROXWEIGHTING" in md.names()
else True 196 bctrl = bkgd.getBackgroundControl()
197 bctrl.setInterpStyle(interpStyle)
198 bctrl.setUndersampleStyle(undersampleStyle)
200 approxStyle, approxOrderX, approxOrderY, approxWeighting)
201 bctrl.setApproximateControl(actrl)
202 bgInfo = (bkgd, interpStyle, undersampleStyle, approxStyle,
203 approxOrderX, approxOrderY, approxWeighting)
210 Compute and return a full-resolution image from our list of 211 (Background, interpStyle, undersampleStyle) 215 for (bkgd, interpStyle, undersampleStyle, approxStyle,
216 approxOrderX, approxOrderY, approxWeighting)
in self:
218 if approxStyle != afwMath.ApproximateControl.UNKNOWN:
219 bkgdImage = bkgd.getImageF()
221 bkgdImage = bkgd.getImageF(interpStyle, undersampleStyle)
223 if approxStyle != afwMath.ApproximateControl.UNKNOWN:
224 bkgdImage += bkgd.getImageF()
226 bkgdImage += bkgd.getImageF(interpStyle, undersampleStyle)
def __getitem__(self, args)
def writeFits(self, fileName, flags=0)
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.
An integer coordinate rectangle.
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.