Commit 4a51dae4 authored by Joseph Torsney's avatar Joseph Torsney Committed by Zhou, Wenduo
Browse files

Sliceviewer transpose MDE export methods and model tests re #30599

parent a0fe7bd4
......@@ -276,7 +276,7 @@ class SliceViewerModel:
def export_roi_to_workspace_mdevent(self, slicepoint: Sequence[Optional[float]],
bin_params: Sequence[float], limits: tuple,
transpose: bool):
transpose: bool, dimension_indices: Sequence[int]):
"""
Export 2D roi to a separate workspace.
:param slicepoint: ND sequence of either None or float. A float defines the point
......@@ -284,12 +284,12 @@ class SliceViewerModel:
:param bin_params: ND sequence containing the number of bins for each dimension
:param limits: An optional ND sequence containing limits for plotting dimensions. If
not provided the full extent of each dimension is used
:param dimension_indices: A list where the value (None, 0, or 1) at index i denotes the index of the axis
dimension i is displayed on
:param transpose: If true the limits are transposed w.r.t the data
"""
workspace = self._get_ws()
if transpose:
limits = limits[1], limits[0]
params, xindex, yindex = _roi_binmd_parameters(workspace, slicepoint, bin_params, limits)
params, xindex, yindex = _roi_binmd_parameters(workspace, slicepoint, bin_params, limits, dimension_indices)
params['OutputWorkspace'] = self._roi_name
roi_ws = BinMD(InputWorkspace=self._get_ws(), **params)
roi_ws.clearOriginalWorkspaces()
......@@ -300,7 +300,7 @@ class SliceViewerModel:
def export_cuts_to_workspace_mdevent(self, slicepoint: Sequence[Optional[float]],
bin_params: Sequence[float], limits: tuple,
transpose: bool, cut: str):
transpose: bool, dimension_indices: Sequence[int], cut: str):
"""
Export 1D cuts in the X/Y direction for the extent.
:param slicepoint: ND sequence of either None or float. A float defines the point
......@@ -312,11 +312,8 @@ class SliceViewerModel:
:param cut: A string denoting which type to export. Options=s,c,x,y.
"""
workspace = self._get_ws()
if transpose:
# swap back to model order
limits = limits[1], limits[0]
xcut_name, ycut_name, help_msg = self._cut_names(cut)
params, xindex, yindex = _roi_binmd_parameters(workspace, slicepoint, bin_params, limits)
params, xindex, yindex = _roi_binmd_parameters(workspace, slicepoint, bin_params, limits, dimension_indices)
output_bins = params['OutputBins']
xbins, ybins = output_bins[xindex], output_bins[yindex]
if transpose:
......@@ -342,7 +339,7 @@ class SliceViewerModel:
def export_roi_to_workspace_mdhisto(self, slicepoint: Sequence[Optional[float]],
bin_params: Sequence[float], limits: tuple,
transpose: bool):
transpose: bool, dimension_indices: Sequence[int]):
"""
Export 2D ROI to a workspace.
:param slicepoint: ND sequence of either None or float. A float defines the point
......@@ -374,7 +371,7 @@ class SliceViewerModel:
def export_cuts_to_workspace_mdhisto(self, slicepoint: Sequence[Optional[float]],
bin_params: Sequence[float], limits: tuple,
transpose: bool, cut: str):
transpose: bool, dimension_indices: Sequence[int], cut: str):
"""
Export 1D cuts in the X/Y direction for the extent.
:param slicepoint: ND sequence of either None or float. A float defines the point
......@@ -412,7 +409,7 @@ class SliceViewerModel:
return help_msg
def export_cuts_to_workspace_matrix(self, slicepoint, bin_params, limits: tuple,
transpose: bool, cut: str):
transpose: bool, dimension_indices: Sequence[int], cut: str):
"""
Export 1D cuts in the X/Y direction for the extent. Signature matches other export functions.
slicepoint, bin_params are unused
......@@ -439,7 +436,7 @@ class SliceViewerModel:
return help_msg
def export_roi_to_workspace_matrix(self, slicepoint, bin_params, limits: tuple,
transpose: bool):
transpose: bool, dimension_indices: Sequence[int]):
"""
Export 2D region as a workspace. Signature matches other export functions
slicepoint, bin_params are unused
......
......@@ -291,7 +291,8 @@ class SliceViewer(ObservingPresenter):
self.model.export_roi_to_workspace(self.get_slicepoint(),
bin_params=data_view.dimensions.get_bin_params(),
limits=limits,
transpose=data_view.dimensions.transpose))
transpose=data_view.dimensions.transpose,
dimension_indices=data_view.dimensions.get_states()))
except Exception as exc:
self._logger.error(str(exc))
self._show_status_message("Error exporting ROI")
......@@ -311,6 +312,7 @@ class SliceViewer(ObservingPresenter):
bin_params=data_view.dimensions.get_bin_params(),
limits=limits,
transpose=data_view.dimensions.transpose,
dimension_indices=data_view.dimensions.get_states(),
cut=cut_type))
except Exception as exc:
self._logger.error(str(exc))
......
......@@ -323,7 +323,7 @@ class SliceViewerModelTest(unittest.TestCase):
model = SliceViewerModel(self.ws_MDE_3D)
mock_binmd.return_value = self.ws_MD_3D
self.assertNotEqual(model.get_ws((None, None, 0), (1, 2, 4), ((-2, 2), (-1, 1))),
self.assertNotEqual(model.get_ws((None, None, 0), (1, 2, 4), ((-2, 2), (-1, 1)), [0, 1, None]),
self.ws_MDE_3D)
call_params = dict(AxisAligned=False,
......@@ -338,7 +338,7 @@ class SliceViewerModelTest(unittest.TestCase):
mock_binmd.assert_called_once_with(**call_params)
mock_binmd.reset_mock()
model.get_data((None, None, 0), (1, 2, 4), ((-2, 2), (-1, 1)))
model.get_data((None, None, 0), (1, 2, 4), [0, 1, None], ((-2, 2), (-1, 1)))
mock_binmd.assert_called_once_with(**call_params)
@patch('mantidqt.widgets.sliceviewer.model.BinMD')
......@@ -348,7 +348,7 @@ class SliceViewerModelTest(unittest.TestCase):
xmin = -5e-8
xmax = 5e-8
self.assertNotEqual(model.get_ws((None, None, 0), (1, 2, 4), ((xmin, xmax), (-1, 1))),
self.assertNotEqual(model.get_ws((None, None, 0), (1, 2, 4), ((xmin, xmax), (-1, 1)), [0, 1, None]),
self.ws_MDE_3D)
call_params = dict(AxisAligned=False,
......@@ -650,10 +650,10 @@ class SliceViewerModelTest(unittest.TestCase):
y_is_spectra=is_spectra)
mock_ws.name.return_value = 'mock_ws'
model = SliceViewerModel(mock_ws)
slicepoint, bin_params = MagicMock(), MagicMock()
slicepoint, bin_params, dimension_indices = MagicMock(), MagicMock(), MagicMock()
help_msg = model.export_roi_to_workspace(slicepoint, bin_params,
((xmin, xmax), (ymin, ymax)), transpose)
((xmin, xmax), (ymin, ymax)), transpose, dimension_indices)
self.assertEqual('ROI created: mock_ws_roi', help_msg)
if is_spectra:
......@@ -685,10 +685,10 @@ class SliceViewerModelTest(unittest.TestCase):
def assert_call_as_expected(mock_ws, transpose, export_type, is_spectra, is_ragged):
model = SliceViewerModel(mock_ws)
slicepoint, bin_params = MagicMock(), MagicMock()
slicepoint, bin_params, dimension_indices = MagicMock(), MagicMock(), MagicMock()
help_msg = model.export_cuts_to_workspace(slicepoint, bin_params,
((xmin, xmax), (ymin, ymax)), transpose,
((xmin, xmax), (ymin, ymax)), transpose, dimension_indices,
export_type)
if export_type == 'c':
......@@ -763,16 +763,18 @@ class SliceViewerModelTest(unittest.TestCase):
xmin, xmax, ymin, ymax = -1., 3., 2., 4.
slicepoint, bin_params = (None, None, 0.5), (100, 100, 0.1)
zmin, zmax = 0.45, 0.55 # 3rd dimension extents
dimension_indices = [0, 1, None] # Value at index i is the index of the axis that dimension i is displayed on
transposed_dimension_indices = [1, 0, None]
def assert_call_as_expected(transpose, export_type):
def assert_call_as_expected(transpose, dimension_indices, export_type):
model = SliceViewerModel(self.ws_MDE_3D)
if export_type == 'r':
help_msg = model.export_roi_to_workspace(slicepoint, bin_params,
((xmin, xmax), (ymin, ymax)), transpose)
((xmin, xmax), (ymin, ymax)), transpose, dimension_indices)
else:
help_msg = model.export_cuts_to_workspace(slicepoint, bin_params,
((xmin, xmax), (ymin, ymax)), transpose,
((xmin, xmax), (ymin, ymax)), transpose, dimension_indices,
export_type)
if transpose:
......@@ -845,8 +847,8 @@ class SliceViewerModelTest(unittest.TestCase):
mock_transposemd.reset_mock()
for export_type in ('r', 'x', 'y', 'c'):
assert_call_as_expected(transpose=False, export_type=export_type)
assert_call_as_expected(transpose=True, export_type=export_type)
assert_call_as_expected(transpose=False, dimension_indices=dimension_indices, export_type=export_type)
assert_call_as_expected(transpose=True, dimension_indices=transposed_dimension_indices, export_type=export_type)
@patch('mantidqt.widgets.sliceviewer.model.BinMD')
@patch('mantidqt.widgets.sliceviewer.roi.ExtractSpectra')
......@@ -854,15 +856,15 @@ class SliceViewerModelTest(unittest.TestCase):
mock_binmd):
def assert_error_returned_in_help(workspace, export_type, mock_alg, err_msg):
model = SliceViewerModel(workspace)
slicepoint, bin_params = (None, None, None), MagicMock()
slicepoint, bin_params, dimension_indices = (None, None, None), MagicMock(), [0, 1, None]
mock_alg.side_effect = RuntimeError(err_msg)
try:
if export_type == 'r':
help_msg = model.export_roi_to_workspace(slicepoint, bin_params,
((1.0, 2.0), (-1, 2.0)), True)
((1.0, 2.0), (-1, 2.0)), True, dimension_indices)
else:
help_msg = model.export_cuts_to_workspace(slicepoint, bin_params,
((1.0, 2.0), (-1, 2.0)), True,
((1.0, 2.0), (-1, 2.0)), True, dimension_indices,
export_type)
except Exception as exc:
help_msg = str(exc)
......
......@@ -183,9 +183,10 @@ class SliceViewerViewTest(unittest.TestCase, QtWidgetFinder):
pres.view.data_view.dimensions.transpose = True
pres.update_plot_data()
extent = pres.view.data_view.image.get_extent()
self.assertTupleEqual(extent, (-9.0, 9.0, -10.0, 10.0))
self.assertTupleEqual(extent[0:2], pres.view.data_view.ax.get_xlim())
self.assertTupleEqual(extent[2:], pres.view.data_view.ax.get_ylim())
# Should be the same as before as transposition is handled in the model
self.assertListEqual(extent, [-10.0, 10.0, -9.0, 9.0])
self.assertListEqual(extent[0:2], list(pres.view.data_view.ax.get_xlim()))
self.assertListEqual(extent[2:], list(pres.view.data_view.ax.get_ylim()))
pres.view.close()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment