Skip to content

Commit

Permalink
Merge branch 'main' into add-astra-loader
Browse files Browse the repository at this point in the history
  • Loading branch information
rileythai committed Dec 6, 2024
2 parents c57544c + f8a8d6a commit a570edd
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 21 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci_cron_weekly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3 # v5.2.0
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
with:
python-version: ${{ matrix.python }}
- name: Install Python dependencies
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/ci_workflows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3 # v5.2.0
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
with:
python-version: ${{ matrix.python }}
- name: Install Python dependencies
Expand All @@ -63,7 +63,7 @@ jobs:
# TODO: Do we need --gcov-glob "*cextern*" ?
- name: Upload coverage to artifacts
if: ${{ contains(matrix.toxenv,'-cov') }}
uses: actions/upload-artifact@604373da6381bf24206979c74d06a550515601b9 # v4.4.1
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
with:
name: coverage_${{ matrix.toxenv }}.xml
path: coverage.xml
Expand Down Expand Up @@ -112,11 +112,11 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3 # v5.2.0
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
with:
python-version: ${{ matrix.python }}
- name: Install Python dependencies
Expand Down
21 changes: 20 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
1.19.0 (unreleased)
1.20.0 (unreleased)
-------------------

New Features
Expand All @@ -10,6 +10,25 @@ Bug Fixes
Other Changes and Additions
^^^^^^^^^^^^^^^^^^^^^^^^^^^

1.19.0 (2024-11-05)
-------------------

Bug Fixes
^^^^^^^^^

