Skip to content

Commit

Permalink
prints removed and minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeSullivan7 committed Apr 5, 2024
1 parent dcaa1bf commit 838b18d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 34 deletions.
1 change: 0 additions & 1 deletion mantidimaging/gui/windows/spectrum_viewer/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ def get_averaged_image(self) -> np.ndarray | None:
or None if it does not
"""
if self._stack is not None:
print(f"{self.tof_range=}")
tof_slice = slice(self.tof_range[0], self.tof_range[1] + 1)
return self._stack.data[tof_slice].mean(axis=0)
return None
Expand Down
45 changes: 15 additions & 30 deletions mantidimaging/gui/windows/spectrum_viewer/presenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,7 @@ def handle_stack_changed(self) -> None:
except RuntimeError:
norm_stack = None
self.model.set_normalise_stack(norm_stack)
print(f"handle_stack_changed: {self.model.tof_data}")
if self.model.tof_data is None:
self.view.tof_mode_select_group.setEnabled(False)
else:
self.view.tof_mode_select_group.setEnabled(True)
self.model.tof_mode = ToFUnitMode.IMAGE_NUMBER
for action in self.view.tof_mode_select_group.actions():
with QSignalBlocker(action):
if action.objectName() == 'Image Index':
action.setChecked(True)
else:
action.setChecked(False)
self.reset_units_menu()
self.model.set_relevant_tof_units()
self.show_new_sample()
self.redraw_all_rois()
Expand All @@ -103,18 +92,7 @@ def handle_sample_change(self, uuid: UUID | None) -> None:
return

self.model.set_stack(self.main_window.get_stack(uuid))
print(f"handle_sample_changed: {self.model.tof_data}")
if self.model.tof_data is None:
self.view.tof_mode_select_group.setEnabled(False)
else:
self.view.tof_mode_select_group.setEnabled(True)
self.model.tof_mode = ToFUnitMode.IMAGE_NUMBER
for action in self.view.tof_mode_select_group.actions():
with QSignalBlocker(action):
if action.objectName() == 'Image Index':
action.setChecked(True)
else:
action.setChecked(False)
self.reset_units_menu()
self.model.set_relevant_tof_units()
normalise_uuid = self.view.get_normalise_stack()
if normalise_uuid is not None:
Expand All @@ -130,6 +108,19 @@ def handle_sample_change(self, uuid: UUID | None) -> None:
self.show_new_sample()
self.view.on_visibility_change()

def reset_units_menu(self):
if self.model.tof_data is None:
self.view.tof_mode_select_group.setEnabled(False)
else:
self.view.tof_mode_select_group.setEnabled(True)
self.model.tof_mode = ToFUnitMode.IMAGE_NUMBER
for action in self.view.tof_mode_select_group.actions():
with QSignalBlocker(action):
if action.objectName() == 'Image Index':
action.setChecked(True)
else:
action.setChecked(False)

def handle_normalise_stack_change(self, normalise_uuid: UUID | None) -> None:
if normalise_uuid == self.current_norm_stack_uuid:
return
Expand Down Expand Up @@ -174,14 +165,12 @@ def show_new_sample(self) -> None:
self.view.set_roi_properties()

def handle_range_slide_moved(self, tof_range) -> None:
print(f"handle_range_slide_moved: tof_range={tof_range}")
self.model.tof_plot_range = tof_range
if self.model.tof_mode == ToFUnitMode.IMAGE_NUMBER:
self.model.tof_range = (int(tof_range[0]), int(tof_range[1]))
else:
image_index_min = np.abs(self.model.tof_data - tof_range[0]).argmin()
image_index_max = np.abs(self.model.tof_data - tof_range[1]).argmin()
print(f"{(image_index_min, image_index_max)=}")
self.model.tof_range = tuple(sorted((image_index_min, image_index_max)))
self.view.spectrum_widget.spectrum_plot_widget.set_image_index_range_label(*self.model.tof_range)
self.view.spectrum_widget.spectrum_plot_widget.set_tof_range_label(*self.model.tof_plot_range)
Expand Down Expand Up @@ -358,12 +347,8 @@ def handle_export_tab_change(self, index: int) -> None:

def handle_tof_unit_change(self) -> None:
selected_mode = self.view.tof_mode_select_group.checkedAction().text()
print(f"{selected_mode=}")
self.model.tof_mode = self.view.allowed_modes[selected_mode]
print(f"{self.model.tof_mode=}")
print(f"1: {self.model.tof_data=}")
self.model.set_relevant_tof_units()
print(f"2: {self.model.tof_data=}")
tof_mode = self.model.tof_mode
tof_axis_label = ""
if tof_mode == ToFUnitMode.IMAGE_NUMBER:
Expand Down
3 changes: 0 additions & 3 deletions mantidimaging/gui/windows/spectrum_viewer/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,6 @@ def __init__(self, main_window: MainWindowView):
if self.presenter.model.tof_data is None:
self.tof_mode_select_group.setEnabled(False)

print(f"{self.tof_mode_select_group.actions()=}")
print(f"{self.tof_mode_select_group.actions()[0].objectName()=}")

self._current_dataset_id = None
self.sampleStackSelector.stack_selected_uuid.connect(self.presenter.handle_sample_change)
self.sampleStackSelector.stack_selected_uuid.connect(self.presenter.handle_button_enabled)
Expand Down

0 comments on commit 838b18d

Please sign in to comment.