Skip to content

Commit 237bf8d

Browse files
kelleCopilot
andauthored
upgrade to specutils>2.0 (#106)
* upgrade to specutils2.1 * fix docstring Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 24a4749 commit 237bf8d

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

astrodbkit/spectra.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from astropy.nddata import StdDevUncertainty
99
from astropy.units import Unit
1010
from astropy.wcs import WCS
11-
from specutils import Spectrum1D
11+
from specutils import Spectrum
1212
from specutils.io.parsing_utils import read_fileobj_or_hdulist
1313
from specutils.io.registers import data_loader
1414

@@ -45,9 +45,9 @@ def identify_spex_prism(origin, *args, **kwargs):
4545
return is_spex
4646

4747

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

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

7373
meta = {"header": header}
7474

75-
return Spectrum1D(flux=data, spectral_axis=wave, uncertainty=uncertainty, meta=meta)
75+
return Spectrum(flux=data, spectral_axis=wave, uncertainty=uncertainty, meta=meta)
7676

7777

7878
def identify_wcs1d_multispec(origin, *args, **kwargs):
@@ -92,7 +92,7 @@ def identify_wcs1d_multispec(origin, *args, **kwargs):
9292
)
9393

9494

95-
@data_loader("wcs1d-multispec", identifier=identify_wcs1d_multispec, extensions=["fits"], dtype=Spectrum1D, priority=10)
95+
@data_loader("wcs1d-multispec", identifier=identify_wcs1d_multispec, extensions=["fits"], dtype=Spectrum, priority=10)
9696
def wcs1d_multispec_loader(file_obj, flux_unit=None, hdu=0, verbose=False, **kwargs):
9797
"""
9898
Loader for multiextension spectra as wcs1d. Adapted from wcs1d_fits_loader
@@ -115,7 +115,7 @@ def wcs1d_multispec_loader(file_obj, flux_unit=None, hdu=0, verbose=False, **kwa
115115
116116
Returns
117117
-------
118-
:class:`~specutils.Spectrum1D`
118+
:class:`~specutils.Spectrum`
119119
"""
120120

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

181-
return Spectrum1D(flux=flux_data, spectral_axis=spectral_axis, uncertainty=uncertainty, meta=meta)
181+
return Spectrum(flux=flux_data, spectral_axis=spectral_axis, uncertainty=uncertainty, meta=meta)
182182

183183

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

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

astrodbkit/tests/test_spectra.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def test_wcs1d_multispec_loader(mock_fits_open, good_wcs1dmultispec, alt_wcs1dmu
142142
assert spectrum.wavelength.unit == Unit("Angstrom")
143143

144144

145-
@mock.patch("astrodbkit.spectra.Spectrum1D.read")
145+
@mock.patch("astrodbkit.spectra.Spectrum.read")
146146
def test_load_spectrum(mock_spectrum1d, monkeypatch):
147147
_ = load_spectrum("fake_file.txt")
148148
mock_spectrum1d.assert_called_with("fake_file.txt")

docs/index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ General Queries with Transformations
328328
------------------------------------
329329

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

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

344344
Spectra need to be specified as either URL or paths relative to an environment variable,

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ dependencies = [
2525
"sqlalchemy>=2.0.38",
2626
"pandas>=1.0.4",
2727
"packaging",
28-
"specutils>=1.0",
28+
"specutils>=2.0",
2929
"tqdm",
3030
]
3131

0 commit comments

Comments
 (0)