From 6e2adabc8eb77797a99dc64ce65594fc2831561f Mon Sep 17 00:00:00 2001 From: Thomas Robitaille Date: Fri, 7 Feb 2020 15:08:13 +0000 Subject: [PATCH] WIP --- glue/plugins/tools/pv_slicer/qt/pv_slicer.py | 57 +++++++++++-------- .../pv_slicer/qt/tests/test_pv_slicer.py | 43 +++++++------- 2 files changed, 58 insertions(+), 42 deletions(-) diff --git a/glue/plugins/tools/pv_slicer/qt/pv_slicer.py b/glue/plugins/tools/pv_slicer/qt/pv_slicer.py index affd619e6..35529692d 100644 --- a/glue/plugins/tools/pv_slicer/qt/pv_slicer.py +++ b/glue/plugins/tools/pv_slicer/qt/pv_slicer.py @@ -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: @@ -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() diff --git a/glue/plugins/tools/pv_slicer/qt/tests/test_pv_slicer.py b/glue/plugins/tools/pv_slicer/qt/tests/test_pv_slicer.py index 2ad9aa746..65fcf1622 100644 --- a/glue/plugins/tools/pv_slicer/qt/tests/test_pv_slicer.py +++ b/glue/plugins/tools/pv_slicer/qt/tests/test_pv_slicer.py @@ -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): @@ -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 @@ -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():