Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions astrodbkit/spectra.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from astropy.nddata import StdDevUncertainty
from astropy.units import Unit
from astropy.wcs import WCS
from specutils import Spectrum1D
from specutils import Spectrum
from specutils.io.parsing_utils import read_fileobj_or_hdulist
from specutils.io.registers import data_loader

Expand Down Expand Up @@ -45,9 +45,9 @@ def identify_spex_prism(origin, *args, **kwargs):
return is_spex


@data_loader("Spex Prism", identifier=identify_spex_prism, extensions=["fits"], dtype=Spectrum1D)
@data_loader("Spex Prism", identifier=identify_spex_prism, extensions=["fits"], dtype=Spectrum)
def spex_prism_loader(filename, **kwargs):
"""Open a SpeX Prism file and convert it to a Spectrum1D object"""
"""Open a SpeX Prism file and convert it to a Spectrum object"""

with fits.open(filename, **kwargs) as hdulist:
header = hdulist[0].header
Expand All @@ -72,7 +72,7 @@ def spex_prism_loader(filename, **kwargs):

meta = {"header": header}

return Spectrum1D(flux=data, spectral_axis=wave, uncertainty=uncertainty, meta=meta)
return Spectrum(flux=data, spectral_axis=wave, uncertainty=uncertainty, meta=meta)


def identify_wcs1d_multispec(origin, *args, **kwargs):
Expand All @@ -92,7 +92,7 @@ def identify_wcs1d_multispec(origin, *args, **kwargs):
)


@data_loader("wcs1d-multispec", identifier=identify_wcs1d_multispec, extensions=["fits"], dtype=Spectrum1D, priority=10)
@data_loader("wcs1d-multispec", identifier=identify_wcs1d_multispec, extensions=["fits"], dtype=Spectrum, priority=10)
def wcs1d_multispec_loader(file_obj, flux_unit=None, hdu=0, verbose=False, **kwargs):
"""
Loader for multiextension spectra as wcs1d. Adapted from wcs1d_fits_loader
Expand All @@ -115,7 +115,7 @@ def wcs1d_multispec_loader(file_obj, flux_unit=None, hdu=0, verbose=False, **kwa

Returns
-------
:class:`~specutils.Spectrum1D`
:class:`~specutils.Spectrum`
"""

with read_fileobj_or_hdulist(file_obj, **kwargs) as hdulist:
Expand Down Expand Up @@ -178,7 +178,7 @@ def wcs1d_multispec_loader(file_obj, flux_unit=None, hdu=0, verbose=False, **kwa
# Store header as metadata information
meta = {"header": header}

return Spectrum1D(flux=flux_data, spectral_axis=spectral_axis, uncertainty=uncertainty, meta=meta)
return Spectrum(flux=flux_data, spectral_axis=spectral_axis, uncertainty=uncertainty, meta=meta)


def load_spectrum(filename: str, spectra_format: str = None, raise_error: bool = False):
Expand All @@ -189,8 +189,8 @@ def load_spectrum(filename: str, spectra_format: str = None, raise_error: bool =
filename
Name of the file to read
spectra_format
Optional file format, passed to Spectrum1D.read.
In its absense Spectrum1D.read will attempt to determine the format.
Optional file format, passed to Spectrum.read.
In its absense Spectrum.read will attempt to determine the format.
raise_error
Boolean to control if a failure to read the spectrum should raise an error.
"""
Expand All @@ -208,9 +208,9 @@ def load_spectrum(filename: str, spectra_format: str = None, raise_error: bool =

try:
if spectra_format is not None:
spec1d = Spectrum1D.read(filename, format=spectra_format)
spec1d = Spectrum.read(filename, format=spectra_format)
else:
spec1d = Spectrum1D.read(filename)
spec1d = Spectrum.read(filename)
except Exception as e: # pylint: disable=broad-except, invalid-name
msg = f"Error loading {filename}: {e}"

Expand Down
2 changes: 1 addition & 1 deletion astrodbkit/tests/test_spectra.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def test_wcs1d_multispec_loader(mock_fits_open, good_wcs1dmultispec, alt_wcs1dmu
assert spectrum.wavelength.unit == Unit("Angstrom")


@mock.patch("astrodbkit.spectra.Spectrum1D.read")
@mock.patch("astrodbkit.spectra.Spectrum.read")
def test_load_spectrum(mock_spectrum1d, monkeypatch):
_ = load_spectrum("fake_file.txt")
mock_spectrum1d.assert_called_with("fake_file.txt")
Expand Down
4 changes: 2 additions & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ General Queries with Transformations
------------------------------------

**AstrodbKit** can convert columns to special types.
Currently, spectra transformations are implemented and the specified column would be converted to a `Spectrum1D` object
Currently, spectra transformations are implemented and the specified column would be converted to a `Spectrum` object
using the `specutils package <https://specutils.readthedocs.io/en/stable/>`_.
To call this, users can supply the name of the column to convert
(by default, none is converted, though .spectra assumes the column name is *spectrum*)::
Expand All @@ -338,7 +338,7 @@ To call this, users can supply the name of the column to convert
db.query(db.Spectra).spectra(fmt='astropy')

These three calls will return results from the Spectra table and will attempt to convert the *spectrum*
column to a Spectrum1D object for each row. Multiple columns to convert can also be passed as a list.
column to a Spectrum object for each row. Multiple columns to convert can also be passed as a list.
The parameter `spectra_format` can be specified if **specutils** is having trouble determining the type of spectrum.

Spectra need to be specified as either URL or paths relative to an environment variable,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ dependencies = [
"sqlalchemy>=2.0.38",
"pandas>=1.0.4",
"packaging",
"specutils>=1.0",
"specutils>=2.0",
"tqdm",
]

Expand Down