Skip to content

Commit

Permalink
Change from fitsio to astropy.
Browse files Browse the repository at this point in the history
  • Loading branch information
aferte committed Feb 1, 2024
1 parent 24106db commit 924193a
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions python/lsst/obs/fiberspectrograph/spectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)

Expand Down

0 comments on commit 924193a

Please sign in to comment.