Skip to content

Commit

Permalink
Merge pull request spacetelescope#1860 from meeseeksmachine/auto-back…
Browse files Browse the repository at this point in the history
…port-of-pr-1856-on-v3.1.x

Backport PR spacetelescope#1856 on branch v3.1.x (FIX: shadowing/subsets after adding plugin data)
  • Loading branch information
pllim authored Nov 21, 2022
2 parents e88a294 + 5c59b3b commit 79467a2
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ Bug Fixes
Cubeviz
^^^^^^^

- Fix spatial-spectral highlighting after adding spectral data set (either manually or by loading
and results from plugins into the spectral-viewer) which had prevented new subsets from being
created. [#1856]

Imviz
^^^^^

Expand Down
28 changes: 22 additions & 6 deletions jdaviz/configs/cubeviz/plugins/viewers.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,22 +193,34 @@ def __init__(self, *args, **kwargs):
"flux_viewer_reference_name", "flux-viewer"
)

def _is_spatial_subset(self, layer):
# spatial subset layers will have the same data-label as the collapsed flux cube
ref_data_label = self.state.reference_data.label
return (isinstance(getattr(layer.layer, 'subset_state', None), RoiSubsetState)
and layer.layer.data.label == ref_data_label)

def _get_spatial_subset_layers(self):
return [ls for ls in self.state.layers
if isinstance(getattr(ls.layer, 'subset_state', None), RoiSubsetState)]
return [ls for ls in self.state.layers if self._is_spatial_subset(ls)]

def _is_spectral_subset(self, layer):
ref_data_label = self.layers[0].layer.data.label
return (isinstance(getattr(layer.layer, 'subset_state', None), RangeSubsetState)
and layer.layer.data.label == ref_data_label)

def _get_spectral_subset_layers(self):
return [ls for ls in self.state.layers
if isinstance(getattr(ls.layer, 'subset_state', None), RangeSubsetState)]
return [ls for ls in self.state.layers if self._is_spectral_subset(ls)]

def _get_marks_for_layers(self, layers):
layers_list = list(self.state.layers)
# here we'll assume that all custom marks are subclasses of Lines/GL but don't directly
# use Lines/LinesGL (so an isinstance check won't be sufficient here)
layer_marks = self.native_marks
# and now we'll assume that the marks are in the same order as the layers, this should
# be the case as long as the order isn't manually resorted
return [layer_marks[layers_list.index(layer)] for layer in layers]
# be the case as long as the order isn't manually resorted. If for any reason the layer
# is added but the mark has not yet been created, this will ignore that entry rather than
# raising an IndexError.
inds = [layers_list.index(layer) for layer in layers]
return [layer_marks[ind] for ind in inds if ind < len(layer_marks)]

def _on_subset_delete(self, msg):
# delete any ShadowSpatialSpectral mark for which either of the spectral or spatial marks
Expand All @@ -228,7 +240,11 @@ def _expected_subset_layer_default(self, layer_state):
"""
super()._expected_subset_layer_default(layer_state)

if not (self._is_spatial_subset(layer_state) or self._is_spectral_subset(layer_state)):
return

this_mark = self._get_marks_for_layers([layer_state])[0]

new_marks = []

if isinstance(layer_state.layer.subset_state, RoiSubsetState):
Expand Down
8 changes: 5 additions & 3 deletions jdaviz/core/marks.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,9 +406,11 @@ def spectral_subset_mark(self):
def _on_shadowing_changed(self, change):
if hasattr(self, '_spectral_mark_id'):
if change['name'] == 'y':
# force a copy or else we'll overwrite the mask to the spatial mark!
change['new'] = deepcopy(self.spatial_spectrum_mark.y)
change['new'][np.isnan(self.spectral_subset_mark.y)] = np.nan
# at initial setup, the arrays may not be populated yet
if self.spatial_spectrum_mark.y.shape == self.spectral_subset_mark.y.shape:
# force a copy or else we'll overwrite the mask to the spatial mark!
change['new'] = deepcopy(self.spatial_spectrum_mark.y)
change['new'][np.isnan(self.spectral_subset_mark.y)] = np.nan

elif change['name'] == 'visible':
# only show if BOTH shadowing marks are set to visible
Expand Down
4 changes: 4 additions & 0 deletions jdaviz/tests/test_subsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ def test_region_spectral_spatial(cubeviz_helper, spectral_cube_wcs):
cubeviz_helper.app.add_data_to_viewer('spectrum-viewer', 'Test Flux')
cubeviz_helper.app.add_data_to_viewer('flux-viewer', 'Test Flux')

# use gaussian smooth plugin as a regression test for
# https://github.com/spacetelescope/jdaviz/issues/1853
cubeviz_helper.plugins['Gaussian Smooth'].smooth(add_data=True)

spectrum_viewer = cubeviz_helper.app.get_viewer("spectrum-viewer")
spectrum_viewer.apply_roi(XRangeROI(5, 15.5))

Expand Down

0 comments on commit 79467a2

Please sign in to comment.