-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
11 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |