From 73c99ad7885420b57e434fcc778680debd06b93d Mon Sep 17 00:00:00 2001 From: Jesse Averbukh Date: Tue, 16 Jul 2024 09:09:34 -0400 Subject: [PATCH] Move all subset importing under import_region --- .../default/plugins/subset_plugin/subset_plugin.py | 9 ++------- .../plugins/subset_plugin/tests/test_subset_plugin.py | 11 +++++++---- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/jdaviz/configs/default/plugins/subset_plugin/subset_plugin.py b/jdaviz/configs/default/plugins/subset_plugin/subset_plugin.py index b8ac0fce6a..0852205d03 100644 --- a/jdaviz/configs/default/plugins/subset_plugin/subset_plugin.py +++ b/jdaviz/configs/default/plugins/subset_plugin/subset_plugin.py @@ -690,20 +690,16 @@ def import_region(self, spec_region): self._import_regions_list(spec_region) elif isinstance(spec_region, dict): for key, value in spec_region.items(): - print(key) - self._import_regions_list(value) + self.import_region(value) elif isinstance(spec_region, str): try: - dict_region = json.load(spec_region) + dict_region = json.loads(spec_region) except ValueError: raise ValueError self.import_region(dict_region) elif isinstance(spec_region, SpectralRegion): self._import_spectral_regions(spec_region) - def _import_spectral_regions(self, spec_region): - raise NotImplementedError - def _import_regions_list(self, spec_region): viewer_name = self.app._jdaviz_helper._default_flux_viewer_reference_name flux_viewer = self.app.get_viewer(viewer_name) @@ -713,4 +709,3 @@ def _import_regions_list(self, spec_region): else: self.app.session.edit_subset_mode.mode = SUBSET_MODES[subregion['glue_state']] flux_viewer.apply_roi(region_translators.regions2roi(subregion['region'])) - 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 77e0930b44..44bd8cce8c 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 @@ -1,5 +1,6 @@ import warnings import pytest +import json import numpy as np from astropy.nddata import NDData @@ -206,6 +207,7 @@ def test_import_spectral_region(cubeviz_helper, spectrum1d_cube, spec_regions, m assert len(subsets) == len_subsets assert len(subsets['Subset 1']) == len_subregions + test_subset_dict = {'Subset 1': [ {'name': 'TrueCircularROI', 'glue_state': 'AndState', @@ -228,7 +230,8 @@ def test_import_spectral_region(cubeviz_helper, spectrum1d_cube, spec_regions, m 'region': CircleAnnulusPixelRegion(center=PixCoord(x=30.452190399169922, y=22.070573806762695), inner_radius=2.4145185947418213, outer_radius=4.829037189483643), 'sky_region': None, 'subset_state': None}], - 'Subset 3': SpectralRegion(6.939254409861322 * u.um, 7.224590119773996 * u.um) } + 'Subset 3': SpectralRegion(6.939254409861322 * u.um, 7.224590119773996 * u.um) +} test_subset_string = str(test_subset_dict) @@ -248,9 +251,9 @@ def test_import_spectral_region(cubeviz_helper, spectrum1d_cube, spec_regions, m @pytest.mark.parametrize( ('spec_region', 'len_subsets', 'len_subregions'), - # [(test_subset_dict, 3, 3), - # (test_subset_string, 3, 3), - [(region, 1, 2)] + [(test_subset_dict, 3, 3), + # (test_subset_string, 3, 3), + (region, 1, 2)] ) def test_add_subset_with_import_region(cubeviz_helper, spectrum1d_cube, spec_region, len_subsets, len_subregions): with warnings.catch_warnings():