Skip to content

Commit

Permalink
Formatter with consistent methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
aferte committed Feb 1, 2024
1 parent 00b1681 commit 24106db
Showing 1 changed file with 11 additions and 20 deletions.
31 changes: 11 additions & 20 deletions python/lsst/obs/fiberspectrograph/rawFormatter.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,34 @@
__all__ = []

from lsst.obs.base import FitsRawFormatterBase
from lsst.daf.butler import Formatter
from .filters import FIBER_SPECTROGRAPH_FILTER_DEFINITIONS
from ._instrument import FiberSpectrograph
from .translator import FiberSpectrographTranslator
import fitsio
import astropy.units as u
from lsst.daf.base import PropertyList
from .spectrum import FiberSpectrum


class FiberSpectrographRawFormatter(FitsRawFormatterBase):
class FiberSpectrographRawFormatter(Formatter):
cameraClass = FiberSpectrograph
translatorClass = FiberSpectrographTranslator
fiberSpectrumClass = FiberSpectrum
filterDefinitions = FIBER_SPECTROGRAPH_FILTER_DEFINITIONS

def getDetector(self, id):
return self.cameraClass().getCamera()[id]

def read(self, component=None):
"""Read just the image component of the Exposure.
"""Read fiberspectrograph data.
Returns
-------
image : `~lsst.afw.image.Image`
In-memory image component.
image : `~lsst.obs.fiberspectrograph.FiberSpectrum`
In-memory spectrum.
"""
pytype = self.fileDescriptor.storageClass.pytype
path = self.fileDescriptor.location.path

sourceMd = dict(fitsio.read_header(path))
md = PropertyList()
md.update(sourceMd)
if component is not None:
if component == 'metadata':
return md
return self.fiberSpectrumClass.readFits(path)

flux = fitsio.read(path)
wavelength = fitsio.read(path, ext=md["PS1_0"], columns=md["PS1_1"]).flatten()

wavelength = u.Quantity(wavelength, u.Unit(md["CUNIT1"]), copy=False)
def write(self):
path = self.fileDescriptor.location.path

return pytype(wavelength, flux, md)
return self.fiberSpectrumClass.writeFits(path)

0 comments on commit 24106db

Please sign in to comment.