Skip to content

Commit 2f519d5

Browse files
committed
Moved cut end calculation into function
1 parent f44beba commit 2f519d5

File tree

4 files changed

+8
-18
lines changed

4 files changed

+8
-18
lines changed

src/mslice/models/alg_workspace_ops.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ def get_number_of_steps(axis):
1313

1414
return int(np.ceil(step_num))
1515

16+
def get_range_end(start, end, width):
17+
return min(start + width, end) if width is not None else end
1618

1719
def get_axis_range(workspace, dimension_name):
1820
workspace = get_workspace_handle(workspace)

src/mslice/presenters/cut_plotter_presenter.py

Lines changed: 3 additions & 8 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
@@ -123,20 +124,14 @@ def _plot_with_width(self, workspace, cut, plot_over):
123124
integration_start = cut.integration_axis.start
124125
integration_end = cut.integration_axis.end
125126
cut_start = integration_start
126-
if cut.width is not None:
127-
cut_end = min(integration_start + cut.width, integration_end)
128-
else:
129-
cut_end = integration_end
127+
cut_end = get_range_end(integration_start, integration_end, cut.width)
130128
while cut_start != cut_end:
131129
cut.integration_axis.start = cut_start
132130
cut.integration_axis.end = cut_end
133131
final_plot = True if cut_start + cut.width == integration_end else False
134132
self._plot_cut(workspace, cut, plot_over, final_plot=final_plot)
135133
cut_start = cut_end
136-
if cut.width is not None:
137-
cut_end = min(cut_end + cut.width, integration_end)
138-
else:
139-
cut_end = integration_end
134+
cut_end = get_range_end(cut_end, integration_end, cut.width)
140135
cut.cut_ws = None
141136
# The first plot will respect which button the user pressed. The rest will over plot
142137
plot_over = True

src/mslice/scripting/helperfunctions.py

Lines changed: 3 additions & 9 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
@@ -221,10 +222,7 @@ def add_cut_lines_with_width(errorbars, script_lines, cuts, intensity_correction
221222
integration_start = cut.integration_axis.start
222223
integration_end = cut.integration_axis.end
223224
cut_start = integration_start
224-
if cut.width is not None:
225-
cut_end = min(integration_start + cut.width, integration_end)
226-
else:
227-
cut_end = integration_end
225+
cut_end = get_range_end(integration_start, integration_end, cut.width)
228226
intensity_range = (cut.intensity_start, cut.intensity_end)
229227
norm_to_one = cut.norm_to_one
230228
algo_str = "" if "Rebin" in cut.algorithm else f', Algorithm="{cut.algorithm}"'
@@ -268,12 +266,8 @@ def add_cut_lines_with_width(errorbars, script_lines, cuts, intensity_correction
268266
)
269267

270268
cut_start = cut_end
271-
if cut.width is not None:
272-
cut_end = min(cut_end + cut.width, integration_end)
273-
else:
274-
cut_end = integration_end
269+
cut_end = get_range_end(cut_end, integration_end, cut.width)
275270
index += 1
276-
277271
cut.reset_integration_axis(cut.start, cut.end)
278272
return return_ws_vars
279273

tests/scripting_helperfunctions_test.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,6 @@ def test_that_add_cut_lines_with_width_works_as_expected_with_multiple_cuts(self
535535
label="error_label_{}".format(i),
536536
)
537537
errorbars = plt.gca().containers
538-
539538
cut_0 = Cut(
540539
Axis("|Q|", "1", "3", "1"),
541540
Axis("DeltaE", "-1", "1", "0"),

0 commit comments

Comments
 (0)