diff --git a/CHANGES.rst b/CHANGES.rst index 7b0bee45c3..57cdf158ef 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -9,6 +9,8 @@ Bug Fixes * Loading valid data no longer emits JSON serialization warnings. [#2011] +* Fixed linking issue preventing smoothed spectrum from showing in Specviz2D. [#2023] + Cubeviz ^^^^^^^ diff --git a/jdaviz/app.py b/jdaviz/app.py index 0dd2bbe75a..1ab849f8d1 100644 --- a/jdaviz/app.py +++ b/jdaviz/app.py @@ -424,7 +424,11 @@ def _link_new_data(self, reference_data=None, data_to_be_linked=None): LinkSame(linked_data.components[0], ref_data.components[1])] dc.add_link(links) return - elif linked_data.meta.get('Plugin', None) == 'SpectralExtraction': + elif (linked_data.meta.get('Plugin', None) == 'SpectralExtraction' or + (linked_data.meta.get('Plugin', None) == ('GaussianSmooth') and + linked_data.ndim < 3 and # Cube linking requires special logic. See below + ref_data.ndim < 3) + ): links = [LinkSame(linked_data.components[0], ref_data.components[0]), LinkSame(linked_data.components[1], ref_data.components[1])] dc.add_link(links) 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 c6b67fcac6..c163690dd2 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 @@ -1,3 +1,4 @@ +import numpy as np import pytest from astropy.utils.exceptions import AstropyUserWarning from specutils import Spectrum1D @@ -168,3 +169,30 @@ def test_spectrum1d_smooth(specviz_helper, spectrum1d): assert spec_viewer.label_mouseover.world_ra_deg == '' assert spec_viewer.label_mouseover.world_dec_deg == '' assert spec_viewer.label_mouseover.icon == '' + + +def test_spectrum2d_smooth(specviz2d_helper, spectrum2d): + data_label = 'test' + dc = specviz2d_helper.app.data_collection + specviz2d_helper.load_data(spectrum_2d=spectrum2d, spectrum_2d_label=data_label) + + gs_plugin = specviz2d_helper.plugins['Gaussian Smooth'] + + # The Autocollapsed spectrum is given the label of "Spectrum 1D by default" + smooth_source_dataset = "Spectrum 1D" + gs_plugin.dataset = smooth_source_dataset + test_stddev_level = 100.0 + gs_plugin.stddev = test_stddev_level + gs_plugin.smooth() + + assert len(dc) == 3 + assert dc[2].label == f'{smooth_source_dataset} smooth stddev-{test_stddev_level}' + + # Ensure all marks were created properly (i.e. not in their initialized state) + # [0,1] is the default (initialization) value for the marks + marks = specviz2d_helper.app.get_viewer('spectrum-viewer').native_marks + + assert len(marks) == 2 + for mark in marks: + np.testing.assert_allclose(mark.x, spectrum2d.spectral_axis.value) + assert not np.array_equal(mark.y, [0, 1]) diff --git a/jdaviz/conftest.py b/jdaviz/conftest.py index a5f203958a..c7fca99a73 100644 --- a/jdaviz/conftest.py +++ b/jdaviz/conftest.py @@ -226,6 +226,18 @@ def mos_spectrum1d(): return Spectrum1D(spectral_axis=spec_axis, flux=flux) +@pytest.fixture +def spectrum2d(): + ''' + A simple 2D Spectrum1D with a center "trace" array rising from 0 to 10 + with two "zero array" buffers above and below + ''' + data = np.zeros((5, 10)) + data[3] = np.arange(10) + + return Spectrum1D(flux=data*u.MJy, spectral_axis=data[3]*u.um) + + @pytest.fixture def mos_spectrum2d(): '''