Skip to content

Commit

Permalink
Merge pull request #2034 from duytnguyendtn/auto-backport-of-pr-2023-…
Browse files Browse the repository at this point in the history
…on-v3.3.x

Manual Backport PR #2023 on branch v3.3.x (Fix 2D smooth visibility bug by utilizing SpectralExtraction linking logic)
  • Loading branch information
duytnguyendtn authored Feb 24, 2023
2 parents c77833d + 12545c7 commit 8dec9ce
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
^^^^^^^

Expand Down
6 changes: 5 additions & 1 deletion jdaviz/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import numpy as np
import pytest
from astropy.utils.exceptions import AstropyUserWarning
from specutils import Spectrum1D
Expand Down Expand Up @@ -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])
12 changes: 12 additions & 0 deletions jdaviz/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
'''
Expand Down

0 comments on commit 8dec9ce

Please sign in to comment.