diff --git a/mantidimaging/gui/windows/spectrum_viewer/model.py b/mantidimaging/gui/windows/spectrum_viewer/model.py index dda8097fb50..9044fbb70ea 100644 --- a/mantidimaging/gui/windows/spectrum_viewer/model.py +++ b/mantidimaging/gui/windows/spectrum_viewer/model.py @@ -567,3 +567,8 @@ def set_tof_unit_mode_for_stack(self) -> None: else: self.tof_mode = ToFUnitMode.WAVELENGTH self.presenter.change_selected_menu_option("Wavelength") + + def get_roi(self, roi_name: str) -> SensibleROI: + if roi_name not in self._roi_ranges.keys(): + raise KeyError(f"ROI {roi_name} does not exist in roi_ranges {self._roi_ranges.keys()}") + return self._roi_ranges[roi_name] diff --git a/mantidimaging/gui/windows/spectrum_viewer/presenter.py b/mantidimaging/gui/windows/spectrum_viewer/presenter.py index 4f99be83ef1..9a7d4b4293d 100644 --- a/mantidimaging/gui/windows/spectrum_viewer/presenter.py +++ b/mantidimaging/gui/windows/spectrum_viewer/presenter.py @@ -331,9 +331,7 @@ def do_add_roi(self) -> None: if roi_name in self.view.spectrum_widget.roi_dict: raise ValueError(f"ROI name already exists: {roi_name}") self.model.set_new_roi(roi_name) - roi = self.model._roi_ranges.get(roi_name) - if roi is None: - raise ValueError(f"ROI for {roi_name} is not valid.") + roi = self.model.get_roi(roi_name) self.view.spectrum_widget.add_roi(roi, roi_name) spectrum = self.model.get_spectrum(roi, self.spectrum_mode, self.view.shuttercount_norm_enabled()) self.view.set_spectrum(roi_name, spectrum)