1 from __future__
import absolute_import, division, print_function
2 from builtins
import object
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 (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()
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)
142 if hdu == DEFAULT_HDU:
148 fits =
Fits(fileName,
"r") 150 if fits.checkCompressedImagePhu():
158 img = afwImage.ImageF(fileName, hdu, md)
165 var = afwImage.ImageF(fileName, hdu)
169 x0 = md.get(
"BKGD_X0")
170 y0 = md.get(
"BKGD_Y0")
171 width = md.get(
"BKGD_WIDTH")
172 height = md.get(
"BKGD_HEIGHT")
176 interpStyle = afwMath.Interpolate.Style(md.get(
"INTERPSTYLE"))
178 md.get(
"UNDERSAMPLESTYLE"))
184 approxStyle = md.get(
"APPROXSTYLE")
if "APPROXSTYLE" in md.names() \
185 else afwMath.ApproximateControl.UNKNOWN
186 approxStyle = afwMath.ApproximateControl.Style(approxStyle)
187 approxOrderX = md.get(
188 "APPROXORDERX")
if "APPROXORDERX" in md.names()
else 1
189 approxOrderY = md.get(
190 "APPROXORDERY")
if "APPROXORDERY" in md.names()
else -1
191 approxWeighting = md.get(
192 "APPROXWEIGHTING")
if "APPROXWEIGHTING" in md.names()
else True 195 bctrl = bkgd.getBackgroundControl()
196 bctrl.setInterpStyle(interpStyle)
197 bctrl.setUndersampleStyle(undersampleStyle)
199 approxStyle, approxOrderX, approxOrderY, approxWeighting)
200 bctrl.setApproximateControl(actrl)
201 bgInfo = (bkgd, interpStyle, undersampleStyle, approxStyle,
202 approxOrderX, approxOrderY, approxWeighting)
209 Compute and return a full-resolution image from our list of 210 (Background, interpStyle, undersampleStyle) 214 for (bkgd, interpStyle, undersampleStyle, approxStyle,
215 approxOrderX, approxOrderY, approxWeighting)
in self:
217 if approxStyle != afwMath.ApproximateControl.UNKNOWN:
218 bkgdImage = bkgd.getImageF()
220 bkgdImage = bkgd.getImageF(interpStyle, undersampleStyle)
222 if approxStyle != afwMath.ApproximateControl.UNKNOWN:
223 bkgdImage += bkgd.getImageF()
225 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.