Skip to content

Commit

Permalink
Move all subset importing under import_region
Browse files Browse the repository at this point in the history
  • Loading branch information
javerbukh committed Jul 16, 2024
1 parent 6af335b commit 73c99ad
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
9 changes: 2 additions & 7 deletions jdaviz/configs/default/plugins/subset_plugin/subset_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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']))

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import warnings
import pytest
import json

import numpy as np
from astropy.nddata import NDData
Expand Down Expand Up @@ -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',
Expand All @@ -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)

Expand All @@ -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():
Expand Down

0 comments on commit 73c99ad

Please sign in to comment.