From e30ab1836b370c5d610e5cd396eba0a30058bd73 Mon Sep 17 00:00:00 2001 From: Jesse Averbukh Date: Thu, 24 Oct 2024 15:43:49 -0400 Subject: [PATCH 1/3] Revert combination mode to before import_region call --- .../default/plugins/subset_plugin/subset_plugin.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/jdaviz/configs/default/plugins/subset_plugin/subset_plugin.py b/jdaviz/configs/default/plugins/subset_plugin/subset_plugin.py index dc76774b29..f379a771c2 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 @@ -876,6 +878,7 @@ def _load_regions(self, regions, combination_mode=None, max_num_regions=None, # Remove selection of subset so that new one will be created self.app.session.edit_subset_mode.edit_subset = None # No overwrite next iteration self.app.session.edit_subset_mode.mode = SUBSET_MODES_PRETTY['new'] + elif combo_mode: self.combination_mode.selected = combo_mode @@ -967,6 +970,8 @@ def _load_regions(self, regions, combination_mode=None, max_num_regions=None, n_loaded += 1 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) From 84b7bbdd22872d3deb4fc21cd52f0e839350e5ee Mon Sep 17 00:00:00 2001 From: Jesse Averbukh Date: Fri, 25 Oct 2024 10:18:23 -0400 Subject: [PATCH 2/3] Add unit test for reverting to previous edit mode --- .../plugins/subset_plugin/tests/test_subset_plugin.py | 8 ++++++++ 1 file changed, 8 insertions(+) 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' From 4d67ceddc1d71aaa1b381e08f11c43bc06ada8fc Mon Sep 17 00:00:00 2001 From: Jesse Averbukh Date: Fri, 25 Oct 2024 15:27:36 -0400 Subject: [PATCH 3/3] Remove whitespace --- jdaviz/configs/default/plugins/subset_plugin/subset_plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jdaviz/configs/default/plugins/subset_plugin/subset_plugin.py b/jdaviz/configs/default/plugins/subset_plugin/subset_plugin.py index f379a771c2..e5097be284 100644 --- a/jdaviz/configs/default/plugins/subset_plugin/subset_plugin.py +++ b/jdaviz/configs/default/plugins/subset_plugin/subset_plugin.py @@ -878,7 +878,6 @@ def _load_regions(self, regions, combination_mode=None, max_num_regions=None, # Remove selection of subset so that new one will be created self.app.session.edit_subset_mode.edit_subset = None # No overwrite next iteration self.app.session.edit_subset_mode.mode = SUBSET_MODES_PRETTY['new'] - elif combo_mode: self.combination_mode.selected = combo_mode @@ -970,6 +969,7 @@ def _load_regions(self, regions, combination_mode=None, max_num_regions=None, n_loaded += 1 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