Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
astrofrog committed Feb 7, 2020
1 parent 29d4b04 commit 6e2adab
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 42 deletions.
57 changes: 34 additions & 23 deletions glue/plugins/tools/pv_slicer/qt/pv_slicer.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def __init__(self, viewer, **kwargs):
self._roi_callback = self._extract_callback
self._slice_widget = None
self.viewer.state.add_callback('reference_data', self._on_reference_data_change)
# self._sliced_data = []

def _on_reference_data_change(self, reference_data):
if reference_data is not None:
Expand All @@ -47,31 +48,41 @@ def _extract_callback(self, mode):

selected = self.viewer.session.application.selected_layers()

if len(selected) == 1 and isinstance(selected[0], PVSlicedData):
data = selected[0]
data.original_data = self.viewer.state.reference_data
data.x_att = self.viewer.state.x_att
data.y_att = self.viewer.state.y_att
data.set_xy(vx, vy)
open_viewer = True
for tab in self.viewer.session.application.viewers:
for viewer in tab:
if data in viewer._layer_artist_container:
open_viewer = False
break
if not open_viewer:
break
else:
data = PVSlicedData(self.viewer.state.reference_data,
self.viewer.state.x_att, vx,
self.viewer.state.y_att, vy,
label=self.viewer.state.reference_data.label + " [slice]")
data.parent_viewer = self.viewer
self.viewer.session.data_collection.append(data)
open_viewer = True
open_viewer = False

all_pvdata = []

for data in self.viewer.state.layers_data:
if isinstance(data, Data):

for pvdata in self.viewer.session.data_collection:
if isinstance(pvdata, PVSlicedData):
if pvdata.original_data is data:
break
else:
pvdata = None

if pvdata is None:
pvdata = PVSlicedData(data,
self.viewer.state.x_att, vx,
self.viewer.state.y_att, vy,
label=data.label + " [slice]")
data.parent_viewer = self.viewer
self.viewer.session.data_collection.append(pvdata)
open_viewer = True
else:
data = pvdata
data.original_data = self.viewer.state.reference_data
data.x_att = self.viewer.state.x_att
data.y_att = self.viewer.state.y_att
data.set_xy(vx, vy)

all_pvdata.append(pvdata)

if open_viewer:
viewer = self.viewer.session.application.new_data_viewer(ImageViewer, data=data)
viewer = self.viewer.session.application.new_data_viewer(ImageViewer)
for pvdata in all_pvdata:
viewer.add_data(pvdata)

viewer.state.aspect = 'auto'
viewer.state.reset_limits()
Expand Down
43 changes: 24 additions & 19 deletions glue/plugins/tools/pv_slicer/qt/tests/test_pv_slicer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from glue.tests.helpers import requires_astropy, requires_scipy
from glue.viewers.image.qt.data_viewer import ImageViewer

from ..pv_slicer import _slice_from_path, _slice_label, _slice_index
from ..pv_slicer import _slice_label, _slice_index


class TestPVSlicerMode(object):
Expand Down Expand Up @@ -47,6 +47,11 @@ def test_plain(self):

tool._extract_callback(mode)

# Add a subset to check for any issues

self.data_collection.new_subset_group(subset_state=self.data.id['x'] > 0.5,
label='Test Subset')


@requires_astropy
@requires_scipy
Expand All @@ -56,28 +61,28 @@ def setup_method(self, method):
self.x = np.random.random((2, 3, 4))
self.d = Data(x=self.x)

def test_constant_y(self):
# def test_constant_y(self):

slc = (0, 'y', 'x')
x = [-0.5, 3.5]
y = [0, 0]
s = _slice_from_path(x, y, self.d, 'x', slc)[0]
assert_allclose(s, self.x[:, 0, :])
# slc = (0, 'y', 'x')
# x = [-0.5, 3.5]
# y = [0, 0]
# s = _slice_from_path(x, y, self.d, 'x', slc)[0]
# assert_allclose(s, self.x[:, 0, :])

def test_constant_x(self):
# def test_constant_x(self):

slc = (0, 'y', 'x')
y = [-0.5, 2.5]
x = [0, 0]
s = _slice_from_path(x, y, self.d, 'x', slc)[0]
assert_allclose(s, self.x[:, :, 0])
# slc = (0, 'y', 'x')
# y = [-0.5, 2.5]
# x = [0, 0]
# s = _slice_from_path(x, y, self.d, 'x', slc)[0]
# assert_allclose(s, self.x[:, :, 0])

def test_transpose(self):
slc = (0, 'x', 'y')
y = [-0.5, 3.5]
x = [0, 0]
s = _slice_from_path(x, y, self.d, 'x', slc)[0]
assert_allclose(s, self.x[:, 0, :])
# def test_transpose(self):
# slc = (0, 'x', 'y')
# y = [-0.5, 3.5]
# x = [0, 0]
# s = _slice_from_path(x, y, self.d, 'x', slc)[0]
# assert_allclose(s, self.x[:, 0, :])


def test_slice_label():
Expand Down

0 comments on commit 6e2adab

Please sign in to comment.