Skip to content

Commit

Permalink
remove _obj when using get_regions
Browse files Browse the repository at this point in the history
  • Loading branch information
cshanahan1 committed Dec 13, 2024
1 parent 1bfa178 commit 54d7d63
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion jdaviz/configs/cubeviz/plugins/tests/test_regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_regions_pixel(self):
[my_reg], return_bad_regions=True)
assert len(bad_regions) == 0
self.verify_region_loaded('Subset 1', count=1)
assert len(self.cubeviz.plugins['Subset Tools']._obj.get_regions()) == 1
assert len(self.cubeviz.plugins['Subset Tools'].get_regions()) == 1

def test_regions_sky_has_wcs(self):
sky = SkyCoord(205.4397, 27.0035, unit='deg')
Expand Down
2 changes: 1 addition & 1 deletion jdaviz/configs/imviz/tests/test_linking.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def test_wcslink_affine_with_extras(self):
all_labels = [layer.layer.label for layer in self.viewer.state.layers]
# Retrieved subsets as sky regions from Subset plugin, and ensure they
# match what was loaded and that they are in sky coordinates.
subset_as_regions = self.imviz.plugins['Subset Tools']._obj.get_regions()
subset_as_regions = self.imviz.plugins['Subset Tools'].get_regions()
assert sorted(subset_as_regions) == ['Subset 1', 'Subset 2']
assert_allclose(subset_as_regions['Subset 1'].center.ra.deg, 337.519449)
assert_allclose(subset_as_regions['Subset 2'].center.ra.deg, 337.518498)
Expand Down
2 changes: 1 addition & 1 deletion jdaviz/configs/imviz/tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ def test_parse_jwst_nircam_level2(self, imviz_helper):
imviz_helper._apply_interactive_region('bqplot:rectangle',
(982, 1088),
(1008, 1077)) # Background
subsets = imviz_helper.plugins['Subset Tools']._obj.get_regions()
subsets = imviz_helper.plugins['Subset Tools'].get_regions()
assert list(subsets.keys()) == ['Subset 1', 'Subset 2'], subsets
# check that retrieved subsets-as-regions from subset plugin match what was loaded.
assert isinstance(subsets['Subset 1'], CirclePixelRegion)
Expand Down
30 changes: 15 additions & 15 deletions jdaviz/configs/imviz/tests/test_regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,21 @@ def test_regions_fully_out_of_bounds(self):
bad_regions = self.subset_plugin.import_region([my_reg], return_bad_regions=True)
assert len(bad_regions) == 0
self.verify_region_loaded('Subset 1')
assert len(self.imviz.plugins['Subset Tools']._obj.get_regions()) == 1
assert len(self.imviz.plugins['Subset Tools'].get_regions()) == 1

def test_regions_mask(self):
mask = np.zeros((10, 10), dtype=np.bool_)
mask[0, 0] = True
bad_regions = self.subset_plugin.import_region([mask], return_bad_regions=True)
assert len(bad_regions) == 0
self.verify_region_loaded('MaskedSubset 1')
assert self.imviz.plugins['Subset Tools']._obj.get_regions() == {}
assert self.imviz.plugins['Subset Tools'].get_regions() == {}

mask[1, 1] = True
bad_regions = self.subset_plugin.import_region([mask], return_bad_regions=True)
assert len(bad_regions) == 0
self.verify_region_loaded('MaskedSubset 2')
assert self.imviz.plugins['Subset Tools']._obj.get_regions() == {}
assert self.imviz.plugins['Subset Tools'].get_regions() == {}

# Also test deletion by label here.
self.imviz._delete_region('MaskedSubset 1')
Expand All @@ -103,7 +103,7 @@ def test_regions_mask(self):
bad_regions = self.subset_plugin.import_region([mask], return_bad_regions=True)
assert len(bad_regions) == 0
self.verify_region_loaded('MaskedSubset 3')
assert self.imviz.plugins['Subset Tools']._obj.get_regions() == {}
assert self.imviz.plugins['Subset Tools'].get_regions() == {}

# Deletion of non-existent label is silent no-op.
self.imviz._delete_region('foo')
Expand All @@ -115,7 +115,7 @@ def test_regions_pixel(self):
combination_mode='new')
assert len(bad_regions) == 0
self.verify_region_loaded('Subset 1')
assert len(self.imviz.plugins['Subset Tools']._obj.get_regions()) == 1
assert len(self.imviz.plugins['Subset Tools'].get_regions()) == 1

