Skip to content
Open
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
1 change: 0 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@
nitpick_ignore = [
("py:class", "ArrayLike"),
("py:class", "numpy._typing.ArrayLike"),
("py:class", "specutils.spectra.spectrum1d.Spectrum1D"),
]

# Ignore complex type annotations that can't be cross-referenced
Expand Down
4 changes: 2 additions & 2 deletions docs/specphot_standards.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Introduction

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

Supported Databases
Expand Down Expand Up @@ -43,7 +43,7 @@ The bulk of them are inherited from IRAF's `onedstds <https://github.com/iraf-co
some more recently curated datasets from `ESO <https://www.eso.org/sci/observing/tools/standards/spectra/stanlis.html>`_, the
`Nearby Supernova Factory <https://snfactory.lbl.gov/>`_, and `Gemini
<https://github.com/GeminiDRSoftware/DRAGONS/tree/master/geminidr/gemini/lookups/spectrophotometric_standards>`_ are included as well. The
`~specreduce.calibration_data.load_onedstds` function is provided to load these data into `~specutils.Spectrum1D`
`~specreduce.calibration_data.load_onedstds` function is provided to load these data into `~specutils.Spectrum`
instances. If `specreduce_data <https://github.com/astropy/specreduce-data/>`_ is not installed, the data will be downloaded from the GitHub
`repository <https://github.com/astropy/specreduce-data/tree/main/specreduce_data/reference_data/onedstds>`_. The available
database names and their descriptions are listed here. Please refer to the `specreduce-data repository
Expand Down
14 changes: 7 additions & 7 deletions docs/terms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Extraction
==========

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

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

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

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

*Data cube*
===========
Expand Down Expand Up @@ -280,12 +280,12 @@ Data Structures

- Python Data structures, which are Python classes.

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

*Data Model*
Expand Down Expand Up @@ -439,7 +439,7 @@ API
*Spectral class*
================

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

Expand Down
11 changes: 5 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ readme = "README.rst"
requires-python = ">=3.11"
dependencies = [
"numpy>=1.24",
"astropy>=5.3",
"scipy>=1.10",
"specutils>=1.9.1",
"astropy>=6.0",
"scipy>=1.14",
"specutils>=2.0",
"matplotlib>=3.10",
"gwcs",
]
Expand All @@ -28,13 +28,13 @@ docs = [
"sphinx-copybutton",
"sphinx-design",
"matplotlib>=3.7",
"photutils>=1.0",
"photutils>=1.11",
"synphot",
"nbsphinx",
"ipykernel"
]
all = [
"photutils>=1.0",
"photutils>=1.11",
"synphot",
]

Expand Down Expand Up @@ -89,7 +89,6 @@ filterwarnings = [
"ignore:.*utcfromtimestamp:DeprecationWarning",
# DeprecationWarning from gwcs 0.18.3 in oldestdeps
"ignore:.*pkg_resources.*:DeprecationWarning",
"ignore:The Spectrum1D class is deprecated and may be removed",
# DeprecationWarning from gwcs in devdeps
"ignore:The isiterable function is deprecated and may be removed",
]
Expand Down
23 changes: 5 additions & 18 deletions specreduce/background.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from astropy.stats import sigma_clip
from astropy.utils.decorators import deprecated_attribute

from specreduce.compat import SPECUTILS_LT_2, Spectrum
from specutils import Spectrum
from specreduce.core import _ImageParser, MaskingOption, ImageLike
from specreduce.extract import _ap_weight_image
from specreduce.tracing import Trace, FlatTrace
Expand Down Expand Up @@ -375,12 +375,9 @@ def bkg_image(self, image=None) -> Spectrum:
self._orig_uncty_type
)

if SPECUTILS_LT_2:
kwargs = {}
else:
kwargs = {"spectral_axis_index": arr.ndim - 1}
return Spectrum(
arr * image.unit, spectral_axis=image.spectral_axis, uncertainty=uncertainty, **kwargs
arr * image.unit, spectral_axis=image.spectral_axis, uncertainty=uncertainty,
spectral_axis_index=arr.ndim - 1
)

def bkg_spectrum(self, image=None, bkg_statistic=None) -> Spectrum:
Expand All @@ -400,7 +397,7 @@ def bkg_spectrum(self, image=None, bkg_statistic=None) -> Spectrum:

Returns
-------
`~specutils.Spectrum1D`
`~specutils.Spectrum`
The background 1D spectrum, with flux and uncertainty expressed
in the same units as the input image (or DN if none were provided).
"""
Expand Down Expand Up @@ -436,17 +433,7 @@ def sub_image(self, image=None) -> Spectrum:
uncertainty.
"""
image = self._parse_image(image)

if not SPECUTILS_LT_2:
return image - self.bkg_image(image)

# a compare_wcs argument is needed for Spectrum.subtract() in order to
# avoid a TypeError from SpectralCoord when image's spectral axis is in
# pixels. it is not needed when image's spectral axis has physical units
kwargs = {"compare_wcs": None} if image.spectral_axis.unit == u.pix else {}

# https://docs.astropy.org/en/stable/nddata/mixins/ndarithmetic.html
return image.subtract(self.bkg_image(image), **kwargs)
return image - self.bkg_image(image)

def sub_spectrum(self, image=None) -> Spectrum:
"""
Expand Down
2 changes: 1 addition & 1 deletion specreduce/calibration_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from astropy.coordinates import SpectralCoord
from specutils.utils.wcs_utils import vac_to_air

from specreduce.compat import Spectrum
from specutils import Spectrum

__all__ = [
'get_available_line_catalogs',
Expand Down
11 changes: 0 additions & 11 deletions specreduce/compat.py

This file was deleted.

15 changes: 3 additions & 12 deletions specreduce/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from astropy.utils.data import get_pkg_data_filename
from specutils import SpectralAxis

from specreduce.compat import SPECUTILS_LT_2, Spectrum
from specutils import Spectrum

try:
from pytest_astropy_header.display import PYTEST_HEADER_MODULES, TESTED_VERSIONS
Expand All @@ -33,11 +33,7 @@ def _mk_test_data(imgtype, nrows=30, ncols=10):
flux = image * u.DN
uncert = VarianceUncertainty(image_ones)
if imgtype == "spec_no_axis":
if SPECUTILS_LT_2:
kwargs = {}
else:
kwargs = {"spectral_axis_index": image.ndim - 1}
image = Spectrum(flux, uncertainty=uncert, **kwargs)
image = Spectrum(flux, uncertainty=uncert, spectral_axis_index=image.ndim - 1)
else: # "spec"
image = Spectrum(flux, spectral_axis=np.arange(ncols) * u.um, uncertainty=uncert)
return image
Expand Down Expand Up @@ -77,15 +73,10 @@ def all_images():
sax = SpectralAxis(np.linspace(14.377, 3.677, flux.shape[-1]) * u.um)
unc = VarianceUncertainty(np.random.rand(*flux.shape))

if SPECUTILS_LT_2:
kwargs = {}
else:
kwargs = {"spectral_axis_index": img.ndim - 1}

all_images = {}
all_images['arr'] = img
all_images['s1d'] = Spectrum(flux, spectral_axis=sax, uncertainty=unc)
all_images['s1d_pix'] = Spectrum(flux, uncertainty=unc, **kwargs)
all_images['s1d_pix'] = Spectrum(flux, uncertainty=unc, spectral_axis_index=img.ndim - 1)
all_images['ccd'] = CCDData(img, uncertainty=unc, unit=flux.unit)
all_images['ndd'] = NDData(img, uncertainty=unc, unit=flux.unit)
all_images['qnt'] = img * flux.unit
Expand Down
10 changes: 3 additions & 7 deletions specreduce/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from astropy import units as u
from astropy.nddata import VarianceUncertainty, NDData

from specreduce.compat import SPECUTILS_LT_2, Spectrum
from specutils import Spectrum

__all__ = ["SpecreduceOperation"]

Expand All @@ -29,7 +29,7 @@ class _ImageParser:
that are missing in the provided image with generic values.
Accepted image types are:

- `~specutils.Spectrum1D` (preferred)
- `~specutils.Spectrum` (preferred)
- `~astropy.nddata.ccddata.CCDData`
- `~astropy.nddata.ndddata.NDDData`
- `~astropy.units.quantity.Quantity`
Expand Down Expand Up @@ -148,13 +148,9 @@ def _get_data_from_image(

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

if SPECUTILS_LT_2:
kwargs = {}
else:
kwargs = {"spectral_axis_index": img.ndim - 1}
img = Spectrum(
img * unit, spectral_axis=spectral_axis, uncertainty=uncertainty, mask=mask,
**kwargs
spectral_axis_index=img.ndim - 1
)
return img

Expand Down
6 changes: 3 additions & 3 deletions specreduce/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from scipy.integrate import trapezoid
from scipy.interpolate import RectBivariateSpline

from specreduce.compat import Spectrum
from specutils import Spectrum
from specreduce.core import SpecreduceOperation, ImageLike, MaskingOption
from specreduce.tracing import Trace, FlatTrace

Expand Down Expand Up @@ -169,7 +169,7 @@ class BoxcarExtract(SpecreduceOperation):

Returns
-------
spec : `~specutils.Spectrum1D`
spec : `~specutils.Spectrum`
The extracted 1d spectrum expressed in DN and pixel units
"""

Expand Down Expand Up @@ -666,7 +666,7 @@ def __call__(

Returns
-------
spec_1d : `~specutils.Spectrum1D`
spec_1d : `~specutils.Spectrum`
The final, Horne extracted 1D spectrum.
"""
image = image if image is not None else self.image
Expand Down
2 changes: 1 addition & 1 deletion specreduce/fluxcal.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from astropy.table import Table
from scipy.interpolate import UnivariateSpline

from specreduce.compat import Spectrum
from specutils import Spectrum
from specreduce.core import SpecreduceOperation


Expand Down
2 changes: 1 addition & 1 deletion specreduce/line_matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from gwcs.wcs import WCS as gWCS
from specutils.fitting import find_lines_threshold, fit_lines

from specreduce.compat import Spectrum
from specutils import Spectrum

__all__ = ["find_arc_lines", "match_lines_wcs"]

Expand Down
2 changes: 1 addition & 1 deletion specreduce/tests/test_background.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from astropy.nddata import NDData, VarianceUncertainty, StdDevUncertainty, InverseVariance

from specreduce.background import Background
from specreduce.compat import Spectrum
from specutils import Spectrum
from specreduce.tracing import FlatTrace, ArrayTrace


Expand Down
2 changes: 1 addition & 1 deletion specreduce/tests/test_extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from astropy.tests.helper import assert_quantity_allclose

from specreduce.background import Background
from specreduce.compat import Spectrum
from specutils import Spectrum
from specreduce.extract import BoxcarExtract, HorneExtract, OptimalExtract, _align_along_trace
from specreduce.tracing import FitTrace, FlatTrace, ArrayTrace

Expand Down
2 changes: 1 addition & 1 deletion specreduce/tests/test_image_parsing.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np
from astropy import units as u

from specreduce.compat import Spectrum
from specutils import Spectrum
from specreduce.core import _ImageParser
from specreduce.extract import HorneExtract
from specreduce.tracing import FlatTrace
Expand Down
2 changes: 1 addition & 1 deletion specreduce/tests/test_line_matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from specutils.fitting import fit_generic_continuum

from specreduce.calibration_data import load_pypeit_calibration_lines
from specreduce.compat import Spectrum
from specutils import Spectrum
from specreduce.extract import BoxcarExtract
from specreduce.line_matching import match_lines_wcs, find_arc_lines
from specreduce.tracing import FlatTrace
Expand Down
8 changes: 2 additions & 6 deletions specreduce/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from astropy.modeling import fitting, models
from astropy.nddata import NDData

from specreduce.compat import SPECUTILS_LT_2, Spectrum
from specutils import Spectrum
from specreduce.tracing import FitTrace
from specreduce.utils.utils import measure_cross_dispersion_profile

Expand Down Expand Up @@ -61,11 +61,7 @@ def test_measure_cross_dispersion_profile(self, pixel, width):
images.append(dat) # test unitless
images.append(dat * u.DN)
images.append(NDData(dat * u.DN))
if SPECUTILS_LT_2:
kwargs = {}
else:
kwargs = {"spectral_axis_index": dat.ndim - 1}
images.append(Spectrum(flux=dat * u.DN, **kwargs))
images.append(Spectrum(flux=dat * u.DN, spectral_axis_index=dat.ndim - 1))

for img in images:

Expand Down
2 changes: 1 addition & 1 deletion specreduce/tests/test_wavecal1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from matplotlib.figure import Figure
from numpy import array

from specreduce.compat import Spectrum
from specutils import Spectrum
from specreduce.wavecal1d import WavelengthCalibration1D

ref_pixel = 250
Expand Down
2 changes: 1 addition & 1 deletion specreduce/tests/test_wavesol1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from astropy.nddata import StdDevUncertainty
from gwcs import wcs
from specreduce.wavesol1d import _diff_poly1d, WavelengthSolution1D
from specreduce.compat import Spectrum
from specutils import Spectrum


ref_pixel = 250.0
Expand Down
2 changes: 1 addition & 1 deletion specreduce/wavecal1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from scipy.spatial import KDTree

from specreduce.calibration_data import load_pypeit_calibration_lines
from specreduce.compat import Spectrum
from specutils import Spectrum
from specreduce.line_matching import find_arc_lines

__all__ = ["WavelengthCalibration1D"]
Expand Down
Loading