From 24106dbd970b85c79540e68eed05654c154d8f10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agn=C3=A8s=20Fert=C3=A9?= Date: Thu, 1 Feb 2024 13:14:11 -0800 Subject: [PATCH] Formatter with consistent methods. --- .../obs/fiberspectrograph/rawFormatter.py | 31 +++++++------------ 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/python/lsst/obs/fiberspectrograph/rawFormatter.py b/python/lsst/obs/fiberspectrograph/rawFormatter.py index e6383a3..17a27e7 100644 --- a/python/lsst/obs/fiberspectrograph/rawFormatter.py +++ b/python/lsst/obs/fiberspectrograph/rawFormatter.py @@ -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)