Skip to content

Commit 7987531

Browse files
Merge pull request #1107 from mantidproject/1105_fix_clipboard_error
Fix for save script error
2 parents f2c85e0 + b9d138e commit 7987531

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

src/mslice/models/alg_workspace_ops.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ def get_number_of_steps(axis):
1414
return int(np.ceil(step_num))
1515

1616

17+
def get_range_end(start, end, width):
18+
return min(start + width, end) if width is not None else end
19+
20+
1721
def get_axis_range(workspace, dimension_name):
1822
workspace = get_workspace_handle(workspace)
1923
return tuple(workspace.limits[dimension_name])

src/mslice/presenters/cut_plotter_presenter.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
cut_figure_exists,
77
get_current_plot,
88
)
9+
from mslice.models.alg_workspace_ops import get_range_end
910
from mslice.models.cut.cut import SampleTempValueError
1011
from mslice.models.cut.cut_functions import compute_cut
1112
from mslice.models.labels import generate_legend
@@ -122,16 +123,15 @@ def _plot_with_width(self, workspace, cut, plot_over):
122123
"""This function handles the width parameter."""
123124
integration_start = cut.integration_axis.start
124125
integration_end = cut.integration_axis.end
125-
cut_start, cut_end = (
126-
integration_start,
127-
min(integration_start + cut.width, integration_end),
128-
)
126+
cut_start = integration_start
127+
cut_end = get_range_end(integration_start, integration_end, cut.width)
129128
while cut_start != cut_end:
130129
cut.integration_axis.start = cut_start
131130
cut.integration_axis.end = cut_end
132131
final_plot = True if cut_start + cut.width == integration_end else False
133132
self._plot_cut(workspace, cut, plot_over, final_plot=final_plot)
134-
cut_start, cut_end = cut_end, min(cut_end + cut.width, integration_end)
133+
cut_start = cut_end
134+
cut_end = get_range_end(cut_end, integration_end, cut.width)
135135
cut.cut_ws = None
136136
# The first plot will respect which button the user pressed. The rest will over plot
137137
plot_over = True

src/mslice/scripting/helperfunctions.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from datetime import datetime
2+
from mslice.models.alg_workspace_ops import get_range_end
23
from mslice.models.labels import get_recoil_key
34
from mslice.util.intensity_correction import IntensityType, IntensityCache
45
import re
@@ -220,10 +221,8 @@ def add_cut_lines_with_width(errorbars, script_lines, cuts, intensity_correction
220221
for cut in cuts:
221222
integration_start = cut.integration_axis.start
222223
integration_end = cut.integration_axis.end
223-
cut_start, cut_end = (
224-
integration_start,
225-
min(integration_start + cut.width, integration_end),
226-
)
224+
cut_start = integration_start
225+
cut_end = get_range_end(integration_start, integration_end, cut.width)
227226
intensity_range = (cut.intensity_start, cut.intensity_end)
228227
norm_to_one = cut.norm_to_one
229228
algo_str = "" if "Rebin" in cut.algorithm else f', Algorithm="{cut.algorithm}"'
@@ -253,6 +252,7 @@ def add_cut_lines_with_width(errorbars, script_lines, cuts, intensity_correction
253252
f"IntensityCorrection={intensity_correction_arg}, SampleTemperature={cut.raw_sample_temp})\n"
254253
)
255254
return_ws_vars.append(cut_ws)
255+
256256
plot_over = False if index == 0 else True
257257
if intensity_range != (None, None):
258258
script_lines.append(
@@ -265,7 +265,8 @@ def add_cut_lines_with_width(errorbars, script_lines, cuts, intensity_correction
265265
f"lw={width}, plot_over={plot_over})\n\n"
266266
)
267267

268-
cut_start, cut_end = cut_end, min(cut_end + cut.width, integration_end)
268+
cut_start = cut_end
269+
cut_end = get_range_end(cut_end, integration_end, cut.width)
269270
index += 1
270271
cut.reset_integration_axis(cut.start, cut.end)
271272
return return_ws_vars

0 commit comments

Comments
 (0)