Skip to content

Commit

Permalink
Add yrange tool to profile viewer
Browse files Browse the repository at this point in the history
and add tests
  • Loading branch information
pllim committed Jun 8, 2023
1 parent 9b40553 commit a4f8a23
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 1 deletion.
81 changes: 81 additions & 0 deletions glue_jupyter/bqplot/profile/tests/test_viewer.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
from astropy.wcs import WCS

import numpy as np
import pytest
from numpy.testing import assert_allclose, assert_equal

from astropy import units as u

from glue.core import Data
from glue.core.edit_subset_mode import AndNotMode
from glue.core.roi import XRangeROI
from glue.core.subset import AndState, InvertState, RangeSubsetState
from glue.config import unit_converter, settings
from glue.plugins.wcs_autolinking.wcs_autolinking import WCSLink

Expand Down Expand Up @@ -61,6 +64,7 @@ def to_unit(self, data, cid, values, original_units, target_units):
equivalencies=u.spectral())


@pytest.mark.filterwarnings("ignore:No observer defined on WCS.*")
def test_unit_conversion(app):

settings.UNIT_CONVERTER = 'test-spectral'
Expand Down Expand Up @@ -157,3 +161,80 @@ def test_unit_conversion(app):

assert len(d2.subsets) == 1
assert_equal(d2.subsets[0].to_mask(), [0, 1, 1])


def test_composite_xrange(app):
session = app.session

wcs2 = WCS(naxis=1)
wcs2.wcs.ctype = ['WAVE']
wcs2.wcs.crval = [10]
wcs2.wcs.cdelt = [10]
wcs2.wcs.crpix = [1]
wcs2.wcs.cunit = ['cm']

d2 = Data(f2=[2000, 1000, 3000])
d2.get_component('f2').units = 'mJy'
d2.coords = wcs2

data_collection = session.data_collection
data_collection.append(d2)

viewer = app.profile1d(data=d2)
tool = viewer.toolbar.tools['bqplot:xrange']
tool.activate()
tool.interact.brushing = True
tool.interact.selected = [15, 35]
tool.interact.brushing = False

session.edit_subset_mode.mode = AndNotMode

tool.interact.brushing = True
tool.interact.selected = [25, 45]
tool.interact.brushing = False
tool.deactivate()

sbst = session.data_collection.subset_groups[0].subset_state
assert isinstance(sbst, AndState)
assert isinstance(sbst.state1, RangeSubsetState)
assert (isinstance(sbst.state2, InvertState) and
isinstance(sbst.state2.state1, RangeSubsetState))


def test_composite_yrange(app):
session = app.session

wcs2 = WCS(naxis=1)
wcs2.wcs.ctype = ['WAVE']
wcs2.wcs.crval = [10]
wcs2.wcs.cdelt = [10]
wcs2.wcs.crpix = [1]
wcs2.wcs.cunit = ['cm']

d2 = Data(f2=[2000, 1000, 3000])
d2.get_component('f2').units = 'mJy'
d2.coords = wcs2

data_collection = session.data_collection
data_collection.append(d2)

viewer = app.profile1d(data=d2)
tool = viewer.toolbar.tools['bqplot:yrange']

tool.activate()
tool.interact.brushing = True
tool.interact.selected = [1100, 1500]
tool.interact.brushing = False

session.edit_subset_mode.mode = AndNotMode

tool.interact.brushing = True
tool.interact.selected = [1450, 1550]
tool.interact.brushing = False
tool.deactivate()

sbst = session.data_collection.subset_groups[0].subset_state
assert isinstance(sbst, AndState)
assert isinstance(sbst.state1, RangeSubsetState)
assert (isinstance(sbst.state2, InvertState) and
isinstance(sbst.state2.state1, RangeSubsetState))
2 changes: 1 addition & 1 deletion glue_jupyter/bqplot/profile/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class BqplotProfileView(BqplotBaseView):
_layer_style_widget_cls = ProfileLayerStateWidget

tools = ['bqplot:home', 'bqplot:panzoom', 'bqplot:panzoom_x', 'bqplot:panzoom_y',
'bqplot:xrange']
'bqplot:xrange', 'bqplot:yrange']

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand Down

0 comments on commit a4f8a23

Please sign in to comment.