From 935945519c966ccdc1df07e69cfe0cea0df42c80 Mon Sep 17 00:00:00 2001 From: Ricky O'Steen Date: Thu, 25 Jul 2024 13:59:24 -0400 Subject: [PATCH 1/9] Remove incorrect moveaxis call in spectrum1d_3d parser --- .../cubeviz/plugins/moment_maps/tests/test_moment_maps.py | 2 +- jdaviz/configs/cubeviz/plugins/parsers.py | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/jdaviz/configs/cubeviz/plugins/moment_maps/tests/test_moment_maps.py b/jdaviz/configs/cubeviz/plugins/moment_maps/tests/test_moment_maps.py index c2efc22c4b..6a0cfd5275 100644 --- a/jdaviz/configs/cubeviz/plugins/moment_maps/tests/test_moment_maps.py +++ b/jdaviz/configs/cubeviz/plugins/moment_maps/tests/test_moment_maps.py @@ -109,7 +109,7 @@ def test_moment_calculation(cubeviz_helper, spectrum1d_cube, tmp_path): ) result = dc[-1].get_object(cls=CCDData) - assert result.shape == (4, 2) # Cube shape is (2, 2, 4) + assert result.shape == (2, 4) # Cube shape is (2, 2, 4), moment transposes assert isinstance(dc[-1].coords, WCS) # Make sure coordinate display now show moment map info (no WCS) diff --git a/jdaviz/configs/cubeviz/plugins/parsers.py b/jdaviz/configs/cubeviz/plugins/parsers.py index a565ba36e1..0dd71bfb26 100644 --- a/jdaviz/configs/cubeviz/plugins/parsers.py +++ b/jdaviz/configs/cubeviz/plugins/parsers.py @@ -423,8 +423,6 @@ def _parse_spectrum1d_3d(app, file_obj, data_label=None, else: flux = val - flux = np.moveaxis(flux, 1, 0) - with warnings.catch_warnings(): warnings.filterwarnings( 'ignore', message='Input WCS indicates that the spectral axis is not last', From 098c643bb37721f3b62927f0de73bc23608b6d6d Mon Sep 17 00:00:00 2001 From: Ricky O'Steen Date: Thu, 25 Jul 2024 14:06:53 -0400 Subject: [PATCH 2/9] Working on correcting expected test results --- .../plugins/gaussian_smooth/tests/test_gaussian_smooth.py | 4 ++-- .../default/plugins/model_fitting/tests/test_fitting.py | 4 ++-- .../default/plugins/model_fitting/tests/test_plugin.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/jdaviz/configs/default/plugins/gaussian_smooth/tests/test_gaussian_smooth.py b/jdaviz/configs/default/plugins/gaussian_smooth/tests/test_gaussian_smooth.py index c60e5ca2b9..32dbffa23a 100644 --- a/jdaviz/configs/default/plugins/gaussian_smooth/tests/test_gaussian_smooth.py +++ b/jdaviz/configs/default/plugins/gaussian_smooth/tests/test_gaussian_smooth.py @@ -121,10 +121,10 @@ def test_spatial_convolution(cubeviz_helper, spectrum1d_cube): assert len(dc) == 3 assert dc[-1].label == f'{data_label}[FLUX] spatial-smooth stddev-3.0' - assert dc[-1].shape == (2, 4, 2) # specutils moved spectral axis to last + assert dc[-1].shape == (4, 2, 2) # specutils moved spectral axis to last assert (dc[f'{data_label}[FLUX] spatial-smooth stddev-3.0'].get_object(cls=Spectrum1D, statistic=None).shape - == (2, 4, 2)) + == (4, 2, 2)) def test_specviz_smooth(specviz_helper, spectrum1d): diff --git a/jdaviz/configs/default/plugins/model_fitting/tests/test_fitting.py b/jdaviz/configs/default/plugins/model_fitting/tests/test_fitting.py index 334816029c..12cf894344 100644 --- a/jdaviz/configs/default/plugins/model_fitting/tests/test_fitting.py +++ b/jdaviz/configs/default/plugins/model_fitting/tests/test_fitting.py @@ -89,10 +89,10 @@ def test_parameter_retrieval(cubeviz_helper, spectral_cube_wcs): plugin.calculate_fit() params = cubeviz_helper.get_model_parameters() - slope_res = np.zeros((4, 3)) + slope_res = np.zeros((3, 4)) slope_res[2, 2] = 1.0 slope_res = slope_res * u.nJy / u.Hz - intercept_res = np.ones((4, 3)) + intercept_res = np.ones((3, 4)) intercept_res[2, 2] = 0 intercept_res = intercept_res * u.nJy assert_quantity_allclose(params['model']['slope'], slope_res, diff --git a/jdaviz/configs/default/plugins/model_fitting/tests/test_plugin.py b/jdaviz/configs/default/plugins/model_fitting/tests/test_plugin.py index a3ccd8b8e7..d16ab60149 100644 --- a/jdaviz/configs/default/plugins/model_fitting/tests/test_plugin.py +++ b/jdaviz/configs/default/plugins/model_fitting/tests/test_plugin.py @@ -169,7 +169,7 @@ def test_fit_cube_no_wcs(cubeviz_helper): assert len(fitted_model) == 56 # ny * nx # Make sure shapes are all self-consistent within Cubeviz instance. fitted_data = cubeviz_helper.app.data_collection["model"] - assert fitted_data.shape == (8, 7, 9) # nx, ny, nz + assert fitted_data.shape == (7, 8, 9) # nx, ny, nz assert fitted_data.shape == cubeviz_helper.app.data_collection[0].shape assert fitted_data.shape == output_cube.shape From 1f0cb2078d0e4b378ab0db6b260509457c8e3744 Mon Sep 17 00:00:00 2001 From: Ricky O'Steen Date: Fri, 26 Jul 2024 12:58:34 -0400 Subject: [PATCH 3/9] Continuing to work on tests --- jdaviz/configs/cubeviz/plugins/tests/test_cubeviz_helper.py | 4 ++-- jdaviz/configs/cubeviz/plugins/tests/test_parsers.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/jdaviz/configs/cubeviz/plugins/tests/test_cubeviz_helper.py b/jdaviz/configs/cubeviz/plugins/tests/test_cubeviz_helper.py index ecc66c4ca3..e5e90b881c 100644 --- a/jdaviz/configs/cubeviz/plugins/tests/test_cubeviz_helper.py +++ b/jdaviz/configs/cubeviz/plugins/tests/test_cubeviz_helper.py @@ -51,5 +51,5 @@ def test_get_data_spatial_and_spectral(cubeviz_helper, spectrum1d_cube_larger): assert spatial_with_spec.flux.ndim == 1 assert list(spatial_with_spec.mask) == [True, True, False, False, True, True, True, True, True, True] - assert max(list(spatial_with_spec.flux.value)) == 157. - assert min(list(spatial_with_spec.flux.value)) == 13. + assert max(list(spatial_with_spec.flux.value)) == 232. + assert min(list(spatial_with_spec.flux.value)) == 16. diff --git a/jdaviz/configs/cubeviz/plugins/tests/test_parsers.py b/jdaviz/configs/cubeviz/plugins/tests/test_parsers.py index f70415c392..0af8484de2 100644 --- a/jdaviz/configs/cubeviz/plugins/tests/test_parsers.py +++ b/jdaviz/configs/cubeviz/plugins/tests/test_parsers.py @@ -149,7 +149,7 @@ def test_spectrum3d_no_wcs_parse(cubeviz_helper): data = cubeviz_helper.app.data_collection[0] flux = data.get_component('flux') assert data.label.endswith('[FLUX]') - assert data.shape == (3, 2, 4) # y, x, z + assert data.shape == (2, 3, 4) # y, x, z assert isinstance(data.coords, PaddedSpectrumWCS) assert_array_equal(flux.data, 1) assert flux.units == 'nJy' From b22ba168b5c322b0bf6e431ec5ef94bcddcda037 Mon Sep 17 00:00:00 2001 From: Ricky O'Steen Date: Mon, 5 Aug 2024 14:00:08 -0400 Subject: [PATCH 4/9] Update spectral extraction tests --- .../spectral_extraction/tests/test_spectral_extraction.py | 8 ++++---- jdaviz/conftest.py | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/jdaviz/configs/cubeviz/plugins/spectral_extraction/tests/test_spectral_extraction.py b/jdaviz/configs/cubeviz/plugins/spectral_extraction/tests/test_spectral_extraction.py index b702634610..22a814a828 100644 --- a/jdaviz/configs/cubeviz/plugins/spectral_extraction/tests/test_spectral_extraction.py +++ b/jdaviz/configs/cubeviz/plugins/spectral_extraction/tests/test_spectral_extraction.py @@ -498,8 +498,8 @@ def test_extraction_composite_subset(cubeviz_helper, spectrum1d_cube): subset_plugin = cubeviz_helper.plugins['Subset Tools']._obj spec_extr_plugin = cubeviz_helper.plugins['Spectral Extraction']._obj - lower_aperture = RectangularROI(-0.5, 1.5, -0.5, 0.5) - upper_aperture = RectangularROI(-0.5, 1.5, 2.5, 3.5) + lower_aperture = RectangularROI(-0.5, 0.5, -0.5, 1.5) + upper_aperture = RectangularROI(2.5, 3.5, -0.5, 1.5) flux_viewer.toolbar.active_tool = flux_viewer.toolbar.tools['bqplot:rectangle'] flux_viewer.apply_roi(lower_aperture) @@ -514,14 +514,14 @@ def test_extraction_composite_subset(cubeviz_helper, spectrum1d_cube): spectrum_2 = spec_extr_plugin.extract() subset_plugin.subset_selected = 'Create New' - rectangle = RectangularROI(-0.5, 1.5, -0.5, 3.5) + rectangle = RectangularROI(-0.5, 3.5, -0.5, 1.5) flux_viewer.toolbar.active_tool = flux_viewer.toolbar.tools['bqplot:rectangle'] flux_viewer.apply_roi(rectangle) flux_viewer.toolbar.active_tool = flux_viewer.toolbar.tools['bqplot:truecircle'] subset_plugin.subset_selected = 'Subset 3' cubeviz_helper.app.session.edit_subset_mode.mode = AndNotMode - circle = CircularROI(0.5, 1.5, 1.1) + circle = CircularROI(1.5, 0.5, 1.1) flux_viewer.apply_roi(circle) spec_extr_plugin.aperture_selected = 'Subset 3' diff --git a/jdaviz/conftest.py b/jdaviz/conftest.py index fb8b1b9a68..8a62132da2 100644 --- a/jdaviz/conftest.py +++ b/jdaviz/conftest.py @@ -246,8 +246,8 @@ def spectrum1d_cube_largest(): "CDELT1": 8e-11, "CDELT2": 0.0001, "CDELT3": -0.0001, "CRPIX1": 0, "CRPIX2": 0, "CRPIX3": 0} w = WCS(wcs_dict) - flux = np.zeros((30, 20, 3001), dtype=np.float32) # nx=20 ny=30 nz=3001 - flux[5:15, 1:11, :] = 1 # Bright corner + flux = np.zeros((20, 30, 3001), dtype=np.float32) # nx=20 ny=30 nz=3001 + flux[1:11, 5:15, :] = 1 # Bright corner return Spectrum1D(flux=flux * u.Jy, wcs=w, meta=wcs_dict) From 8b04f0b03ee43ea9e9bdb3c8d2a9e1fab6fbc543 Mon Sep 17 00:00:00 2001 From: Ricky O'Steen Date: Mon, 5 Aug 2024 14:05:46 -0400 Subject: [PATCH 5/9] Update aperphot test --- .../cubeviz/plugins/tests/test_cubeviz_aperphot.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/jdaviz/configs/cubeviz/plugins/tests/test_cubeviz_aperphot.py b/jdaviz/configs/cubeviz/plugins/tests/test_cubeviz_aperphot.py index 20f31702d5..9d922f6a57 100644 --- a/jdaviz/configs/cubeviz/plugins/tests/test_cubeviz_aperphot.py +++ b/jdaviz/configs/cubeviz/plugins/tests/test_cubeviz_aperphot.py @@ -166,8 +166,8 @@ def test_cubeviz_aperphot_cube_orig_flux_mjysr(cubeviz_helper, spectrum1d_cube_c cube = spectrum1d_cube_custom_fluxunit(fluxunit=u.MJy / u.sr) cubeviz_helper.load_data(cube, data_label="test") - aper = RectanglePixelRegion(center=PixCoord(x=1, y=3), width=1, height=1) - bg = RectanglePixelRegion(center=PixCoord(x=0, y=2), width=1, height=1) + aper = RectanglePixelRegion(center=PixCoord(x=3, y=1), width=1, height=1) + bg = RectanglePixelRegion(center=PixCoord(x=2, y=0), width=1, height=1) cubeviz_helper.load_regions([aper, bg]) plg = cubeviz_helper.plugins["Aperture Photometry"]._obj @@ -183,8 +183,8 @@ def test_cubeviz_aperphot_cube_orig_flux_mjysr(cubeviz_helper, spectrum1d_cube_c row = cubeviz_helper.get_aperture_photometry_results()[0] # Basically, we should recover the input rectangle here, minus background. - assert_allclose(row["xcenter"], 1 * u.pix) - assert_allclose(row["ycenter"], 3 * u.pix) + assert_allclose(row["xcenter"], 3 * u.pix) + assert_allclose(row["ycenter"], 1 * u.pix) assert_allclose(row["sum"], 1.1752215e-12 * u.MJy) # (15 - 10) MJy/sr x 2.3504431e-13 sr assert_allclose(row["sum_aper_area"], 1 * (u.pix * u.pix)) assert_allclose(row["pixarea_tot"], 2.350443053909789e-13 * u.sr) From 38085f2cbbf45da8800624bd08cbdc111a64fdda Mon Sep 17 00:00:00 2001 From: Ricky O'Steen Date: Mon, 5 Aug 2024 14:07:11 -0400 Subject: [PATCH 6/9] Changelog --- CHANGES.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index eea2516be7..101ecec939 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -196,6 +196,8 @@ Bug Fixes Cubeviz ^^^^^^^ +- No longer incorrectly swap RA and Dec axes when loading Spectrum1D objects. [#3133] + Imviz ^^^^^ From 1e920b6f10cf9d403062f331d1a1e1fda173d17d Mon Sep 17 00:00:00 2001 From: Ricky O'Steen Date: Mon, 5 Aug 2024 15:23:41 -0400 Subject: [PATCH 7/9] Make one cubeviz mouseover test sensitive to axis swap --- jdaviz/configs/cubeviz/plugins/tests/test_tools.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/jdaviz/configs/cubeviz/plugins/tests/test_tools.py b/jdaviz/configs/cubeviz/plugins/tests/test_tools.py index 7c1129ff59..8f08d55319 100644 --- a/jdaviz/configs/cubeviz/plugins/tests/test_tools.py +++ b/jdaviz/configs/cubeviz/plugins/tests/test_tools.py @@ -87,10 +87,10 @@ def test_spectrum_at_spaxel_altkey_true(cubeviz_helper, spectrum1d_cube): assert flux_viewer.slice == 1 label_mouseover = cubeviz_helper.app.session.application._tools['g-coords-info'] label_mouseover._viewer_mouse_event(flux_viewer, - {'event': 'mousemove', 'domain': {'x': 1, 'y': 1}}) - assert label_mouseover.as_text() == ('Pixel x=01.0 y=01.0 Value +1.30000e+01 Jy', - 'World 13h39m59.9461s +27d00m00.7200s (ICRS)', - '204.9997755344 27.0001999998 (deg)') + {'event': 'mousemove', 'domain': {'x': 2, 'y': 1}}) + assert label_mouseover.as_text() == ('Pixel x=02.0 y=01.0 Value +1.40000e+01 Jy', + 'World 13h39m59.9192s +27d00m00.7200s (ICRS)', + '204.9996633015 27.0001999996 (deg)') # Click on spaxel location x = 1 From eeb289187ed98ac53ae2ccec0fe1180943195cf3 Mon Sep 17 00:00:00 2001 From: Ricky O'Steen Date: Mon, 5 Aug 2024 16:16:08 -0400 Subject: [PATCH 8/9] Update comment --- .../configs/default/plugins/model_fitting/tests/test_plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jdaviz/configs/default/plugins/model_fitting/tests/test_plugin.py b/jdaviz/configs/default/plugins/model_fitting/tests/test_plugin.py index d16ab60149..27eb81bb18 100644 --- a/jdaviz/configs/default/plugins/model_fitting/tests/test_plugin.py +++ b/jdaviz/configs/default/plugins/model_fitting/tests/test_plugin.py @@ -158,7 +158,7 @@ def test_register_cube_model(cubeviz_helper, spectrum1d_cube): def test_fit_cube_no_wcs(cubeviz_helper): # This is like when user do something to a cube outside of Jdaviz # and then load it back into a new instance of Cubeviz for further analysis. - sp = Spectrum1D(flux=np.ones((7, 8, 9)) * u.nJy) # ny, nx, nz + sp = Spectrum1D(flux=np.ones((7, 8, 9)) * u.nJy) # nx, ny, nz cubeviz_helper.load_data(sp, data_label="test_cube") mf = cubeviz_helper.plugins['Model Fitting'] mf.create_model_component('Linear1D') From e53d12839a2a4842f781044dcc5b9dfe01bb1b43 Mon Sep 17 00:00:00 2001 From: Ricky O'Steen <39831871+rosteen@users.noreply.github.com> Date: Thu, 8 Aug 2024 11:24:19 -0400 Subject: [PATCH 9/9] Update jdaviz/configs/cubeviz/plugins/tests/test_parsers.py --- jdaviz/configs/cubeviz/plugins/tests/test_parsers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jdaviz/configs/cubeviz/plugins/tests/test_parsers.py b/jdaviz/configs/cubeviz/plugins/tests/test_parsers.py index 0af8484de2..8946cc283e 100644 --- a/jdaviz/configs/cubeviz/plugins/tests/test_parsers.py +++ b/jdaviz/configs/cubeviz/plugins/tests/test_parsers.py @@ -149,7 +149,7 @@ def test_spectrum3d_no_wcs_parse(cubeviz_helper): data = cubeviz_helper.app.data_collection[0] flux = data.get_component('flux') assert data.label.endswith('[FLUX]') - assert data.shape == (2, 3, 4) # y, x, z + assert data.shape == (2, 3, 4) # x, y, z assert isinstance(data.coords, PaddedSpectrumWCS) assert_array_equal(flux.data, 1) assert flux.units == 'nJy'