Skip to content

Commit

Permalink
Revert combination mode to before import_region call (#3255)
Browse files Browse the repository at this point in the history
* Revert combination mode to before import_region call

* Add unit test for reverting to previous edit mode

* Remove whitespace
  • Loading branch information
javerbukh authored and rosteen committed Oct 29, 2024
1 parent 8014672 commit 12a409d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
11 changes: 8 additions & 3 deletions jdaviz/configs/default/plugins/subset_plugin/subset_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -860,9 +860,11 @@ def _load_regions(self, regions, combination_mode=None, max_num_regions=None,
if combo_mode_is_list and len(combination_mode) != (len(regions)):
raise ValueError("list of mode must be size of regions")
elif combo_mode_is_list:
for mode in combination_mode:
if mode not in COMBO_OPTIONS:
raise ValueError(f"{mode} not one of {COMBO_OPTIONS}")
unknown_options = list(set(combination_mode) - set(COMBO_OPTIONS))
if len(unknown_options) > 0:
raise ValueError(f"{unknown_options} not one of {COMBO_OPTIONS}")

previous_mode = self.app.session.edit_subset_mode.mode

for index, region in enumerate(regions):
# Set combination mode for how region will be applied to current subset
Expand Down Expand Up @@ -968,6 +970,9 @@ def _load_regions(self, regions, combination_mode=None, max_num_regions=None,
if max_num_regions is not None and n_loaded >= max_num_regions:
break

# Revert edit mode to before the import_region call
self.app.session.edit_subset_mode.mode = previous_mode

n_reg_in = len(regions)
n_reg_bad = len(bad_regions)
if n_loaded == 0:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import astropy.units as u
from specutils import SpectralRegion
from glue.core.roi import EllipticalROI, CircularROI, CircularAnnulusROI, RectangularROI
from glue.core.edit_subset_mode import ReplaceMode, OrMode
from numpy.testing import assert_allclose

from jdaviz.configs.default.plugins.subset_plugin import utils
Expand Down Expand Up @@ -198,6 +199,7 @@ def test_import_spectral_region(cubeviz_helper, spectrum1d_cube, spec_regions, m
subsets = cubeviz_helper.app.get_subsets()
assert len(subsets) == len_subsets
assert len(subsets['Subset 1']) == len_subregions
assert cubeviz_helper.app.session.edit_subset_mode.mode == ReplaceMode


def test_import_spectral_regions_file(cubeviz_helper, spectrum1d_cube, tmp_path):
Expand All @@ -216,5 +218,11 @@ def test_import_spectral_regions_file(cubeviz_helper, spectrum1d_cube, tmp_path)
subsets = cubeviz_helper.app.get_subsets()
assert len(subsets['Subset 1']) == 2

subset2 = (SpectralRegion(5.772486091213352 * u.um, 6.052963676101135 * u.um) +
SpectralRegion(5.8 * u.um, 5.9 * u.um))
plg.import_region(subset2, combination_mode=['new', 'andnot'])

assert cubeviz_helper.app.session.edit_subset_mode.mode == OrMode

with pytest.raises(ValueError, match='test not one of'):
plg.combination_mode.selected = 'test'

0 comments on commit 12a409d

Please sign in to comment.