Skip to content

Commit

Permalink
Use the APE 14 specified API in some of the tests (#1195)
Browse files Browse the repository at this point in the history
* Use the `world_to_pixel_values` in some test cases as this is a low-level object conversion not a highlevel one.

* Minor testing update so that files generated by testing get cleaned up by pytest

* Correct fix for backwards compatiblity
  • Loading branch information
WilliamJamieson authored Nov 19, 2024
1 parent 170d70f commit f8a8d6a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
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))
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 f8a8d6a

Please sign in to comment.