From 9d3c67307cfb6881314a2e34d8006eec19d6b075 Mon Sep 17 00:00:00 2001 From: William Jamieson Date: Tue, 19 Nov 2024 16:09:06 -0500 Subject: [PATCH 1/3] Use the `world_to_pixel_values` in some test cases as this is a low-level object conversion not a highlevel one. --- specutils/tests/test_spectrum1d.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/specutils/tests/test_spectrum1d.py b/specutils/tests/test_spectrum1d.py index 39ea23278..297d4c4f2 100644 --- a/specutils/tests/test_spectrum1d.py +++ b/specutils/tests/test_spectrum1d.py @@ -318,7 +318,7 @@ 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) + pix_axis = spec.wcs.world_to_pixel_values(np.arange(20, 30) * u.nm) disp_axis = spec.wcs.pixel_to_world(np.arange(20, 30)) assert isinstance(pix_axis, np.ndarray) @@ -326,7 +326,7 @@ def test_wcs_transformations(): # Test transform with different unit with u.set_enabled_equivalencies(u.spectral()): - spec.wcs.world_to_pixel(np.arange(20, 30) * u.GHz) + spec.wcs.world_to_pixel_values(np.arange(20, 30) * u.GHz) # Test with a FITS WCS my_wcs = fitswcs.WCS(header={'CDELT1': 1, 'CRVAL1': 6562.8, 'CUNIT1': 'Angstrom', From 335c1fb955e821171857e952f14296d014eea2bd Mon Sep 17 00:00:00 2001 From: William Jamieson Date: Tue, 19 Nov 2024 16:25:26 -0500 Subject: [PATCH 2/3] Minor testing update so that files generated by testing get cleaned up by pytest --- docs/spectral_regions.rst | 5 +++++ specutils/tests/test_regions.py | 7 ++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/docs/spectral_regions.rst b/docs/spectral_regions.rst index 15cae1b20..01a2b745d 100644 --- a/docs/spectral_regions.rst +++ b/docs/spectral_regions.rst @@ -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. diff --git a/specutils/tests/test_regions.py b/specutils/tests/test_regions.py index bc7720ab9..9b9320725 100644 --- a/specutils/tests/test_regions.py +++ b/specutils/tests/test_regions.py @@ -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()) From d5dc72214f0143d7c3a84bd3f6c3e37f5e65b618 Mon Sep 17 00:00:00 2001 From: William Jamieson Date: Tue, 19 Nov 2024 17:01:44 -0500 Subject: [PATCH 3/3] Correct fix for backwards compatiblity --- specutils/tests/test_spectrum1d.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/specutils/tests/test_spectrum1d.py b/specutils/tests/test_spectrum1d.py index 297d4c4f2..36f249d8a 100644 --- a/specutils/tests/test_spectrum1d.py +++ b/specutils/tests/test_spectrum1d.py @@ -318,7 +318,9 @@ 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_values(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) @@ -326,7 +328,9 @@ def test_wcs_transformations(): # Test transform with different unit with u.set_enabled_equivalencies(u.spectral()): - spec.wcs.world_to_pixel_values(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',