Skip to content

Commit b0f657c

Browse files
authored
Merge pull request #299 from hpparvi/specutils2
Dropping Specutils v1 support.
2 parents aa12957 + 08d5a66 commit b0f657c

23 files changed

+47
-90
lines changed

docs/conf.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,6 @@
208208
nitpick_ignore = [
209209
("py:class", "ArrayLike"),
210210
("py:class", "numpy._typing.ArrayLike"),
211-
("py:class", "specutils.spectra.spectrum1d.Spectrum1D"),
212211
]
213212

214213
# Ignore complex type annotations that can't be cross-referenced

docs/specphot_standards.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Introduction
88

99
Instrument sensitivity as a function of wavelength is calibrated using observations of
1010
spectrophotometric standard stars. `specreduce <https://specreduce.readthedocs.io/en/stable/index.html>`_ offers some
11-
convenience functions for accessing some databases of commonly used standard stars and loading the data into `~specutils.Spectrum1D`
11+
convenience functions for accessing some databases of commonly used standard stars and loading the data into `~specutils.Spectrum`
1212
instances.
1313

1414
Supported Databases
@@ -43,7 +43,7 @@ The bulk of them are inherited from IRAF's `onedstds <https://github.com/iraf-co
4343
some more recently curated datasets from `ESO <https://www.eso.org/sci/observing/tools/standards/spectra/stanlis.html>`_, the
4444
`Nearby Supernova Factory <https://snfactory.lbl.gov/>`_, and `Gemini
4545
<https://github.com/GeminiDRSoftware/DRAGONS/tree/master/geminidr/gemini/lookups/spectrophotometric_standards>`_ are included as well. The
46-
`~specreduce.calibration_data.load_onedstds` function is provided to load these data into `~specutils.Spectrum1D`
46+
`~specreduce.calibration_data.load_onedstds` function is provided to load these data into `~specutils.Spectrum`
4747
instances. If `specreduce_data <https://github.com/astropy/specreduce-data/>`_ is not installed, the data will be downloaded from the GitHub
4848
`repository <https://github.com/astropy/specreduce-data/tree/main/specreduce_data/reference_data/onedstds>`_. The available
4949
database names and their descriptions are listed here. Please refer to the `specreduce-data repository

docs/terms.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ Extraction
6565
==========
6666

6767
- The process of converting raw spectrum data on 2D image into flux versus
68-
spectral axis or pixel (i.e. Spectrum1D), not necessarily flux or spectral
68+
spectral axis or pixel (i.e. Spectrum), not necessarily flux or spectral
6969
calibration.
7070

7171
Rectified ND spectrum
@@ -227,8 +227,8 @@ MOS (Multi-Object Spectroscopy)
227227
- Also used as a shorthand for “the not spectral unit part of a 1D spectrum”
228228
(would that be the “dependent variable”?)
229229
- Oftentimes used to mean “flux density”
230-
- `Spectrum1D
231-
<https://specutils.readthedocs.io/en/stable/api/specutils.Spectrum1D.html#specutils.Spectrum1D>`__
230+
- `Spectrum
231+
<https://specutils.readthedocs.io/en/stable/api/specutils.Spectrum.html#specutils.Spectrum>`__
232232
uses the attribute 'flux'. Should this be renamed to 'flux_density'?
233233

234234
- The intent in specutils was to not agonize over this but just accept that
@@ -246,7 +246,7 @@ Flux Density
246246

247247
- Collection of 1D spectra in a 2D array (image?), one spectrum per row.
248248
- Shared spectral axis.
249-
- This is the format of specutils.Spectrum1D when it's a “vector” spectrum1D
249+
- This is the format of specutils.Spectrum when it's a “vector” spectrum1D
250250

251251
*Data cube*
252252
===========
@@ -280,12 +280,12 @@ Data Structures
280280

281281
- Python Data structures, which are Python classes.
282282

283-
- NDData/NDCube/SpectrumCollection, Spectrum1D etc.
283+
- NDData/NDCube/SpectrumCollection, Spectrum etc.
284284
- CCDData. Subclass of NDData
285285
- AstroData - from DRAGONS (collection of NDData-like objects, mapped to a
286286
file, plus metadata abstraction etc.)
287287
- Lots of classes to represent spectra
288-
- Link to issue about renaming Spectrum1D class in specutils.
288+
- Link to issue about renaming Spectrum class in specutils.
289289
- arrays
290290

291291
*Data Model*
@@ -439,7 +439,7 @@ API
439439
*Spectral class*
440440
================
441441

