268 def factory(cls, stamp_im, metadata, index, archive_element=None):
269 """This method is needed to service the FITS reader. We need a standard
270 interface to construct objects like this. Parameters needed to
271 construct this object are passed in via a metadata dictionary and then
272 passed to the constructor of this class. If lists of values are passed
273 with the following keys, they will be passed to the constructor,
274 otherwise dummy values will be passed: RA_DEG, DEC_DEG. They should
275 each point to lists of values.
276
277 Parameters
278 ----------
279 stamp : `~lsst.afw.image.MaskedImage`
280 Pixel data to pass to the constructor
281 metadata : `dict`
282 Dictionary containing the information
283 needed by the constructor.
284 idx : `int`
285 Index into the lists in ``metadata``
286 archive_element : `~lsst.afw.table.io.Persistable`, optional
287 Archive element (e.g. Transform or WCS) associated with this stamp.
288
289 Returns
290 -------
291 stamp : `Stamp`
292 An instance of this class
293 """
294 if "RA_DEG" in metadata and "DEC_DEG" in metadata:
295 return cls(
296 stamp_im=stamp_im,
297 archive_element=archive_element,
298 position=SpherePoint(
299 Angle(metadata.getArray("RA_DEG")[index], degrees),
300 Angle(metadata.getArray("DEC_DEG")[index], degrees),
301 ),
302 )
303 else:
304 return cls(
305 stamp_im=stamp_im,
306 archive_element=archive_element,
307 position=SpherePoint(Angle(np.nan), Angle(np.nan)),
308 )
309
310