- Fixed ``mwmVisit`` SDSS-V ``Spectrum1D`` and ``SpectrumList`` default loader
being unable to load files containing only BOSS instrument spectra. [#1185]

- Fixed automatic format detection for SDSS-V ``SpectrumList`` default loaders. [#1185]

- Fixed ``SplineInterpolatedResampler`` when input and output spectral axes are different
physical types, e.g. wavelength and velocity. [#1190]

Other Changes and Additions
^^^^^^^^^^^^^^^^^^^^^^^^^^^

- "Multi" loaders have been removed from SDSS-V ``SpectrumList`` default loaders. [#1185]

1.18.0 (2024-10-16)
-------------------

Expand Down
5 changes: 5 additions & 0 deletions docs/spectral_regions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,11 @@ to create a new `~specutils.SpectralRegion` using the ``read`` class method:
>>> spec_reg = SpectralRegion.read("spectral_region.ecsv")
.. testcleanup::

>>> import os
>>> os.remove("spectral_region.ecsv")

The `~astropy.table.QTable` created to write out the `~specutils.SpectralRegion` to file can also be accessed
directly with the ``as_table`` method, and a `~specutils.SpectralRegion` can be created directly from a `~astropy.table.QTable`
with the appropriate columns (minimally ``lower_bound`` and ``upper_bound``) using the ``from_qtable`` class method.
Expand Down
12 changes: 10 additions & 2 deletions specutils/io/default_loaders/jwst_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,11 @@ def _jwst_s2d_loader(filename, **kwargs):

# Get the wavelength array from the GWCS object which returns a
# tuple of (RA, Dec, lambda)
grid = grid_from_bounding_box(wcs.bounding_box)
with warnings.catch_warnings():
# https://github.com/spacetelescope/gwcs/pull/522
warnings.filterwarnings(
"ignore", message="The bounding_box was set in C order.*")
grid = grid_from_bounding_box(wcs.bounding_box)
_, _, lam = wcs(*grid)
_, _, lam_unit = wcs.output_frame.unit

Expand Down Expand Up @@ -587,7 +591,11 @@ def _jwst_s3d_loader(filename, **kwargs):
# tuple of (RA, Dec, lambda).
# Since the spatial and spectral axes are orthogonal in s3d data,
# it is much faster to compute a slice down the spectral axis.
grid = grid_from_bounding_box(wcs.bounding_box)[:, :, 0, 0]
with warnings.catch_warnings():
# https://github.com/spacetelescope/gwcs/pull/522
warnings.filterwarnings(
"ignore", message="The bounding_box was set in C order.*")
grid = grid_from_bounding_box(wcs.bounding_box)[:, :, 0, 0]
_, _, wavelength_array = wcs(*grid)
_, _, wavelength_unit = wcs.output_frame.unit

Expand Down
9 changes: 5 additions & 4 deletions specutils/io/default_loaders/sdss_v.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,17 +763,17 @@ def _load_astra_hdu(hdulist: HDUList, hdu: int, **kwargs):

# collapse shape if 1D spectra in 2D array, makes readout easier
if flux.shape[0] == 1:
flux = flux[0]
e_flux = e_flux[0]
mask = mask[0]
flux = np.ravel(flux)
e_flux = e_flux[0] # different class
mask = np.ravel(mask)

# Create metadata
meta = dict()
meta["header"] = hdulist[0].header

# Add identifiers (obj, telescope, mjd, datatype)
meta["telescope"] = hdulist[hdu].data["telescope"]
meta['instrument'] = 'BOSS' if hdu <= 2 else 'APOGEE'
meta["instrument"] = hdulist[hdu].header.get("INSTRMNT")
try: # get obj if exists
meta["obj"] = hdulist[hdu].data["obj"]
except KeyError:
Expand All @@ -791,6 +791,7 @@ def _load_astra_hdu(hdulist: HDUList, hdu: int, **kwargs):
meta["name"] = hdulist[hdu].name
meta["sdss_id"] = hdulist[hdu].data['sdss_id']

# drop back a list of Spectrum1Ds to unpack
return Spectrum1D(
spectral_axis=spectral_axis,
flux=flux,
Expand Down
2 changes: 1 addition & 1 deletion specutils/manipulation/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ def resample1d(self, orig_spectrum, fin_spec_axis):
if self.extrapolation_treatment == 'zero_fill':
fill_val = 0

orig_edges = orig_spectrum.spectral_axis.bin_edges
orig_edges = orig_axis_in_new.bin_edges
off_edges = (fin_spec_axis < np.min(orig_edges)) | (np.max(orig_edges) < fin_spec_axis)
out_flux_val[off_edges] = fill_val
if new_unc is not None:
Expand Down
7 changes: 4 additions & 3 deletions specutils/tests/test_regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,11 @@ def test_from_list_list():
assert_quantity_allclose(reg, (spec_reg[i].lower, spec_reg[i].upper))


def test_read_write():
def test_read_write(tmp_path):
path = tmp_path / "test_sr.ecsv"
sr = SpectralRegion([(0.45*u.um, 0.6*u.um), (0.8*u.um, 0.9*u.um)])
sr.write("test_sr.ecsv")
sr2 = SpectralRegion.read("test_sr.ecsv")
sr.write(str(path))
sr2 = SpectralRegion.read(path)
assert list(sr2.as_table().columns) == ["lower_bound", "upper_bound"]

sr3 = SpectralRegion.from_qtable(sr2.as_table())
Expand Down
18 changes: 17 additions & 1 deletion specutils/tests/test_resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from astropy.nddata import VarianceUncertainty, InverseVariance, StdDevUncertainty
from astropy.tests.helper import assert_quantity_allclose

from ..spectra.spectrum1d import Spectrum1D
from ..spectra.spectrum1d import Spectrum1D, SpectralAxis
from ..manipulation.resample import FluxConservingResampler, LinearInterpolatedResampler, SplineInterpolatedResampler


Expand Down Expand Up @@ -214,6 +214,22 @@ def test_resample_different_units(all_resamplers):
resampled = resampler(input_spectrum, resamp_grid)
assert not np.any(np.isnan(resampled.flux))

resamp_grid = [550, 650]*u.nm
resampled = resampler(input_spectrum, resamp_grid)

# Test conversion to velocity grid
rest_wavelength = 656.2 * u.nm
wavelengths = np.linspace(640, 672, 10) * u.nm
flux = np.ones(10) * u.mJy
spec1d = Spectrum1D(spectral_axis=wavelengths, velocity_convention="optical", flux=flux)
spec1d.spectral_axis.doppler_rest = rest_wavelength

velocities = np.linspace(-1000, 1000, 5) * u.km/u.s
velocity_grid = SpectralAxis(velocities, doppler_rest=rest_wavelength,
doppler_convention="optical")
velocity_binned = resampler(spec1d, velocity_grid)
assert not np.any(np.isnan(velocity_binned.flux))


def test_resample_uncs(all_resamplers):
sdunc = StdDevUncertainty([0.1, 0.2, 0.3]*u.mJy)
Expand Down
8 changes: 6 additions & 2 deletions specutils/tests/test_spectrum1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,15 +318,19 @@ def test_wcs_transformations():
spec = Spectrum1D(spectral_axis=np.arange(1, 50) * u.nm,
flux=np.ones(49) * u.Jy)

pix_axis = spec.wcs.world_to_pixel(np.arange(20, 30) * u.nm)
# After spacetelescope/gwcs#457 is merged and released, this can be changed to
# pix_axis = spec.wcs.world_to_pixel_values(np.arange(20, 30) * u.nm)
pix_axis = spec.wcs.world_to_pixel(SpectralCoord(np.arange(20, 30) * u.nm))
disp_axis = spec.wcs.pixel_to_world(np.arange(20, 30))

assert isinstance(pix_axis, np.ndarray)
assert isinstance(disp_axis, u.Quantity)

# Test transform with different unit
with u.set_enabled_equivalencies(u.spectral()):
spec.wcs.world_to_pixel(np.arange(20, 30) * u.GHz)
# After spacetelescope/gwcs#457 is merged and released, this can be changed to
# spec.wcs.world_to_pixel_values(np.arange(20, 30) * u.GHz)
spec.wcs.world_to_pixel(SpectralCoord(np.arange(20, 30) * u.GHz))

# Test with a FITS WCS
my_wcs = fitswcs.WCS(header={'CDELT1': 1, 'CRVAL1': 6562.8, 'CUNIT1': 'Angstrom',
Expand Down

0 comments on commit a570edd

Please sign in to comment.