diff --git a/jdaviz/configs/mosviz/plugins/tools.py b/jdaviz/configs/mosviz/plugins/tools.py index a99ab5098c..f7955d8af0 100644 --- a/jdaviz/configs/mosviz/plugins/tools.py +++ b/jdaviz/configs/mosviz/plugins/tools.py @@ -21,18 +21,13 @@ def _is_matched_viewer(self, viewer): def _map_limits(self, from_viewer, to_viewer, limits={}): components = self.viewer.state.data_collection[0]._components # Determine cid for spectral axis - cid = None for key in components.keys(): - if 'Wavelength' in str(key): - cid = str(key) + strkey = str(key) + if 'Wavelength' in strkey or 'Wave' in strkey: + native_unit = u.Unit(self.viewer.state.data_collection[0].get_component(strkey).units) # noqa break - elif 'Wave' in str(key): - cid = str(key) - break - - if cid is not None: - native_unit = u.Unit(self.viewer.state.data_collection[0].get_component(cid).units) else: + # no matches found native_unit = '' current_display_unit = u.Unit(self.viewer.jdaviz_helper.app._get_display_unit('spectral')) diff --git a/jdaviz/configs/specviz/plugins/line_analysis/tests/test_line_analysis.py b/jdaviz/configs/specviz/plugins/line_analysis/tests/test_line_analysis.py index 7c055378d0..32cc5902e5 100644 --- a/jdaviz/configs/specviz/plugins/line_analysis/tests/test_line_analysis.py +++ b/jdaviz/configs/specviz/plugins/line_analysis/tests/test_line_analysis.py @@ -92,7 +92,7 @@ def test_cubeviz_units(cubeviz_helper, spectrum1d_cube_custom_fluxunit, is in flux/pix2 and flux/sr, and that the results remain consistant between translations of the spectral y axis flux<>surface brightness. """ - cube = spectrum1d_cube_custom_fluxunit(fluxunit=u.MJy / sq_angle_unit, + cube = spectrum1d_cube_custom_fluxunit(fluxunit=u.Jy / sq_angle_unit, shape=(25, 25, 4), with_uncerts=True) cubeviz_helper.load_data(cube, data_label="Test Cube") @@ -119,14 +119,14 @@ def test_cubeviz_units(cubeviz_helper, spectrum1d_cube_custom_fluxunit, la._obj.continuum_marks['right'].y] # change flux unit and make sure result stays the same after conversion - uc.flux_unit.selected = 'Jy' + uc.flux_unit.selected = 'MJy' marks_after = [la._obj.continuum_marks['left'].y, la._obj.continuum_marks['right'].y] # ensure continuum marks update when spectral_y is changed by # multiply converted continuum marks by expected scale factor (MJy -> Jy) - scaling_factor = 1e6 + scaling_factor = 1e-6 assert_allclose([mark * scaling_factor for mark in marks_before], marks_after, rtol=1e-5) # reset to test again after spectral_y_type is changed diff --git a/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.py b/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.py index f327070562..776981b76f 100644 --- a/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.py +++ b/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.py @@ -708,7 +708,6 @@ def import_trace(self, trace): else: # pragma: no cover raise NotImplementedError(f"trace of type {trace.__class__.__name__} not supported") - # UPDATE HERE @with_spinner('trace_spinner') def export_trace(self, add_data=False, **kwargs): """ diff --git a/jdaviz/core/tests/test_tools.py b/jdaviz/core/tests/test_tools.py index beea25e853..ee4e24864d 100644 --- a/jdaviz/core/tests/test_tools.py +++ b/jdaviz/core/tests/test_tools.py @@ -5,6 +5,7 @@ from astropy.nddata import NDData from numpy.testing import assert_allclose from photutils.datasets import make_4gaussians_image +from specutils import Spectrum1D from jdaviz.tests.test_utils import PHOTUTILS_LT_1_12_1 @@ -170,3 +171,29 @@ def test_unit_conversion_limits_update(specviz2d_helper, mos_spectrum2d): # test again when matching viewer's limits are reset assert_allclose(spec_viewer_lims_before, spec_viewer.get_limits()) assert_allclose(spec2d_viewer_lims_before, spec2d_viewer.get_limits()) + + +def test_match_limits_without_wave_component(specviz2d_helper): + data = np.zeros((5, 10)) + spec2d = Spectrum1D(flux=data*u.MJy) + specviz2d_helper.load_data(spec2d) + + spec_viewer = specviz2d_helper.app.get_viewer( + specviz2d_helper.app._jdaviz_helper._default_spectrum_viewer_reference_name) + spec2d_viewer = specviz2d_helper.app.get_viewer( + specviz2d_helper.app._jdaviz_helper._default_spectrum_2d_viewer_reference_name) + + spec_viewer_lims_before = spec_viewer.get_limits() + spec2d_viewer_lims_before = spec2d_viewer.get_limits() + + spec_viewer.reset_limits() + + # ensure limits reset when Wave nor Wavelength component is present + assert_allclose(spec_viewer_lims_before, spec_viewer.get_limits()) + assert_allclose(spec2d_viewer_lims_before, spec2d_viewer.get_limits()) + + spec2d_viewer.reset_limits() + + # test again when when limits are reset with spectrum2d-viewer + assert_allclose(spec_viewer_lims_before, spec_viewer.get_limits()) + assert_allclose(spec2d_viewer_lims_before, spec2d_viewer.get_limits())