mantidproject / mantid

Main repository for Mantid code
https://www.mantidproject.org
GNU General Public License v3.0
207 stars 121 forks source link

Unhandled Exception When Monitor Workspaces Are Cropped #37132

Open cailafinn opened 3 months ago

cailafinn commented 3 months ago

Describe the bug An unhandled exception occurs when a monitor workspace is cropped while the plot is open. For regular workspaces, cropping the workspace also updates the spectrum numbers associated with each curve, but for monitor workspaces they seem to keep spectrum 1 when it is removed. This causes an unhandled exception whenever the figure window is opened. To Reproduce

For example

  1. Load something with monitors like LOQ49886 from the Training Course Data. Separate the monitors.
  2. Plot the monitor workspace.
  3. Run CropWorkspace to remove the first spectrum (Put 1 in the StartWorkspaceIndex property).
  4. Try to open the figure options on the plot.

Expected behavior The legend and lines should correctly represent the spectrum numbers present in the workspace, and allow the figure management widget to be opened.

Screenshots This screenshot shows the monitor workspace with it's missing first spectrum, but the legend shows a line with a spec num of 1. image

Platform/Version (please complete the following information):

jhaigh0 commented 1 month ago

Stack trace I get when recreating this

Traceback (most recent call last):
  File "C:\Users\bya67386\work\mantid\qt\applications\workbench\workbench\plotting\figuremanager.py", line 365, in launch_plot_options
    self.plot_options_dialog = PlotConfigDialogPresenter(self.canvas.figure, parent=self.window)
  File "C:\Users\bya67386\work\mantid\qt\python\mantidqt\mantidqt\widgets\plotconfigdialog\presenter.py", line 45, in __init__
    curves_tab = CurvesTabWidgetPresenter(self.fig, parent_view=self.view, parent_presenter=self, legend_tab=legend_tab)
  File "C:\Users\bya67386\work\mantid\qt\python\mantidqt\mantidqt\widgets\plotconfigdialog\curvestabwidget\presenter.py", line 39, in __init__
    self.update_view()
  File "C:\Users\bya67386\work\mantid\qt\python\mantidqt\mantidqt\widgets\plotconfigdialog\curvestabwidget\presenter.py", line 287, in update_view
    self.set_errorbars_tab_enabled()
  File "C:\Users\bya67386\work\mantid\qt\python\mantidqt\mantidqt\widgets\plotconfigdialog\curvestabwidget\presenter.py", line 247, in set_errorbars_tab_enabled
    enable_errorbars = curve_has_errors(self.get_current_curve())
  File "C:\Users\bya67386\work\mantid\qt\python\mantidqt\mantidqt\widgets\plotconfigdialog\curvestabwidget\__init__.py", line 114, in curve_has_errors
    return ax.artists_workspace_has_errors(curve)
  File "C:\Users\bya67386\work\mantid\Framework\PythonInterface\mantid\plots\mantidaxes.py", line 324, in artists_workspace_has_errors
    workspace_index = workspace.getIndexFromSpectrumNumber(spec_num)
RuntimeError: Could not find spectrum number in any spectrum.