Skip to content

Commit

Permalink
Merge pull request #706 from mantidproject/release-next
Browse files Browse the repository at this point in the history
Merge release-next into main
  • Loading branch information
martyngigg authored Feb 9, 2022
2 parents eadc107 + 302cfd8 commit d1c8786
Show file tree
Hide file tree
Showing 21 changed files with 199 additions and 103 deletions.
1 change: 1 addition & 0 deletions docs/source/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ rectangle by clicking outside the current rectangle and dragging. Once you have
``Interactive Cut`` again to leave interactive mode. If you leave a slice in interactive cut mode and plot another
slice, another window will open. Making a cut (see below) whilst the interactive mode is active will overplot on the
same window as the interactive cut and this cut will be removed when the interactive mode rectangle is moved again.
Only when you click ``Save Cut to Workspace`` is an ``MD Histo`` type workspace created.

Plotting a Cut
--------------
Expand Down
16 changes: 6 additions & 10 deletions mslice/app/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ def __init__(self, in_mantid=False):
self.actionEUnitConvEnabled.triggered.connect(partial(self.set_energy_conversion, True))
self.actionEUnitConvDisabled.triggered.connect(partial(self.set_energy_conversion, False))
self._cut_algo_map = {'Rebin': self.actionCutAlgoRebin, 'Integration': self.actionCutAlgoIntegration}
self.actionCutAlgoRebin.triggered.connect(partial(self.set_cut_algorithm, 'Rebin'))
self.actionCutAlgoIntegration.triggered.connect(partial(self.set_cut_algorithm, 'Integration'))
self.actionCutAlgoRebin.triggered.connect(partial(self.set_cut_algorithm_default, 'Rebin'))
self.actionCutAlgoIntegration.triggered.connect(partial(self.set_cut_algorithm_default, 'Integration'))

def setup_save(self):
menu = QMenu()
Expand Down Expand Up @@ -254,15 +254,11 @@ def set_energy_conversion(self, EnabledClicked):
else:
self.actionEUnitConvEnabled.setChecked(not self.actionEUnitConvDisabled.isChecked())

def is_energy_conversion_allowed(self):
return self.actionEUnitConvEnabled.isChecked()

def set_cut_algorithm(self, algo):
def set_cut_algorithm_default(self, algo):
for action in self._cut_algo_map.keys():
if algo not in action:
self._cut_algo_map[action].setChecked(False)
self._presenter.set_cut_algorithm_default(algo)

def get_cut_algorithm(self):
for action in self._cut_algo_map.keys():
if self._cut_algo_map[action].isChecked():
return action
def is_energy_conversion_allowed(self):
return self.actionEUnitConvEnabled.isChecked()
32 changes: 16 additions & 16 deletions mslice/app/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
<widget class="QPushButton" name="btnRename">
<property name="maximumSize">
<size>
<width>110</width>
<width>130</width>
<height>16777215</height>
</size>
</property>
Expand All @@ -101,7 +101,7 @@
<widget class="QPushButton" name="btnDelete">
<property name="maximumSize">
<size>
<width>110</width>
<width>130</width>
<height>16777215</height>
</size>
</property>
Expand All @@ -114,7 +114,7 @@
<widget class="QPushButton" name="btnAdd">
<property name="maximumSize">
<size>
<width>110</width>
<width>130</width>
<height>16777215</height>
</size>
</property>
Expand All @@ -127,7 +127,7 @@
<widget class="QPushButton" name="btnSave">
<property name="maximumSize">
<size>
<width>110</width>
<width>130</width>
<height>16777215</height>
</size>
</property>
Expand All @@ -140,7 +140,7 @@
<widget class="QPushButton" name="btnPlot">
<property name="maximumSize">
<size>
<width>110</width>
<width>130</width>
<height>16777215</height>
</size>
</property>
Expand All @@ -153,7 +153,7 @@
<widget class="QPushButton" name="btnMerge">
<property name="maximumSize">
<size>
<width>110</width>
<width>130</width>
<height>16777215</height>
</size>
</property>
Expand All @@ -166,7 +166,7 @@
<widget class="QPushButton" name="btnOverplot">
<property name="maximumSize">
<size>
<width>110</width>
<width>130</width>
<height>16777215</height>
</size>
</property>
Expand All @@ -179,7 +179,7 @@
<widget class="QPushButton" name="btnSubtract">
<property name="maximumSize">
<size>
<width>110</width>
<width>130</width>
<height>16777215</height>
</size>
</property>
Expand Down Expand Up @@ -211,7 +211,7 @@
</property>
<property name="minimumSize">
<size>
<width>110</width>
<width>130</width>
<height>25</height>
</size>
</property>
Expand All @@ -232,7 +232,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>110</width>
<width>130</width>
<height>25</height>
</rect>
</property>
Expand All @@ -244,13 +244,13 @@
</property>
<property name="minimumSize">
<size>
<width>110</width>
<width>130</width>
<height>25</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>110</width>
<width>130</width>
<height>16777215</height>
</size>
</property>
Expand All @@ -264,7 +264,7 @@
<widget class="QFrame" name="composeFrame">
<property name="maximumSize">
<size>
<width>110</width>
<width>130</width>
<height>16777215</height>
</size>
</property>
Expand Down Expand Up @@ -426,7 +426,7 @@
</widget>
<widget class="QMenu" name="menuCutAlgo">
<property name="title">
<string>Cut algorithm</string>
<string>Cut algorithm default</string>
</property>
<addaction name="actionCutAlgoRebin"/>
<addaction name="actionCutAlgoIntegration"/>
Expand Down Expand Up @@ -470,15 +470,15 @@
<bool>true</bool>
</property>
<property name="text">
<string>Rebin</string>
<string>Rebin (Averages Counts)</string>
</property>
</action>
<action name="actionCutAlgoIntegration">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Integration</string>
<string>Integration (Sum Counts)</string>
</property>
</action>
</widget>
Expand Down
29 changes: 18 additions & 11 deletions mslice/models/cut/cut_algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

