diff --git a/jdaviz/configs/default/plugins/subset_plugin/subset_plugin.py b/jdaviz/configs/default/plugins/subset_plugin/subset_plugin.py index dc76774b29..e5097be284 100644 --- a/jdaviz/configs/default/plugins/subset_plugin/subset_plugin.py +++ b/jdaviz/configs/default/plugins/subset_plugin/subset_plugin.py @@ -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 @@ -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: diff --git a/jdaviz/configs/default/plugins/subset_plugin/tests/test_subset_plugin.py b/jdaviz/configs/default/plugins/subset_plugin/tests/test_subset_plugin.py index 825f9a366a..0f8a4c563b 100644 --- a/jdaviz/configs/default/plugins/subset_plugin/tests/test_subset_plugin.py +++ b/jdaviz/configs/default/plugins/subset_plugin/tests/test_subset_plugin.py @@ -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 @@ -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): @@ -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'