def test_regions_sky_has_wcs(self):
# Mimic interactive region (before)
Expand All @@ -141,7 +141,7 @@ def test_regions_sky_has_wcs(self):
# Check interactive regions. We do not check if the translation is correct,
# that check hopefully is already done in glue-astronomy.
# Apparently, static region ate up one number...
subsets = self.imviz.plugins['Subset Tools']._obj.get_regions()
subsets = self.imviz.plugins['Subset Tools'].get_regions()
assert list(subsets.keys()) == ['Subset 1', 'Subset 2', 'Subset 3', 'Subset 5', 'Subset 6'], subsets # noqa: E501
assert isinstance(subsets['Subset 1'], CirclePixelRegion)
assert isinstance(subsets['Subset 2'], CirclePixelRegion)
Expand All @@ -161,7 +161,7 @@ def test_regions_annulus_from_load_data(self):
# Test data is set up such that 1 pixel is 1 arcsec.
subset_radii = {"Subset 1": [0.5, 1], "Subset 2": [1, 3]}

subsets = self.imviz.plugins['Subset Tools']._obj.get_regions()
subsets = self.imviz.plugins['Subset Tools'].get_regions()
subset_names = sorted(subsets.keys())
assert subset_names == ['Subset 1', 'Subset 2']
for n in subset_names:
Expand All @@ -174,15 +174,15 @@ def test_photutils_pixel(self):
bad_regions = self.subset_plugin.import_region([my_aper], return_bad_regions=True)
assert len(bad_regions) == 0
self.verify_region_loaded('Subset 1')
assert len(self.imviz.plugins['Subset Tools']._obj.get_regions()) == 1
assert len(self.imviz.plugins['Subset Tools'].get_regions()) == 1

def test_photutils_sky_has_wcs(self):
sky = SkyCoord(ra=337.5202808, dec=-20.833333059999998, unit='deg')
my_aper_sky = SkyCircularAperture(sky, 0.5 * u.arcsec)
bad_regions = self.subset_plugin.import_region([my_aper_sky], return_bad_regions=True)
assert len(bad_regions) == 0
self.verify_region_loaded('Subset 1')
assert len(self.imviz.plugins['Subset Tools']._obj.get_regions()) == 1
assert len(self.imviz.plugins['Subset Tools'].get_regions()) == 1


class TestLoadRegionsFromFile(BaseRegionHandler):
Expand All @@ -204,7 +204,7 @@ def test_ds9_load_all(self, imviz_helper):
assert len(bad_regions) == 1

# Will load 8/9 and 7 of that become ROIs.
subsets = imviz_helper.plugins['Subset Tools']._obj.get_regions()
subsets = imviz_helper.plugins['Subset Tools'].get_regions()
assert list(subsets.keys()) == ['Subset 1', 'Subset 2', 'Subset 3',
'Subset 4', 'Subset 5', 'Subset 6', 'Subset 7'], subsets

Expand All @@ -217,7 +217,7 @@ def test_ds9_load_two_good(self, imviz_helper):
bad_regions = imviz_helper.plugins['Subset Tools'].import_region(
self.region_file, combination_mode='new', max_num_regions=2, return_bad_regions=True)
assert len(bad_regions) == 0
subsets = imviz_helper.plugins['Subset Tools']._obj.get_regions()
subsets = imviz_helper.plugins['Subset Tools'].get_regions()
assert list(subsets.keys()) == ['Subset 1', 'Subset 2'], subsets
self.verify_region_loaded('MaskedSubset 1', count=0)

Expand All @@ -227,7 +227,7 @@ def test_ds9_load_one_bad(self, imviz_helper):
bad_regions = imviz_helper.plugins['Subset Tools'].import_region(
self.raw_regions[6], return_bad_regions=True)
assert len(bad_regions) == 1
assert imviz_helper.plugins['Subset Tools']._obj.get_regions() == {}
assert imviz_helper.plugins['Subset Tools'].get_regions() == {}
self.verify_region_loaded('MaskedSubset 1', count=0)

def test_ds9_load_one_good_one_bad(self, imviz_helper):
Expand All @@ -237,7 +237,7 @@ def test_ds9_load_one_good_one_bad(self, imviz_helper):
[self.raw_regions[3], self.raw_regions[6]], return_bad_regions=True)
assert len(bad_regions) == 1

subsets = imviz_helper.plugins['Subset Tools']._obj.get_regions()
subsets = imviz_helper.plugins['Subset Tools'].get_regions()
assert list(subsets.keys()) == ['Subset 1'], subsets
self.verify_region_loaded('MaskedSubset 1', count=0)

Expand All @@ -250,7 +250,7 @@ def test_annulus(self):
self.imviz._apply_interactive_region('bqplot:truecircle', (2, 2), (7, 7))

