Skip to content

Commit

Permalink
made suggested chnages
Browse files Browse the repository at this point in the history
  • Loading branch information
ashmeigh committed Dec 4, 2024
1 parent c9b44b0 commit 04ec340
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 30 deletions.
2 changes: 1 addition & 1 deletion mantidimaging/gui/test/gui_system_spectrum_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def test_adjust_roi(self):
roi_widget.movePoint(handle_index, new_position)
QTest.qWait(SHORT_DELAY)

updated_roi = self.spectrum_window.presenter.view.spectrum_widget.get_roi(roi_name)
updated_roi = self.spectrum_window.spectrum_widget.get_roi(roi_name)
self.assertEqual(updated_roi.right, new_position[0])
self.assertEqual(updated_roi.bottom, new_position[1])
self.assertEqual(updated_roi.top, 0)
Expand Down
4 changes: 3 additions & 1 deletion mantidimaging/gui/windows/spectrum_viewer/presenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,9 @@ def do_remove_roi(self, roi_name: str | None = None) -> None:
@param roi_name: Name of the ROI to remove
"""
if roi_name is None:
self.view.spectrum_widget.roi_dict.clear()
self.view.clear_all_rois()
for name in self.get_roi_names():
self.view.spectrum_widget.remove_roi(name)
self.model.remove_all_roi()
else:
self.view.spectrum_widget.remove_roi(roi_name)
Expand Down
20 changes: 7 additions & 13 deletions mantidimaging/gui/windows/spectrum_viewer/test/model_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ def test_save_rits_dat(self):
self.model.set_normalise_stack(norm)

roi = SensibleROI.from_list([0, 0, 12, 11])
self.model._roi_ranges["ROI_RITS"] = roi
mock_stream, mock_path = self._make_mock_path_stream()
with mock.patch.object(self.model, "save_roi_coords"):
self.model.save_rits_roi(mock_path, ErrorMode.STANDARD_DEVIATION, roi)
Expand Down Expand Up @@ -245,6 +244,8 @@ def test_save_rits_roi_dat(self):

@parameterized.expand([
("std_dev", ErrorMode.STANDARD_DEVIATION, [0., 0.25, 0.5, 0.75, 1., 1.25, 1.5, 1.75, 2., 2.25]),
("std_dev", ErrorMode.PROPAGATED,
[0.0000, 0.0772, 0.1306, 0.1823, 0.2335, 0.2845, 0.3354, 0.3862, 0.4369, 0.4876]),
])
def test_save_rits_data_errors(self, _, error_mode, expected_error):
stack, _ = self._set_sample_stack(with_tof=True)
Expand Down Expand Up @@ -389,11 +390,6 @@ def test_when_new_roi_set_THEN_roi_name_added_to_list_of_roi_names(self):
self.assertIn("new_roi", self.model._roi_ranges)
self.assertListEqual(list(self.model._roi_ranges.keys()), ["all", "new_roi"])

def test_WHEN_accessing_non_existent_roi_THEN_keyerror_is_raised(self):
self.model.set_stack(generate_images())
with self.assertRaises(KeyError):
_ = self.model._roi_ranges["non_existent_roi"]

@parameterized.expand([
("False", None, False),
("True", ImageStack(np.ones([10, 11, 12])), True),
Expand Down Expand Up @@ -625,18 +621,16 @@ def test_get_transmission_error_propogated(self):
average_shutter_counts = sample_shutter_counts[0] / open_shutter_counts[0]

roi = SensibleROI.from_list([0, 0, 5, 5])
self.model._roi_ranges["roi"] = roi
sample = self.model.get_stack_spectrum_summed(stack, roi)
open = self.model.get_stack_spectrum_summed(normalise_stack, roi)
expected = np.sqrt(sample / open**2 + sample**2 / open**3) / average_shutter_counts

with mock.patch.object(self.model,
"get_shuttercount_normalised_correction_parameter",
return_value=average_shutter_counts):
with mock.patch.object(
self.model, "get_shuttercount_normalised_correction_parameter",
return_value=average_shutter_counts) as mock_get_shuttercount_normalised_correction_parameter:
result = self.model.get_transmission_error_propagated(roi, normalise_with_shuttercount=True)

self.assertEqual(len(expected), len(result))
np.testing.assert_allclose(expected, result)
mock_get_shuttercount_normalised_correction_parameter.assert_called_once()
np.testing.assert_allclose(result, expected)

def test_get_transmission_error_propogated_raises_runtimeerror_if_no_stack(self):
with self.assertRaises(RuntimeError):
Expand Down
18 changes: 4 additions & 14 deletions mantidimaging/gui/windows/spectrum_viewer/test/presenter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,21 +285,11 @@ def test_WHEN_ROI_renamed_THEN_roi_renamed(self):
rois = ["all", "roi", "roi_1"]
self.view.spectrum_widget.roi_dict = {roi: mock.Mock() for roi in rois}
self.presenter.model._roi_ranges = {roi: mock.Mock() for roi in rois}
self.view.spectrum_widget.rename_roi.side_effect = lambda old, new: self.view.spectrum_widget.roi_dict.update(
{new: self.view.spectrum_widget.roi_dict.pop(old)})
self.view.spectrum_widget.rename_roi = mock.Mock()
self.presenter.rename_roi("roi_1", "new_name")
self.assertSetEqual(set(self.view.spectrum_widget.roi_dict.keys()), {"all", "roi", "new_name"})
self.assertSetEqual(set(self.presenter.model._roi_ranges.keys()), {"all", "roi", "new_name"})

def test_WHEN_default_ROI_renamed_THEN_default_roi_renamed(self):
rois = ["all", "roi", "roi_1"]
self.view.spectrum_widget.roi_dict = {roi: mock.Mock() for roi in rois}
self.presenter.model._roi_ranges = {roi: mock.Mock() for roi in rois}
self.view.spectrum_widget.rename_roi.side_effect = lambda old, new: self.view.spectrum_widget.roi_dict.update(
{new: self.view.spectrum_widget.roi_dict.pop(old)})
self.presenter.rename_roi("roi", "new_name")
self.assertSetEqual(set(self.view.spectrum_widget.roi_dict.keys()), {"all", "roi_1", "new_name"})
self.assertSetEqual(set(self.presenter.model._roi_ranges.keys()), {"all", "roi_1", "new_name"})
self.view.spectrum_widget.rename_roi.assert_called_once_with("roi_1", "new_name")
self.assertIn("new_name", self.presenter.model._roi_ranges)
self.assertNotIn("roi_1", self.presenter.model._roi_ranges)

@parameterized.expand([("all", ), ("roi", )])
def test_WHEN_ROI_renamed_to_existing_name_THEN_runtimeerror(self, name):
Expand Down
1 change: 0 additions & 1 deletion mantidimaging/gui/windows/spectrum_viewer/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ def __init__(self, main_window: MainWindowView):
self.normalise_error_icon_pixmap = QPixmap(icon_path)

self.selected_row: int = 0
self.last_clicked_roi = ""
self.current_roi_name: str = ""
self.roiPropertiesSpinBoxes: dict[str, QSpinBox] = {}
self.roiPropertiesLabels: dict[str, QLabel] = {}
Expand Down

0 comments on commit 04ec340

Please sign in to comment.