from mantid.api import PythonAlgorithm, WorkspaceProperty
from mantid.kernel import Direction, PropertyManagerProperty, StringMandatoryValidator, StringListValidator
from mantid.simpleapi import BinMD, ConvertSpectrumAxis, CreateMDHistoWorkspace, Rebin2D, SofQW3, TransformMD, Scale, \
ConvertToMD, DeleteWorkspace, CreateSimulationWorkspace, AddSampleLog, CopyLogs, Integration, Rebin, Transpose
from mantid.simpleapi import BinMD, ConvertSpectrumAxis, CreateMDHistoWorkspace, Rebin2D, SofQW3, TransformMD, \
ConvertToMD, DeleteWorkspace, CreateSimulationWorkspace, AddSampleLog, CopyLogs, Integration, Rebin, Transpose, \
IntegrateMDHistoWorkspace

from mslice.models.alg_workspace_ops import fill_in_missing_input, get_number_of_steps
from mslice.models.axis import Axis
Expand Down Expand Up @@ -50,25 +51,33 @@ def category(self):

def compute_cut(selected_workspace, cut_axis, integration_axis, e_mode, PSD, is_norm, algo):
if PSD:
cut = _compute_cut_PSD(selected_workspace, cut_axis, integration_axis)
cut = _compute_cut_PSD(selected_workspace, cut_axis, integration_axis, algo)
else:
cut = _compute_cut_nonPSD(selected_workspace, cut_axis, integration_axis, e_mode, algo)
if is_norm:
normalize_workspace(cut)
return cut


def _compute_cut_PSD(selected_workspace, cut_axis, integration_axis):
def _compute_cut_PSD(selected_workspace, cut_axis, integration_axis, algo):
cut_axis.units = cut_axis.units.replace('2Theta', 'Degrees')
integration_axis.units = integration_axis.units.replace('2Theta', 'Degrees')
fill_in_missing_input(cut_axis, selected_workspace)
n_steps = get_number_of_steps(cut_axis)
cut_binning = " ,".join(map(str, (cut_axis.units, cut_axis.start_meV, cut_axis.end_meV, n_steps)))
integration_binning = integration_axis.units + "," + str(integration_axis.start_meV) + "," + \
str(integration_axis.end_meV) + ",1"
str(integration_axis.end_meV) + (",1" if 'Rebin' in algo else ",100")

return BinMD(InputWorkspace=selected_workspace, AxisAligned="1", AlignedDim1=integration_binning,
AlignedDim0=cut_binning, StoreInADS=False)
ws = BinMD(InputWorkspace=selected_workspace, AxisAligned="1", AlignedDim0=integration_binning,
AlignedDim1=cut_binning, StoreInADS=False)
if 'Integration' in algo:
x0, x1 = (integration_axis.start_meV, integration_axis.end_meV)
# 100 step is hard coded into the `integration_binning` string above
norm_fac = (np.sum(ws.getNumEventsArray() != 0., axis=0) / 100) * (x1 - x0)
ws = IntegrateMDHistoWorkspace(ws, P1Bin=[x0, x1], P2Bin=[], StoreInADS=False)
ws.setSignalArray(ws.getSignalArray() * norm_fac)
ws.setErrorSquaredArray(ws.getErrorSquaredArray() * np.square(norm_fac))
return ws


