Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the APE 14 specified API in some of the tests #1195

Merged
merged 3 commits into from
Nov 19, 2024
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
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
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
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))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine. I think it makes sense for specutils to use high level API.

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
Loading