Skip to content

Commit cf3f37c

Browse files
committed
Add a new specialized function for exporting pixel cuts from MDHisto workspaces
1 parent e08be5b commit cf3f37c

File tree

2 files changed

+40
-5
lines changed

2 files changed

+40
-5
lines changed

qt/python/mantidqt/mantidqt/widgets/sliceviewer/models/model.py

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ def __init__(self, ws):
7070
if WorkspaceInfo.get_ws_type(self._get_ws()) == WS_TYPE.MDE:
7171
self.export_roi_to_workspace = self.export_roi_to_workspace_mdevent
7272
self.export_cuts_to_workspace = self.export_cuts_to_workspace_mdevent
73-
self.export_pixel_cut_to_workspace = self.export_pixel_cut_to_workspace_md
73+
self.export_pixel_cut_to_workspace = self.export_pixel_cut_to_workspace_mdevent
7474
elif ws_type == WS_TYPE.MDH:
7575
self.export_roi_to_workspace = self.export_roi_to_workspace_mdhisto
7676
self.export_cuts_to_workspace = self.export_cuts_to_workspace_mdhisto
77-
self.export_pixel_cut_to_workspace = self.export_pixel_cut_to_workspace_md
77+
self.export_pixel_cut_to_workspace = self.export_pixel_cut_to_workspace_mdhisto
7878
else:
7979
self.export_roi_to_workspace = self.export_roi_to_workspace_matrix
8080
self.export_cuts_to_workspace = self.export_cuts_to_workspace_matrix
@@ -269,6 +269,7 @@ def export_cuts_to_workspace_mdevent(
269269
:param limits: An optional ND sequence containing limits for plotting dimensions. If
270270
not provided the full extent of each dimension is used
271271
:param transpose: If true then the limits are transposed w.r.t to the data
272+
:param dimension_indices: A list where the value (None, 0, or 1) at index i denotes the index of the axis
272273
:param cut: A string denoting which type to export. Options=s,c,x,y.
273274
"""
274275
workspace = self._get_ws()
@@ -356,6 +357,7 @@ def export_roi_to_workspace_mdhisto(
356357
:param limits: An optional ND sequence containing limits for plotting dimensions. If
357358
not provided the full extent of each dimension is used
358359
:param transpose: If true then the limits are transposed w.r.t to the data
360+
:param dimension_indices: A list where the value (None, 0, or 1) at index i denotes the index of the axis
359361
"""
360362
workspace = self._get_ws()
361363
dim_limits = _dimension_limits(workspace, slicepoint, bin_params, dimension_indices, limits)
@@ -391,6 +393,7 @@ def export_cuts_to_workspace_mdhisto(
391393
:param limits: An optional ND sequence containing limits for plotting dimensions. If
392394
not provided the full extent of each dimension is used
393395
:param transpose: If true then the limits are transposed w.r.t to the data
396+
:param dimension_indices: A list where the value (None, 0, or 1) at index i denotes the index of the axis
394397
:param cut: A string denoting which type to export. Options=c,x,y.
395398
"""
396399
workspace = self._get_ws()
@@ -426,6 +429,7 @@ def export_cuts_to_workspace_matrix(
426429
:param limits: An optional ND sequence containing limits for plotting dimensions. If
427430
not provided the full extent of each dimension is used
428431
:param transpose: If true then the limits are transposed .w.r.t. the data
432+
:param dimension_indices: A list where the value (None, 0, or 1) at index i denotes the index of the axis
429433
:param cut: A string denoting which cut to export. Options=c,x,y.
430434
"""
431435
workspace = self._get_ws()
@@ -452,35 +456,65 @@ def export_roi_to_workspace_matrix(self, slicepoint, bin_params, limits: tuple,
452456
:param limits: An ND sequence containing limits for plotting dimensions. If
453457
not provided the full extent of each dimension is used
454458
:param transpose: If true then the limits are transposed .w.r.t. the data
459+
:param dimension_indices: A list where the value (None, 0, or 1) at index i denotes the index of the axis
455460
"""
456461
if transpose:
457462
# swap back to model order
458463
limits = limits[1], limits[0]
459464
extract_roi_matrix(self._get_ws(), *limits[0], *limits[1], transpose, self._roi_name)
460465
return f"ROI created: {self._roi_name}"
461466

462-
def export_pixel_cut_to_workspace_md(self, slicepoint, bin_params, pos: tuple, transpose: bool, axis: str):
467+
def export_pixel_cut_to_workspace_mdhisto(
468+
self, slicepoint, bin_params, pos: tuple, transpose: bool, dimension_indices: Sequence[int], axis: str
469+
):
463470
"""
464471
Export a single row/column as a workspace. Signature matches other export functions
465472
slicepoint, bin_params are unused
466473
:param pos: A 2-tuple containing the position of the pixel whose row/column should be exported
467474
:param transpose: If true then the limits are transposed .w.r.t. the data
475+
:param dimension_indices: A list where the value (None, 0, or 1) at index i denotes the index of the axis
468476
:param axis: A string 'x' or 'y' identifying the axis to cut along
469477
"""
470478
# Form single pixel limits for a cut
471479
xindex, yindex = WorkspaceInfo.display_indices(slicepoint, transpose)
472480
workspace = self._get_ws()
473481
deltax, deltay = workspace.getDimension(xindex).getBinWidth(), workspace.getDimension(yindex).getBinWidth()
474482
xpos, ypos = pos
483+
if transpose:
484+
xpos, ypos = ypos, xpos
475485
limits = (xpos - 0.5 * deltax, xpos + 0.5 * deltax), (ypos - 0.5 * deltay, ypos + 0.5 * deltay)
476-
return self.export_cuts_to_workspace_mdevent(slicepoint, bin_params, limits, transpose, axis)
486+
return self.export_cuts_to_workspace_mdhisto(slicepoint, bin_params, limits, transpose, dimension_indices, axis)
477487

478-
def export_pixel_cut_to_workspace_matrix(self, slicepoint, bin_params, pos: tuple, transpose: bool, axis: str):
488+
def export_pixel_cut_to_workspace_mdevent(
489+
self, slicepoint, bin_params, pos: tuple, transpose: bool, dimension_indices: Sequence[int], axis: str
490+
):
479491
"""
480492
Export a single row/column as a workspace. Signature matches other export functions
481493
slicepoint, bin_params are unused
482494
:param pos: A 2-tuple containing the position of the pixel whose row/column should be exported
483495
:param transpose: If true then the limits are transposed .w.r.t. the data
496+
:param dimension_indices: A list where the value (None, 0, or 1) at index i denotes the index of the axis
497+
:param axis: A string 'x' or 'y' identifying the axis to cut along
498+
"""
499+
# Form single pixel limits for a cut
500+
xindex, yindex = WorkspaceInfo.display_indices(slicepoint, transpose)
501+
workspace = self._get_ws()
502+
deltax, deltay = workspace.getDimension(xindex).getBinWidth(), workspace.getDimension(yindex).getBinWidth()
503+
xpos, ypos = pos
504+
if transpose:
505+
xpos, ypos = ypos, xpos
506+
limits = (xpos - 0.5 * deltax, xpos + 0.5 * deltax), (ypos - 0.5 * deltay, ypos + 0.5 * deltay)
507+
return self.export_cuts_to_workspace_mdevent(slicepoint, bin_params, limits, transpose, dimension_indices, axis)
508+
509+
def export_pixel_cut_to_workspace_matrix(
510+
self, slicepoint, bin_params, pos: tuple, transpose: bool, dimension_indices: Sequence[int], axis: str
511+
):
512+
"""
513+
Export a single row/column as a workspace. Signature matches other export functions
514+
slicepoint, bin_params are unused
515+
:param pos: A 2-tuple containing the position of the pixel whose row/column should be exported
516+
:param transpose: If true then the limits are transposed .w.r.t. the data
517+
:param dimension_indices: A list where the value (None, 0, or 1) at index i denotes the index of the axis
484518
:param axis: A string 'x' or 'y' identifying the axis to cut along
485519
"""
486520
workspace = self._get_ws()

qt/python/mantidqt/mantidqt/widgets/sliceviewer/presenters/presenter.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ def export_pixel_cut(self, pos, axis):
294294
bin_params=data_view.dimensions.get_bin_params(),
295295
pos=pos,
296296
transpose=data_view.dimensions.transpose,
297+
dimension_indices=data_view.dimensions.get_states(),
297298
axis=axis,
298299
)
299300
)

0 commit comments

Comments
 (0)