143 def readFits(fileName, hdu=0, flags=0):
144 """Read our list of Backgrounds from a file.
145
146 Parameters
147 ----------
148 fileName : `str`
149 FITS file to read
150 hdu : `int`
151 First Header/Data Unit to attempt to read from
152 flags : `int`
153 Flags to control details of reading; currently unused, but present
154 for consistency with `lsst.afw.table.BaseCatalog.readFits`.
155
156 See Also
157 --------
158 getImage
159 """
160 if not isinstance(fileName, MemFileManager) and not os.path.exists(fileName):
161 raise RuntimeError(f"File not found: {fileName}")
162
163 self = BackgroundList()
164
165 f = Fits(fileName, 'r')
166 nHdus = f.countHdus()
167 f.closeFile()
168 if nHdus % 3 != 0:
169 raise RuntimeError(f"BackgroundList FITS file {fileName} has {nHdus} HDUs;"
170 f"expected a multiple of 3 (compression is not supported).")
171
172 for hdu in range(0, nHdus, 3):
173
174
175
179 statsImage = afwImage.MaskedImageF(imageReader.read(), maskReader.read(), varianceReader.read())
180 md = imageReader.readMetadata()
181
182 x0 = md["BKGD_X0"]
183 y0 = md["BKGD_Y0"]
184 width = md["BKGD_WIDTH"]
185 height = md["BKGD_HEIGHT"]
187
188 interpStyle = Interpolate.Style(md["INTERPSTYLE"])
189 undersampleStyle = UndersampleStyle(md["UNDERSAMPLESTYLE"])
190
191
192
193
194
195 approxStyle = md.get("APPROXSTYLE", ApproximateControl.UNKNOWN)
196 approxStyle = ApproximateControl.Style(approxStyle)
197 approxOrderX = md.get("APPROXORDERX", 1)
198 approxOrderY = md.get("APPROXORDERY", -1)
199 approxWeighting = md.get("APPROXWEIGHTING", True)
200
201 bkgd = BackgroundMI(imageBBox, statsImage)
202 bctrl = bkgd.getBackgroundControl()
203 bctrl.setInterpStyle(interpStyle)
204 bctrl.setUndersampleStyle(undersampleStyle)
205 actrl = ApproximateControl(approxStyle, approxOrderX, approxOrderY, approxWeighting)
206 bctrl.setApproximateControl(actrl)
207 bgInfo = (bkgd, interpStyle, undersampleStyle, approxStyle,
208 approxOrderX, approxOrderY, approxWeighting)
209 self.append(bgInfo)
210
211 return self
212
A FITS reader class for regular Images.
A FITS reader class for Masks.
An integer coordinate rectangle.