Coverage for python/pfs/datamodel/target.py : 26%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
"""A spectroscopic target
Parameters ---------- catId : `int` Catalog identifier of the object. tract : `int` Tract in which the object resides. patch : `str` Patch in which the object resides. objId : `objId` Object identifier of the object. ra : `float`, optional Right Ascension of the object. dec : `float`, optional Declination of the object. targetType : `TargetType`, optional Type of target (typically ``SCIENCE``). fiberFlux : `dict` mapping `str` to `float`, optional Filter names and corresponding fiber fluxes. """ """Attributes to read from FITS header (iterable of `str`)"""
self.catId = catId self.tract = tract self.patch = patch self.objId = objId self.ra = ra self.dec = dec self.targetType = targetType self.fiberFlux = fiberFlux if fiberFlux is not None else {} self.identity = dict(catId=catId, tract=tract, patch=patch, objId=objId)
"""Stringify""" return "catId=%d tract=%d patch=%s objId=%d" % (self.catId, self.tract, self.patch, self.objId)
def fromFits(cls, fits): """Construct from a FITS file
Parameters ---------- fits : `astropy.io.fits.HDUList` Opened FITS file.
Returns ------- self : `Target` Constructed `Target`. """ hdu = fits["TARGET"] header = astropyHeaderToDict(hdu.header) kwargs = {} for attr in cls._attributes: kwargs[attr] = header[attr.upper()] kwargs["fiberFlux"] = dict(zip(hdu.data["filterName"], hdu.data["fiberFlux"])) return cls(**kwargs)
"""Write to a FITS file
Parameters ---------- fits : `astropy.io.fits.HDUList` Opened FITS file. """ from astropy.io.fits import BinTableHDU, Column maxLength = max(len(ff) for ff in self.fiberFlux.keys()) if self.fiberFlux else 1 header = astropyHeaderFromDict({attr.upper(): getattr(self, attr) for attr in self._attributes}) header.update(TargetType.getFitsHeaders()) hdu = BinTableHDU.from_columns([ Column("filterName", "%dA" % maxLength, array=list(self.fiberFlux.keys())), Column("fiberFlux", "E", array=np.array(list(self.fiberFlux.values()))), ], header=header, name="TARGET") fits.append(hdu)
return hash((self.catId, self.tract, self.patch, self.objId))
def fromPfsConfig(cls, pfsConfig, index): """Construct from a PfsConfig
Parameters ---------- pfsConfig : `pfs.datamodel.PfsConfig` Top-end configuration. index : `int` Index into the ``pfsConfig`` arrays for the target of interest.
Returns ------- self : cls Constructed `Target`. """ catId = pfsConfig.catId[index] tract = pfsConfig.tract[index] patch = pfsConfig.patch[index] objId = pfsConfig.objId[index] ra = pfsConfig.ra[index] dec = pfsConfig.dec[index] fiberFlux = dict(zip(pfsConfig.filterNames[index], pfsConfig.fiberFlux[index])) targetType = pfsConfig.targetType[index] return cls(catId, tract, patch, objId, ra, dec, targetType, fiberFlux)
"""How to pickle""" return type(self), (self.catId, self.tract, self.patch, self.objId, self.ra, self.dec, self.targetType, self.fiberFlux) |