Skip to content

Commit

Permalink
TST: Fix test_get_regions_composite
Browse files Browse the repository at this point in the history
  • Loading branch information
pllim committed Dec 31, 2024
1 parent a8b3e03 commit e5ac44b
Showing 1 changed file with 25 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import warnings
import pytest

import numpy as np
import pytest
from astropy import units as u
from astropy.nddata import NDData
import astropy.units as u
from regions import CirclePixelRegion, PixCoord
from specutils import SpectralRegion
from glue.core.edit_subset_mode import ReplaceMode, OrMode, NewMode
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 regions import CirclePixelRegion, PixCoord
from specutils import SpectralRegion

from jdaviz.configs.default.plugins.subset_tools import utils
from jdaviz.core.region_translators import regions2roi


@pytest.mark.filterwarnings('ignore')
def test_plugin(specviz_helper, spectrum1d):
specviz_helper.load_data(spectrum1d)
with warnings.catch_warnings():
warnings.simplefilter("ignore")
specviz_helper.load_data(spectrum1d)
p = specviz_helper.plugins['Subset Tools']

# regression test for https://github.com/spacetelescope/jdaviz/issues/1693
Expand Down Expand Up @@ -276,8 +277,7 @@ def test_get_regions(cubeviz_helper, spectrum1d_cube, imviz_helper):
plg.get_regions(region_type='fail')


@pytest.mark.xfail(reason='Unskip once issue XXXX is resolved.')
def test_get_regions_composite(cubeviz_helper, spectrum1d_cube):
def test_get_regions_composite(imviz_helper):
"""
If you apply a circular subset mask to a circular subset to make a
composite subset, and they aren't exactly aligned at the center to form a
Expand All @@ -287,34 +287,31 @@ def test_get_regions_composite(cubeviz_helper, spectrum1d_cube):
``app.get_subsets``. This test ensures that a region is returned through
both ``app.get_subsets`` and ``get_regions``.
"""
cubeviz_helper.load_data(spectrum1d_cube)
plg = cubeviz_helper.plugins['Subset Tools']

# For some reason, Subset 2 disappears after the third subset is applied
# when loaded this way. Uncomment to replace _apply_interactive_region once
# JDAT-5014 is resolved
# plg.import_region(CirclePixelRegion(center=PixCoord(x=96.0, y=96.0),
# radius=45.0), combination_mode='new')
# plg.import_region(CirclePixelRegion(center=PixCoord(x=95.0, y=95.0),
# radius=25.0), combination_mode='new')
a = np.ones((200, 200))
imviz_helper.load_data(a, data_label="test")
plg = imviz_helper.plugins['Subset Tools']

# apply two circular subsets
cubeviz_helper._apply_interactive_region('bqplot:truecircle', (51, 51), (141, 141))
cubeviz_helper._apply_interactive_region('bqplot:truecircle', (70, 70), (120, 120))
plg.import_region(CirclePixelRegion(center=PixCoord(x=96.0, y=96.0),
radius=45.0), combination_mode='new')
plg.import_region(CirclePixelRegion(center=PixCoord(x=95.0, y=95.0),
radius=25.0), combination_mode='new')

# apply composite subset created from two existing circular subsets
subset_groups = cubeviz_helper.app.data_collection.subset_groups
imviz_helper.app.session.edit_subset_mode._mode = NewMode
subset_groups = imviz_helper.app.data_collection.subset_groups
new_subset = subset_groups[0].subset_state & ~subset_groups[1].subset_state
cubeviz_helper.default_viewer._obj.apply_subset_state(new_subset)
imviz_helper.default_viewer._obj.apply_subset_state(new_subset)

# make sure Subset 3, the composite subset, is retrieved.
# FIXME: make sure Subset 3, the composite subset, is retrieved.
# This needs https://jira.stsci.edu/browse/JDAT-5035
regions = plg.get_regions()
ss_labels = ['Subset 1', 'Subset 2', 'Subset 3']
assert np.all([regions[ss] for ss in ss_labels])
assert sorted(regions) == ["Subset 1", "Subset 2"] # What we have
# assert sorted(regions) == ["Subset 1", "Subset 2", "Subset 3"] # What we want after JDAT-5035

# make sure the same regions are returned by app.get_subsets
get_subsets = cubeviz_helper.app.get_subsets()
assert np.all([get_subsets[ss][0]['region'] == regions[ss] for ss in ss_labels])
get_subsets = imviz_helper.app.get_subsets()
assert sorted(get_subsets) == ["Subset 1", "Subset 2", "Subset 3"]


def test_check_valid_subset_label(imviz_helper):
Expand Down Expand Up @@ -353,7 +350,6 @@ def test_rename_subset(cubeviz_helper, spectrum1d_cube):

plg.rename_subset("Subset 1", "Test Rename")

print(cubeviz_helper.app.data_collection)
assert plg.subset.choices == ['Create New', 'Test Rename', 'Subset 2']
assert cubeviz_helper.app.data_collection[-1].label == "Spectrum (Test Rename, sum)"

Expand Down

0 comments on commit e5ac44b

Please sign in to comment.