def _compute_cut_nonPSD(selected_workspace, cut_axis, integration_axis, emode, algo):
Expand Down Expand Up @@ -149,17 +158,15 @@ def _cut_nonPSD_momentum(q_binning, e_binning, emode, selected_workspace, algo):
if 'Integration' in algo:
qbins = [float(q) for q in q_binning.split(',')]
ebins = [float(e) for e in e_binning.split(',')]
nstep = 100.
if np.abs((qbins[2]-qbins[0]) - qbins[1]) < 0.0001:
qbinstr = ','.join(map(str, [qbins[0], (qbins[2]-qbins[0])/nstep, qbins[2]]))
qbinstr = ','.join(map(str, [qbins[0], (qbins[2]-qbins[0])/100., qbins[2]]))
ws_out = _cut_indirect_or_direct(qbinstr, e_binning, emode, selected_workspace)
ws_out = Transpose(InputWorkspace=ws_out, EnableLogging=False)
ws_out = Integration(InputWorkspace=ws_out, RangeLower=qbins[0], RangeUpper=qbins[2], EnableLogging=False)
else:
ebinstr = ','.join(map(str, [ebins[0], (ebins[2]-ebins[0])/nstep, ebins[2]]))
ebinstr = ','.join(map(str, [ebins[0], (ebins[2]-ebins[0])/100., ebins[2]]))
ws_out = _cut_indirect_or_direct(q_binning, ebinstr, emode, selected_workspace)
ws_out = Integration(InputWorkspace=ws_out, RangeLower=ebins[0], RangeUpper=ebins[2], EnableLogging=False)
ws_out = Scale(InputWorkspace=ws_out, Factor=nstep, EnableLogging=False)
else:
ws_out = _cut_indirect_or_direct(q_binning, e_binning, emode, selected_workspace)
return ws_out
8 changes: 7 additions & 1 deletion mslice/plotting/plot_window/cut_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,14 @@ def save_default_options(self):

def setup_connections(self, plot_window):
plot_window.redraw.connect(self._canvas.draw)
plot_window.menu_intensity.setDisabled(True)
plot_window.menu_information.setDisabled(False)
plot_window.menu_recoil_lines.setDisabled(True)
plot_window.menu_intensity.setDisabled(True)
plot_window.action_toggle_legends.setVisible(True)
plot_window.action_keep.setVisible(True)
plot_window.action_make_current.setVisible(True)
plot_window.action_save_image.setVisible(True)
plot_window.action_plot_options.setVisible(True)
plot_window.action_interactive_cuts.setVisible(False)
plot_window.action_save_cut.setVisible(False)
plot_window.action_save_cut.triggered.connect(self.save_icut)
Expand Down
32 changes: 17 additions & 15 deletions mslice/plotting/plot_window/plot_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,35 +86,37 @@ def create_menus(self):
self.add_intensity_actions(self.menu_intensity)

self.setMenuBar(self.menubar)
self.menu_information.setDisabled(True)
self.menu_intensity.setDisabled(True)

def add_file_actions(self, menu):
self.action_gen_script = add_action(menu, self, "Generate Script File")
menu.addAction(self.action_gen_script)
self.action_gen_script_clipboard = add_action(menu, self, "Generate Script to Clipboard")
menu.addAction(self.action_gen_script_clipboard)

self.action_quit = add_action(menu, self, "Close")
self.action_quit = add_action(menu, self, "Close", visible=True)
menu.addAction(self.action_quit)
self.action_quit.triggered.connect(self.close)

def add_information_actions(self, menu, items):
for text in items:
action = add_action(menu, self, text, checkable=True)
action = add_action(menu, self, text, checkable=True, visible=True)
setattr(self, create_attribute_name(text), action)
menu.addAction(action)

