Skip to content

Commit

Permalink
Test get_data when changing a subsets label (#2609)
Browse files Browse the repository at this point in the history
* Test get_data when changing a subsets label

* Add test for subset renaming to data name

* Check mask instead of flux and spectral axis

* Fix codestyle

* Fix np where statement

* Use actual array comparison
  • Loading branch information
javerbukh authored Dec 15, 2023
1 parent 71a943b commit 8128788
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions jdaviz/tests/test_subsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -951,3 +951,38 @@ def test_no_wcs_sky_regions(self, imviz_helper):
imviz_helper.app.get_viewer('imviz-0').apply_roi(CircularROI(25, 25, 10))
subsets = imviz_helper.app.get_subsets(include_sky_region=True)
assert subsets['Subset 1'][0]['sky_region'] is None

def test_subset_renaming(self, specviz_helper, spectrum1d):
specviz_helper.load_data(spectrum1d, 'myfile')
spectrum_viewer_name = specviz_helper._default_spectrum_viewer_reference_name
viewer = specviz_helper.app.get_viewer(spectrum_viewer_name)

viewer.apply_roi(XRangeROI(6200, 7200))
get_data_no_sub = specviz_helper.get_data('myfile')
get_data_1 = specviz_helper.get_data('myfile', spectral_subset='Subset 1')

get_data_1_mask = np.where(~get_data_1.mask)

# Retrieving data with no subset means mask is None
assert get_data_no_sub.mask is None
assert len(get_data_1_mask[0]) > 0

# rename subset to 'diffname'
subset_group = specviz_helper.app.data_collection.subset_groups
subset_group[0].label = 'diffname'
get_data_2 = specviz_helper.get_data('myfile', spectral_subset='diffname')

assert_quantity_allclose(get_data_1.flux, get_data_2.flux)
assert_quantity_allclose(get_data_1.spectral_axis, get_data_2.spectral_axis)
get_data_2_mask = np.where(~get_data_2.mask)
assert (get_data_1_mask[0] == get_data_2_mask[0]).all()

# when we officially implement subset renaming in jdaviz, we will want
# to be aware of the case of naming subsets after existing data
# and handle it appropriately
subset_group = specviz_helper.app.data_collection.subset_groups
subset_group[0].label = 'myfile'
get_data_3 = specviz_helper.get_data('myfile', spectral_subset='myfile')

get_data_3_mask = np.where(~get_data_3.mask)
assert (get_data_1_mask[0] == get_data_3_mask[0]).all()

0 comments on commit 8128788

Please sign in to comment.