From 924193a53956f8a02e3f075351a9b6e523b13b3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agn=C3=A8s=20Fert=C3=A9?= Date: Thu, 1 Feb 2024 13:14:47 -0800 Subject: [PATCH] Change from fitsio to astropy. --- python/lsst/obs/fiberspectrograph/spectrum.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/python/lsst/obs/fiberspectrograph/spectrum.py b/python/lsst/obs/fiberspectrograph/spectrum.py index 4a99b84..58db9ee 100644 --- a/python/lsst/obs/fiberspectrograph/spectrum.py +++ b/python/lsst/obs/fiberspectrograph/spectrum.py @@ -23,7 +23,6 @@ import numpy as np import astropy.io.fits -import fitsio import astropy.units as u from ._instrument import FiberSpectrograph import lsst.afw.image as afwImage @@ -75,7 +74,7 @@ def getBBox(self): return self.detector.getBBox() @classmethod - def readFits(cls,path): + def readFits(cls, path): """Read a Spectrum from disk" Parameters @@ -88,11 +87,15 @@ def readFits(cls,path): spectrum : `~lsst.obs.fiberspectrograph.FiberSpectrum` In-memory spectrum. """ - md = dict(fitsio.read_header(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) + fitsfile = astropy.io.fits.open(path) + md = dict(fitsfile[0].header) + + if md["FORMAT_V"] >= 1: + flux = fitsfile[0].data + wavelength = fitsfile[md["PS1_0"]].data[md["PS1_1"]].flatten() + + wavelength = u.Quantity(wavelength, u.Unit(md["CUNIT1"]), copy=False) return cls(wavelength, flux, md)