def add_intensity_actions(self, menu):
self.action_sqe = add_action(menu, self, "S(Q,E)", checkable=True, checked=True)
self.action_sqe = add_action(menu, self, "S(Q,E)", checkable=True, checked=True, visible=True)
menu.addAction(self.action_sqe)
self.action_chi_qe = add_action(menu, self, "Chi''(Q,E)", checkable=True)
self.action_chi_qe = add_action(menu, self, "Chi''(Q,E)", checkable=True, visible=True)
menu.addAction(self.action_chi_qe)
self.action_chi_qe_magnetic = add_action(menu, self, "Chi''(Q,E) magnetic", checkable=True)
self.action_chi_qe_magnetic = add_action(menu, self, "Chi''(Q,E) magnetic", checkable=True, visible=True)
menu.addAction(self.action_chi_qe_magnetic)
self.action_d2sig_dw_de = add_action(menu, self, "d2sigma/dOmega.dE", checkable=True)
self.action_d2sig_dw_de = add_action(menu, self, "d2sigma/dOmega.dE", checkable=True, visible=True)
menu.addAction(self.action_d2sig_dw_de)
self.action_symmetrised_sqe = add_action(menu, self, "Symmetrised S(Q,E)", checkable=True)
self.action_symmetrised_sqe = add_action(menu, self, "Symmetrised S(Q,E)", checkable=True, visible=True)
menu.addAction(self.action_symmetrised_sqe)
self.action_gdos = add_action(menu, self, "GDOS", checkable=True)
self.action_gdos = add_action(menu, self, "GDOS", checkable=True, visible=True)
menu.addAction(self.action_gdos)

def create_toolbar(self):
Expand All @@ -124,23 +126,23 @@ def create_toolbar(self):

def add_toolbar_actions(self, toolbar):
self.action_zoom_in = add_action(toolbar, self, "Zoom In", on_triggered=self.stock_toolbar.zoom,
icon_name='mdi.magnify-plus-outline', checkable=True)
icon_name='mdi.magnify-plus-outline', checkable=True, visible=True)
self.action_zoom_out = add_action(toolbar, self, "Zoom Out", on_triggered=self.stock_toolbar.back,
icon_name='mdi.magnify-minus-outline', checkable=False)
icon_name='mdi.magnify-minus-outline', checkable=False, visible=True)
self.action_toggle_legends = add_action(toolbar, self, "Legends", checkable=True,
checked=True)
toolbar.addSeparator()
self.action_keep = add_action(toolbar, self, "Keep", checkable=True)
self.action_keep = add_action(toolbar, self, "Keep", checkable=True, visible=True)
self.action_make_current = add_action(toolbar, self, "Make Current",
checkable=True, checked=True)
checkable=True, checked=True, visible=True)
self.keep_make_current_group = QtWidgets.QActionGroup(self)
self.keep_make_current_group.addAction(self.action_keep)
self.keep_make_current_group.addAction(self.action_make_current)
self.keep_make_current_seperator = toolbar.addSeparator()

self.action_save_image = add_action(toolbar, self, "Save Image", icon_name='mdi.content-save')
self.action_copy_image = add_action(toolbar, self, "Copy Image", icon_name='mdi.content-copy')
self.action_print_plot = add_action(toolbar, self, "Print", icon_name='mdi.printer')
self.action_copy_image = add_action(toolbar, self, "Copy Image", icon_name='mdi.content-copy', visible=True)
self.action_print_plot = add_action(toolbar, self, "Print", icon_name='mdi.printer', visible=True)
self.action_plot_options = add_action(toolbar, self, "Plot Options", icon_name='mdi.settings')

toolbar.addSeparator()
Expand Down Expand Up @@ -249,7 +251,7 @@ def create_attribute_name(text):


def add_action(holder, parent, text, on_triggered=None, icon_name=None,
checkable=False, checked=False, visible=True):
checkable=False, checked=False, visible=False):
"""Create a new action based on the given attributes and add it to the given
holder"""
action = QtWidgets.QAction(text, parent)
Expand Down
9 changes: 9 additions & 0 deletions mslice/plotting/plot_window/slice_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ def save_default_options(self):

def setup_connections(self, plot_window):
plot_window.redraw.connect(self._canvas.draw)
plot_window.action_gen_script.setVisible(True)
plot_window.action_gen_script_clipboard.setVisible(True)
plot_window.menu_information.setDisabled(False)
plot_window.menu_intensity.setDisabled(False)
plot_window.action_toggle_legends.setVisible(True)
plot_window.action_keep.setVisible(True)
plot_window.action_make_current.setVisible(True)
plot_window.action_save_image.setVisible(True)
plot_window.action_plot_options.setVisible(True)
plot_window.action_interactive_cuts.setVisible(True)
plot_window.action_interactive_cuts.triggered.connect(self.toggle_interactive_cuts)
plot_window.action_save_cut.setVisible(False)
Expand Down
2 changes: 2 additions & 0 deletions mslice/plotting/pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3199,6 +3199,8 @@ def plot(*args, **kwargs):
ax = gca()
# Deprecated: allow callers to override the hold state
# by passing hold=True|False
if not hasattr(ax, '_hold'):
return ax.plot(*args, **kwargs)
washold = ax._hold
hold = kwargs.pop('hold', None)
if hold is not None:
Expand Down
Loading

0 comments on commit d1c8786

Please sign in to comment.