Skip to content

Commit

Permalink
Reduce get_spectrum() calls when opening the spectrum viewer (#1914)
Browse files Browse the repository at this point in the history
  • Loading branch information
samtygier-stfc authored Sep 5, 2023
2 parents 9bc5b88 + bb9a6f7 commit c5e3498
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 41 deletions.
7 changes: 3 additions & 4 deletions mantidimaging/gui/windows/spectrum_viewer/presenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ def handle_normalise_stack_change(self, normalise_uuid: Optional['UUID']) -> Non
return
self.model.set_normalise_stack(self.main_window.get_stack(normalise_uuid))
self.view.set_normalise_error(self.model.normalise_issue())
self.redraw_all_rois()
if self.view.normalisation_enabled():
self.redraw_all_rois()

def auto_find_flat_stack(self, new_dataset_id):
if self.view.current_dataset_id != new_dataset_id:
Expand All @@ -103,8 +104,6 @@ def show_new_sample(self) -> None:
self.view.set_image(self.model.get_averaged_image())
self.view.spectrum.add_range(*self.model.tof_range)
self.view.auto_range_image()
self.view.spectrum.reset_roi_size(self.model.get_image_shape())
self.handle_roi_moved(True)

def handle_range_slide_moved(self, tof_range) -> None:
self.model.tof_range = tof_range
Expand Down Expand Up @@ -181,8 +180,8 @@ def do_add_roi(self) -> None:
"""
roi_name = self.model.roi_name_generator()
self.model.set_new_roi(roi_name)
self.view.set_spectrum(roi_name, self.model.get_spectrum(roi_name, self.spectrum_mode))
self.view.spectrum.add_roi(self.model.get_roi(roi_name), roi_name)
self.view.set_spectrum(roi_name, self.model.get_spectrum(roi_name, self.spectrum_mode))
self.view.auto_range_image()
self.do_add_roi_to_table(roi_name)

Expand Down
15 changes: 0 additions & 15 deletions mantidimaging/gui/windows/spectrum_viewer/spectrum_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,18 +228,3 @@ def rename_roi(self, old_name: str, new_name: str) -> None:
if old_name in self.roi_dict.keys() and new_name not in self.roi_dict.keys():
self.roi_dict[new_name] = self.roi_dict.pop(old_name)
self.spectrum_data_dict[new_name] = self.spectrum_data_dict.pop(old_name)

def reset_roi_size(self, image_shape) -> None:
"""
Reset the size of the ROI to the maximum size of the image.
@param image_shape: The shape of the image.
"""
roi_name = list(self.roi_dict.keys())[0]
height, width = image_shape

self.roi_dict[roi_name].setSize([width, height])
self.roi_dict[roi_name].setPos([0, 0])
self.roi_dict[roi_name].maxBounds = self.roi_dict[roi_name].parentBounds()
self.image.vb.addItem(self.roi_dict[roi_name])
self.roi_dict[roi_name].sigRegionChanged.connect(self.roi_changed.emit)
14 changes: 0 additions & 14 deletions mantidimaging/gui/windows/spectrum_viewer/test/spectrum_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,17 +161,3 @@ def test_WHEN_rename_roi_called_with_default_roi_THEN_roi_name_not_changed(self)
self.assertIn("roi_1", self.spectrum_widget.roi_dict.keys())
self.spectrum_widget.rename_roi("roi_1", "roi")
self.assertIn("roi_1", self.spectrum_widget.roi_dict)

def test_WHEN_reset_size_called_THEN_roi_size_reset(self):
image_shape = (100, 100)
spectrum_roi = SpectrumROI("roi",
self.sensible_roi,
pos=(0, 0),
rotatable=False,
scaleSnap=True,
translateSnap=True)
self.spectrum_widget.roi_dict["roi"] = spectrum_roi
self.spectrum_widget.spectrum_data_dict["roi"] = np.array([0, 0, 0, 0])
self.spectrum_widget.reset_roi_size(image_shape)
img_x, img_y = spectrum_roi.size()
self.assertEqual((img_x, img_y), (100, 100))
13 changes: 5 additions & 8 deletions mantidimaging/gui/windows/spectrum_viewer/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def __init__(self, main_window: 'MainWindowView'):
self._current_dataset_id = None
self.sampleStackSelector.stack_selected_uuid.connect(self.presenter.handle_sample_change)
self.normaliseStackSelector.stack_selected_uuid.connect(self.presenter.handle_normalise_stack_change)
self.normaliseCheckBox.stateChanged.connect(self.set_normalise_dropdown_state)
self.normaliseCheckBox.stateChanged.connect(self.normaliseStackSelector.setEnabled)
self.normaliseCheckBox.stateChanged.connect(self.presenter.handle_enable_normalised)

# ROI action buttons
Expand Down Expand Up @@ -158,12 +158,6 @@ def _configure_dropdown(self, selector: DatasetSelectorWidgetView) -> None:
selector.presenter.show_stacks = True
selector.subscribe_to_main_window(self.main_window)

def set_normalise_dropdown_state(self) -> None:
if self.normaliseCheckBox.isChecked():
self.normaliseStackSelector.setEnabled(True)
else:
self.normaliseStackSelector.setEnabled(False)

def try_to_select_relevant_normalise_stack(self, name: str) -> None:
self.normaliseStackSelector.try_to_select_relevant_stack(name)

Expand Down Expand Up @@ -206,13 +200,16 @@ def set_normalise_error(self, norm_issue: str):
self.display_normalise_error()

def display_normalise_error(self):
if self.normalise_error_issue and self.normaliseCheckBox.isChecked():
if self.normalise_error_issue and self.normalisation_enabled():
self.normaliseErrorIcon.setPixmap(self.normalise_error_icon_pixmap)
self.normaliseErrorIcon.setToolTip(self.normalise_error_issue)
else:
self.normaliseErrorIcon.setPixmap(QPixmap())
self.normaliseErrorIcon.setToolTip("")

def normalisation_enabled(self):
return self.normaliseCheckBox.isChecked()

def set_new_roi(self) -> None:
"""
Set a new ROI on the image
Expand Down

0 comments on commit c5e3498

Please sign in to comment.