Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add composite subset fixes #2291

Merged
merged 6 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ Cubeviz
- Moment Map plugin now writes FITS file to working directory if no path provided
in standalone mode. [#2264]

- Fixes detection of spatial vs spectral subsets for composite subsets. [#2207, #2266, #2291]

Imviz
^^^^^

Expand Down
8 changes: 6 additions & 2 deletions jdaviz/configs/imviz/plugins/coords_info/coords_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from astropy import units as u
from glue.core import BaseData
from glue.core.subset import RoiSubsetState
from glue.core.subset_group import GroupedSubset
from glue_jupyter.bqplot.image.layer_artist import BqplotImageSubsetLayerArtist

Expand All @@ -17,6 +16,7 @@
from jdaviz.core.marks import PluginScatter
from jdaviz.core.registries import tool_registry
from jdaviz.core.template_mixin import TemplateMixin, DatasetSelectMixin
from jdaviz.utils import get_subset_type

__all__ = ['CoordsInfo']

Expand Down Expand Up @@ -443,7 +443,11 @@
continue

if isinstance(lyr.layer, GroupedSubset):
if not isinstance(lyr.layer.subset_state, RoiSubsetState):
subset_state = getattr(lyr.layer, 'subset_state', None)
if subset_state is None:
return False

Check warning on line 448 in jdaviz/configs/imviz/plugins/coords_info/coords_info.py

View check run for this annotation

Codecov / codecov/patch

jdaviz/configs/imviz/plugins/coords_info/coords_info.py#L448

Added line #L448 was not covered by tests
javerbukh marked this conversation as resolved.
Show resolved Hide resolved
subset_type = get_subset_type(subset_state)
if subset_type == 'spectral':
# then this is a SPECTRAL subset
continue
# For use later in data retrieval
Expand Down
3 changes: 2 additions & 1 deletion jdaviz/configs/specviz/plugins/viewers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from jdaviz.core.linelists import load_preset_linelist, get_available_linelists
from jdaviz.core.freezable_state import FreezableProfileViewerState
from jdaviz.configs.default.plugins.viewers import JdavizViewerMixin
from jdaviz.utils import get_subset_type

__all__ = ['SpecvizProfileView']

Expand Down Expand Up @@ -377,7 +378,7 @@ def add_data(self, data, color=None, alpha=None, **layer_state):
# that new data entries (from model fitting or gaussian smooth, etc) will only be spectra
# and all subsets affected will be spectral
for layer in self.state.layers:
if "Subset" in layer.layer.label and layer.layer.data.label == data.label:
if get_subset_type(layer.layer) == 'spectral' and layer.layer.data.label == data.label:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think get_subset_type assumes the input is a subset... does the fact that this works depend on the assumption that spectral is defined first in that function (do we need some way to still detect if the layer is a subset at all vs actual data)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_subset_type has a check to start if the layer.layer object has attribute "subset_state" and if not it returns None. I added a check to this if statement though to make it more clear that this should only accept layer's associated with subsets.

layer.linewidth = 3

return result
Expand Down
6 changes: 3 additions & 3 deletions jdaviz/core/template_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,9 @@ def _delete_subset(self, subset):
self._apply_default_selection()

def _is_valid_item(self, subset):
def is_spectral(subset):
return _subset_type(subset) == 'spectral'

def is_spatial(subset):
return _subset_type(subset) == 'spatial'

Expand All @@ -1042,9 +1045,6 @@ def is_not_annulus(subset):
return super()._is_valid_item(subset, locals())

def _update_subset(self, subset, attribute=None):
if self._allowed_type is not None and get_subset_type(subset) != self._allowed_type:
return

if subset.label not in self.labels:
# NOTE: this logic will need to be revisited if generic renaming of subsets is added
# see https://github.com/spacetelescope/jdaviz/pull/1175#discussion_r829372470
Expand Down
4 changes: 2 additions & 2 deletions jdaviz/tests/test_subsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def test_region_spectral_spatial(cubeviz_helper, spectral_cube_wcs):
flux_viewer.toolbar.active_tool = flux_viewer.toolbar.tools['bqplot:rectangle']
flux_viewer.apply_roi(RectangularROI(1, 3.5, -0.2, 3.3))

assert len([m for m in spectrum_viewer.figure.marks if isinstance(m, ShadowSpatialSpectral)]) == 1 # noqa
assert len([m for m in spectrum_viewer.figure.marks if isinstance(m, ShadowSpatialSpectral)]) == 2 # noqa
Comment on lines -202 to +204
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this (and the next set of changes to line 229) is only temporary until #2292 is addressed, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming Gaussian Smooth stays a cube, this is the correct number for the amount of ShadowSpatialSpectral marks. A spatial subset is applied to the flux cube AND the smoothed cube, which creates two collapsed spectra in the spectrum viewer. Each of those spectra then has a spectral subset applied to them, creating 2 shadow marks. If you add another spectral subset, that number goes up to 4. If you delete the smooth cube, that number goes back down to 2 since you still have the flux cube's spatial subset intersecting with the two spectral subsets.


subsets = cubeviz_helper.app.get_subsets(spectral_only=True)
reg = subsets.get('Subset 1')
Expand All @@ -226,7 +226,7 @@ def test_region_spectral_spatial(cubeviz_helper, spectral_cube_wcs):
spectrum_viewer.toolbar.active_tool = spectrum_viewer.toolbar.tools['jdaviz:panzoom']
spectrum_viewer.toolbar.active_tool = spectrum_viewer.toolbar.tools['bqplot:xrange']
spectrum_viewer.apply_roi(XRangeROI(3, 16))
assert len([m for m in spectrum_viewer.figure.marks if isinstance(m, ShadowSpatialSpectral)]) == 2 # noqa
assert len([m for m in spectrum_viewer.figure.marks if isinstance(m, ShadowSpatialSpectral)]) == 4 # noqa


def test_disjoint_spatial_subset(cubeviz_helper, spectral_cube_wcs):
Expand Down
Loading