Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions src/mslice/plotting/plot_window/overplot_interface.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from qtpy.QtWidgets import QFileDialog

import os.path as path
import warnings

from mslice.models.labels import get_recoil_label
import mslice.plotting.pyplot as plt
Expand Down Expand Up @@ -47,15 +48,19 @@ def toggle_overplot_line(
)

if checked:
plotter_presenter.add_overplot_line(
plot_handler.ws_name,
key,
recoil,
cif_file,
plot_handler.y_log,
plot_handler._get_overplot_datum(),
plot_handler.intensity_type,
)
try:
plotter_presenter.add_overplot_line(
plot_handler.ws_name,
key,
recoil,
cif_file,
plot_handler.y_log,
plot_handler._get_overplot_datum(),
plot_handler.intensity_type,
)
except: # noqa: E722
warnings.warn("No Bragg peak found as cut has no |Q| dimension.")
return
else:
plotter_presenter.hide_overplot_line(plot_handler.ws_name, key)

Expand Down
13 changes: 12 additions & 1 deletion src/mslice/presenters/cut_plotter_presenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
cut_figure_exists,
get_current_plot,
)
from mslice.models.cut.cut import SampleTempValueError
from mslice.models.cut.cut_functions import compute_cut
from mslice.models.labels import generate_legend
from mslice.models.workspacemanager.workspace_algorithms import export_workspace_to_ads
Expand Down Expand Up @@ -281,7 +282,10 @@ def add_overplot_line(
return
try:
ws_handle = get_workspace_handle(workspace_name)
workspace_name = ws_handle.parent
if not ws_handle.parent:
workspace_name = workspace_name.split("(")[0][:-4]
else:
workspace_name = ws_handle.parent
except KeyError:
# Workspace is interactively generated and is not in the workspace list
workspace_name = workspace_name.split("(")[0][:-4]
Expand Down Expand Up @@ -316,6 +320,13 @@ def _get_overall_q_axis(self):
def _get_overall_max_signal(self, intensity_correction):
overall_max_signal = 0
for cut in self._cut_cache_dict[plt.gca()]:
try:
cut.sample_temp
except SampleTempValueError:
try:
self.propagate_sample_temperatures_throughout_cache(plt.gca())
except RuntimeError:
continue
ws = cut.get_intensity_corrected_ws(intensity_correction)
max_cut_signal = np.nanmax(ws.get_signal())
if max_cut_signal > overall_max_signal:
Expand Down
16 changes: 16 additions & 0 deletions tests/cut_plotter_presenter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,22 @@ def test_propagate_sample_temperatures_throughout_cache(self):
self.assertEqual(cut_2.sample_temp, 120)
self.assertEqual(cut_3._sample_temp, None)

@mock.patch("mslice.presenters.cut_plotter_presenter.plt.gca")
def test_missing_sample_temperature(self, mock_plot_gca):
ax = mock.MagicMock()
self.populate_presenter_cache_dict(ax)
cut_1, cut_2, cut_3 = self.cut_plotter_presenter._cut_cache_dict[ax]
cut_1._cut_ws.get_signal.return_value = 25.0
cut_2._cut_ws.get_signal.return_value = 50.0
cut_3._cut_ws.get_signal.return_value = 100.0
cut_1.sample_temp = 120
mock_plot_gca.return_value = ax
self.cut_plotter_presenter._get_overall_max_signal(
IntensityType.SCATTERING_FUNCTION
)
self.assertEqual(cut_1.sample_temp, 120)
self.assertEqual(cut_2.sample_temp, 120)

@mock.patch("mslice.presenters.cut_plotter_presenter.plt.gca")
def test_get_overall_q_axis(self, mock_plot_gca):
ax = mock.MagicMock()
Expand Down
Loading