442-
- E.g., Spectrum1D
442+
- E.g., Spectrum
443443
- In SDSS, 'class' is short for 'classification'.
444444
- DESI uses SPECTYPE for spectral type (QSO, GALAXY, STAR)
445445

pyproject.toml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ readme = "README.rst"
1010
requires-python = ">=3.11"
1111
dependencies = [
1212
"numpy>=1.24",
13-
"astropy>=5.3",
14-
"scipy>=1.10",
15-
"specutils>=1.9.1",
13+
"astropy>=6.0",
14+
"scipy>=1.14",
15+
"specutils>=2.0",
1616
"matplotlib>=3.10",
1717
"gwcs",
1818
]
@@ -28,13 +28,13 @@ docs = [
2828
"sphinx-copybutton",
2929
"sphinx-design",
3030
"matplotlib>=3.7",
31-
"photutils>=1.0",
31+
"photutils>=1.11",
3232
"synphot",
3333
"nbsphinx",
3434
"ipykernel"
3535
]
3636
all = [
37-
"photutils>=1.0",
37+
"photutils>=1.11",
3838
"synphot",
3939
]
4040

@@ -89,7 +89,6 @@ filterwarnings = [
8989
"ignore:.*utcfromtimestamp:DeprecationWarning",
9090
# DeprecationWarning from gwcs 0.18.3 in oldestdeps
9191
"ignore:.*pkg_resources.*:DeprecationWarning",
92-
"ignore:The Spectrum1D class is deprecated and may be removed",
9392
# DeprecationWarning from gwcs in devdeps
9493
"ignore:The isiterable function is deprecated and may be removed",
9594
]

specreduce/background.py

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from astropy.stats import sigma_clip
1010
from astropy.utils.decorators import deprecated_attribute
1111

12-
from specreduce.compat import SPECUTILS_LT_2, Spectrum
12+
from specutils import Spectrum
1313
from specreduce.core import _ImageParser, MaskingOption, ImageLike
1414
from specreduce.extract import _ap_weight_image
1515
from specreduce.tracing import Trace, FlatTrace
@@ -375,12 +375,9 @@ def bkg_image(self, image=None) -> Spectrum:
375375
self._orig_uncty_type
376376
)
377377

378-
if SPECUTILS_LT_2:
379-
kwargs = {}
380-
else:
381-
kwargs = {"spectral_axis_index": arr.ndim - 1}
382378
return Spectrum(
383-
arr * image.unit, spectral_axis=image.spectral_axis, uncertainty=uncertainty, **kwargs
379+
arr * image.unit, spectral_axis=image.spectral_axis, uncertainty=uncertainty,
380+
spectral_axis_index=arr.ndim - 1
384381
)
385382

386383
def bkg_spectrum(self, image=None, bkg_statistic=None) -> Spectrum:
@@ -400,7 +397,7 @@ def bkg_spectrum(self, image=None, bkg_statistic=None) -> Spectrum:
400397
401398
Returns
402399
-------
403-
`~specutils.Spectrum1D`
400+
`~specutils.Spectrum`
404401
The background 1D spectrum, with flux and uncertainty expressed
405402
in the same units as the input image (or DN if none were provided).
406403
"""
@@ -436,17 +433,7 @@ def sub_image(self, image=None) -> Spectrum:
436433
uncertainty.
437434
"""
438435
image = self._parse_image(image)
439-
440-
if not SPECUTILS_LT_2:
441-
return image - self.bkg_image(image)
442-
443-
# a compare_wcs argument is needed for Spectrum.subtract() in order to
444-
# avoid a TypeError from SpectralCoord when image's spectral axis is in
445-
# pixels. it is not needed when image's spectral axis has physical units
446-
kwargs = {"compare_wcs": None} if image.spectral_axis.unit == u.pix else {}
447-
448-
# https://docs.astropy.org/en/stable/nddata/mixins/ndarithmetic.html
449-
return image.subtract(self.bkg_image(image), **kwargs)
436+
return image - self.bkg_image(image)
450437