# At this point, there should be two normal circles.
subsets = self.imviz.plugins['Subset Tools']._obj.get_regions()
subsets = self.imviz.plugins['Subset Tools'].get_regions()
assert list(subsets.keys()) == ['Subset 1', 'Subset 2'], subsets
assert isinstance(subsets['Subset 1'], CirclePixelRegion)
assert isinstance(subsets['Subset 2'], CirclePixelRegion)
Expand All @@ -266,7 +266,7 @@ def test_annulus(self):
new_subset = subset_groups[0].subset_state & ~subset_groups[1].subset_state
self.viewer.apply_subset_state(new_subset)

subsets = self.imviz.plugins['Subset Tools']._obj.get_regions()
subsets = self.imviz.plugins['Subset Tools'].get_regions()
assert len(self.imviz.app.data_collection.subset_groups) == 3
assert list(subsets.keys()) == ['Subset 1', 'Subset 2', 'Subset 3'], subsets
assert isinstance(subsets['Subset 1'], CirclePixelRegion)
Expand Down
16 changes: 8 additions & 8 deletions jdaviz/configs/specviz/tests/test_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def test_get_spectral_regions_two(self):
7800*self.spec.spectral_axis.unit))
self.spec_app.plugins['Subset Tools'].import_region(subset, combination_mode='or')

spec_region = self.spec_app.plugins['Subset Tools']._obj.get_regions()
spec_region = self.spec_app.plugins['Subset Tools'].get_regions()

assert len(spec_region['Subset 1'].subregions) == 2

Expand All @@ -149,7 +149,7 @@ def test_get_spectral_regions_three(self):
7800*self.spec.spectral_axis.unit))
self.spec_app.plugins['Subset Tools'].import_region(subset, combination_mode='or')

spec_region = self.spec_app.plugins['Subset Tools']._obj.get_regions()
spec_region = self.spec_app.plugins['Subset Tools'].get_regions()

assert len(spec_region['Subset 1'].subregions) == 3
# Assert correct values for test with 3 subregions
Expand All @@ -175,7 +175,7 @@ def test_get_spectral_regions_does_not_raise_value_error(self):
6*self.spec.spectral_axis.unit))
self.spec_app.plugins['Subset Tools'].import_region(subset, combination_mode='or')

spec_region = self.spec_app.plugins['Subset Tools']._obj.get_regions()
spec_region = self.spec_app.plugins['Subset Tools'].get_regions()
assert_quantity_allclose(spec_region['Subset 1'].subregions[0][0].value,
1, atol=1e-5)
assert_quantity_allclose(spec_region['Subset 1'].subregions[0][1].value,
Expand All @@ -196,7 +196,7 @@ def test_get_spectral_regions_composite_region(self):
self.spec_app.plugins['Subset Tools'].import_region(
subset, combination_mode=['new', 'andnot', 'and'])

spec_region = self.spec_app.plugins['Subset Tools']._obj.get_regions()
spec_region = self.spec_app.plugins['Subset Tools'].get_regions()

assert len(spec_region['Subset 1'].subregions) == 1
# Assert correct values for test with 3 subregions
Expand All @@ -215,7 +215,7 @@ def test_get_spectral_regions_composite_region_multiple_and_nots(self):
self.spec_app.plugins['Subset Tools'].import_region(
subset, combination_mode=['new', 'andnot', 'andnot'])

spec_region = self.spec_app.plugins['Subset Tools']._obj.get_regions()
spec_region = self.spec_app.plugins['Subset Tools'].get_regions()

assert len(spec_region['Subset 1'].subregions) == 3
# Assert correct values for test with 3 subregions
Expand Down Expand Up @@ -276,7 +276,7 @@ def test_get_spectral_regions_unit(specviz_helper, spectrum1d):
7000 * spectrum1d.spectral_axis.unit)
specviz_helper.plugins['Subset Tools'].import_region(subset)

subsets = specviz_helper.plugins['Subset Tools']._obj.get_regions()
subsets = specviz_helper.plugins['Subset Tools'].get_regions()
reg = subsets.get('Subset 1')

assert spectrum1d.spectral_axis.unit == reg.lower.unit
Expand Down Expand Up @@ -319,12 +319,12 @@ def test_get_spectral_regions_unit_conversion(specviz_helper, spectrum1d):
specviz_helper.plugins['Subset Tools'].import_region(subset)

# Retrieve the Subset
ss = specviz_helper.plugins['Subset Tools']._obj.get_regions(use_display_units=False)
ss = specviz_helper.plugins['Subset Tools'].get_regions(use_display_units=False)
reg = ss.get('Subset 1')
assert reg.lower.unit == u.Angstrom
assert reg.upper.unit == u.Angstrom

ss = specviz_helper.plugins['Subset Tools']._obj.get_regions(use_display_units=True)
ss = specviz_helper.plugins['Subset Tools'].get_regions(use_display_units=True)
reg = ss.get('Subset 1')
assert reg.lower.unit == u.um
assert reg.upper.unit == u.um
Expand Down

0 comments on commit 54d7d63

Please sign in to comment.