451438
def sub_spectrum(self, image=None) -> Spectrum:
452439
"""

specreduce/calibration_data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from astropy.coordinates import SpectralCoord
1515
from specutils.utils.wcs_utils import vac_to_air
1616

17-
from specreduce.compat import Spectrum
17+
from specutils import Spectrum
1818

1919
__all__ = [
2020
'get_available_line_catalogs',

specreduce/compat.py

Lines changed: 0 additions & 11 deletions
This file was deleted.

specreduce/conftest.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from astropy.utils.data import get_pkg_data_filename
99
from specutils import SpectralAxis
1010

11-
from specreduce.compat import SPECUTILS_LT_2, Spectrum
11+
from specutils import Spectrum
1212

1313
try:
1414
from pytest_astropy_header.display import PYTEST_HEADER_MODULES, TESTED_VERSIONS
@@ -33,11 +33,7 @@ def _mk_test_data(imgtype, nrows=30, ncols=10):
3333
flux = image * u.DN
3434
uncert = VarianceUncertainty(image_ones)
3535
if imgtype == "spec_no_axis":
36-
if SPECUTILS_LT_2:
37-
kwargs = {}
38-
else:
39-
kwargs = {"spectral_axis_index": image.ndim - 1}
40-
image = Spectrum(flux, uncertainty=uncert, **kwargs)
36+
image = Spectrum(flux, uncertainty=uncert, spectral_axis_index=image.ndim - 1)
4137
else: # "spec"
4238
image = Spectrum(flux, spectral_axis=np.arange(ncols) * u.um, uncertainty=uncert)
4339
return image
@@ -77,15 +73,10 @@ def all_images():
7773
sax = SpectralAxis(np.linspace(14.377, 3.677, flux.shape[-1]) * u.um)
7874
unc = VarianceUncertainty(np.random.rand(*flux.shape))
7975

80-
if SPECUTILS_LT_2:
81-
kwargs = {}
82-
else:
83-
kwargs = {"spectral_axis_index": img.ndim - 1}
84-
8576
all_images = {}
8677
all_images['arr'] = img
8778
all_images['s1d'] = Spectrum(flux, spectral_axis=sax, uncertainty=unc)
88-
all_images['s1d_pix'] = Spectrum(flux, uncertainty=unc, **kwargs)
79+
all_images['s1d_pix'] = Spectrum(flux, uncertainty=unc, spectral_axis_index=img.ndim - 1)
8980
all_images['ccd'] = CCDData(img, uncertainty=unc, unit=flux.unit)
9081
all_images['ndd'] = NDData(img, uncertainty=unc, unit=flux.unit)
9182
all_images['qnt'] = img * flux.unit

specreduce/core.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from astropy import units as u
1010
from astropy.nddata import VarianceUncertainty, NDData
1111

12-
from specreduce.compat import SPECUTILS_LT_2, Spectrum
12+
from specutils import Spectrum
1313

1414
__all__ = ["SpecreduceOperation"]
1515

@@ -29,7 +29,7 @@ class _ImageParser:
2929
that are missing in the provided image with generic values.
3030
Accepted image types are:
3131
32-
- `~specutils.Spectrum1D` (preferred)
32+
- `~specutils.Spectrum` (preferred)
3333
- `~astropy.nddata.ccddata.CCDData`
3434
- `~astropy.nddata.ndddata.NDDData`
3535
- `~astropy.units.quantity.Quantity`
@@ -148,13 +148,9 @@ def _get_data_from_image(
148148

149149
spectral_axis = getattr(image, "spectral_axis", np.arange(img.shape[disp_axis]) * u.pix)
150150

151-
if SPECUTILS_LT_2:
152-
kwargs = {}
153-
else:
154-
kwargs = {"spectral_axis_index": img.ndim - 1}
155151
img = Spectrum(
156152
img * unit, spectral_axis=spectral_axis, uncertainty=uncertainty, mask=mask,
157-
**kwargs
153+
spectral_axis_index=img.ndim - 1
158154
)
159155
return img
160156

specreduce/extract.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from scipy.integrate import trapezoid
1212
from scipy.interpolate import RectBivariateSpline
1313

14-
from specreduce.compat import Spectrum
14+
from specutils import Spectrum
1515
from specreduce.core import SpecreduceOperation, ImageLike, MaskingOption
1616
from specreduce.tracing import Trace, FlatTrace
1717

@@ -169,7 +169,7 @@ class BoxcarExtract(SpecreduceOperation):
169169
170170
Returns
171171
-------
172-
spec : `~specutils.Spectrum1D`
172+
spec : `~specutils.Spectrum`
173173
The extracted 1d spectrum expressed in DN and pixel units
174174
"""
175175

@@ -666,7 +666,7 @@ def __call__(
666666
667667
Returns
668668
-------
669-
spec_1d : `~specutils.Spectrum1D`
669+
spec_1d : `~specutils.Spectrum`
670670
The final, Horne extracted 1D spectrum.
671671
"""
672672
image = image if image is not None else self.image

0 commit comments

Comments
 (0)