From 34a25295b2c9e2ce0731c61316336caa23948ce9 Mon Sep 17 00:00:00 2001 From: Sam Tygier Date: Fri, 15 Nov 2024 08:36:02 +0000 Subject: [PATCH 1/5] Rename load_images_into_mixed_dataset to load_image_stack_to_new_dataset And use Dataset --- mantidimaging/gui/windows/main/model.py | 10 +++++----- mantidimaging/gui/windows/main/presenter.py | 2 +- mantidimaging/gui/windows/main/test/model_test.py | 2 +- mantidimaging/gui/windows/main/test/presenter_test.py | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/mantidimaging/gui/windows/main/model.py b/mantidimaging/gui/windows/main/model.py index ec73528afb5..78c6412b7ec 100644 --- a/mantidimaging/gui/windows/main/model.py +++ b/mantidimaging/gui/windows/main/model.py @@ -7,7 +7,7 @@ from typing import NoReturn, TYPE_CHECKING from mantidimaging.core.data import ImageStack -from mantidimaging.core.data.dataset import StrictDataset, MixedDataset, Dataset +from mantidimaging.core.data.dataset import StrictDataset, Dataset from mantidimaging.core.io import loader, saver from mantidimaging.core.io.filenames import FilenameGroup from mantidimaging.core.io.loader.loader import LoadingParameters, ImageParameters @@ -60,11 +60,11 @@ def load(im_param: ImageParameters) -> ImageStack: self.datasets[ds.id] = ds return ds - def load_images_into_mixed_dataset(self, file_path: str, progress: Progress) -> MixedDataset: + def load_image_stack_to_new_dataset(self, file_path: str, progress: Progress) -> Dataset: images = self.load_image_stack(file_path, progress) - sd = MixedDataset(stacks=[images], name=images.name) - self.datasets[sd.id] = sd - return sd + ds = Dataset(stacks=[images], name=images.name) + self.datasets[ds.id] = ds + return ds def load_image_stack(self, file_path: str, progress: Progress) -> ImageStack: group = FilenameGroup.from_file(Path(file_path)) diff --git a/mantidimaging/gui/windows/main/presenter.py b/mantidimaging/gui/windows/main/presenter.py index c2b23b16703..e2c06d1517d 100644 --- a/mantidimaging/gui/windows/main/presenter.py +++ b/mantidimaging/gui/windows/main/presenter.py @@ -159,7 +159,7 @@ def save_nexus_file(self) -> None: busy=True) def load_image_stack(self, file_path: str) -> None: - start_async_task_view(self.view, self.model.load_images_into_mixed_dataset, self._on_dataset_load_done, + start_async_task_view(self.view, self.model.load_image_stack_to_new_dataset, self._on_dataset_load_done, {'file_path': file_path}) def _open_window_if_not_open(self) -> None: diff --git a/mantidimaging/gui/windows/main/test/model_test.py b/mantidimaging/gui/windows/main/test/model_test.py index be4c4afa093..d515630ef72 100644 --- a/mantidimaging/gui/windows/main/test/model_test.py +++ b/mantidimaging/gui/windows/main/test/model_test.py @@ -270,7 +270,7 @@ def test_load_stack(self, fng_mock: mock.MagicMock, loader: mock.MagicMock): group = mock.Mock() fng_mock.from_file.return_value = group - self.model.load_images_into_mixed_dataset(file_path, progress) + self.model.load_image_stack_to_new_dataset(file_path, progress) loader.load_stack_from_group.assert_called_once_with(group, progress) diff --git a/mantidimaging/gui/windows/main/test/presenter_test.py b/mantidimaging/gui/windows/main/test/presenter_test.py index be3fe749fb4..884ccc04db3 100644 --- a/mantidimaging/gui/windows/main/test/presenter_test.py +++ b/mantidimaging/gui/windows/main/test/presenter_test.py @@ -96,7 +96,7 @@ def test_load_stack(self, start_async_mock: mock.Mock): self.presenter.load_image_stack(file_path) - start_async_mock.assert_called_once_with(self.view, self.presenter.model.load_images_into_mixed_dataset, + start_async_mock.assert_called_once_with(self.view, self.presenter.model.load_image_stack_to_new_dataset, self.presenter._on_dataset_load_done, {'file_path': file_path}) def test_add_stack(self): From efec58b4942aec27eb1ec1685e7736253e9ec903 Mon Sep 17 00:00:00 2001 From: Sam Tygier Date: Fri, 15 Nov 2024 08:58:54 +0000 Subject: [PATCH 2/5] MainWindowModelTest: remove MixedDataset --- mantidimaging/gui/windows/main/test/model_test.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mantidimaging/gui/windows/main/test/model_test.py b/mantidimaging/gui/windows/main/test/model_test.py index d515630ef72..161c3b67731 100644 --- a/mantidimaging/gui/windows/main/test/model_test.py +++ b/mantidimaging/gui/windows/main/test/model_test.py @@ -10,7 +10,7 @@ import numpy as np from mantidimaging.core.data import ImageStack -from mantidimaging.core.data.dataset import StrictDataset, MixedDataset, Dataset +from mantidimaging.core.data.dataset import StrictDataset, Dataset from mantidimaging.core.io.loader.loader import LoadingParameters, ImageParameters from mantidimaging.core.utility.data_containers import ProjectionAngles, FILE_TYPES, Indices from mantidimaging.gui.windows.main import MainWindowModel @@ -393,7 +393,7 @@ def test_remove_images_from_mixed_dataset(self): ids = [image_stack.id for image_stack in images] id_to_remove = ids[0] - ds = MixedDataset(stacks=images) + ds = Dataset(stacks=images) self.model.datasets[ds.id] = ds deleted_stacks = self.model.remove_container(id_to_remove) @@ -418,7 +418,7 @@ def test_proj180s(self): ds1 = StrictDataset(sample=generate_images()) ds2 = StrictDataset(sample=generate_images()) - ds3 = MixedDataset(stacks=[generate_images()]) + ds3 = Dataset(stacks=[generate_images()]) proj180s = [ImageStack(ds1.sample.data[0]), ImageStack(ds2.sample.data[0])] ds1.proj180deg = proj180s[0] @@ -451,8 +451,8 @@ def test_delete_all_recons_in_dataset(self): self.assertListEqual(ds.recons.stacks, []) def test_get_all_recon_list_ids(self): - ds1 = MixedDataset() - ds2 = MixedDataset() + ds1 = Dataset() + ds2 = Dataset() self.model.add_dataset_to_model(ds1) self.model.add_dataset_to_model(ds2) @@ -460,7 +460,7 @@ def test_get_all_recon_list_ids(self): self.assertListEqual(self.model.recon_list_ids, [ds1.recons.id, ds2.recons.id]) def test_get_recon_list_id(self): - ds = MixedDataset() + ds = Dataset() self.model.add_dataset_to_model(ds) assert self.model.get_recon_list_id(ds.id) == ds.recons.id From 41fc617e7cf6722c0c83103d5a8d5101828cda22 Mon Sep 17 00:00:00 2001 From: Sam Tygier Date: Fri, 15 Nov 2024 09:03:31 +0000 Subject: [PATCH 3/5] Remove MixedDataset from StackVisualiserPresenter --- .../gui/windows/stack_visualiser/presenter.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mantidimaging/gui/windows/stack_visualiser/presenter.py b/mantidimaging/gui/windows/stack_visualiser/presenter.py index 9e3b8f58070..b906996d520 100644 --- a/mantidimaging/gui/windows/stack_visualiser/presenter.py +++ b/mantidimaging/gui/windows/stack_visualiser/presenter.py @@ -14,7 +14,7 @@ from mantidimaging.gui.mvp_base import BasePresenter from .model import SVModel from ...utility.common import operation_in_progress -from mantidimaging.core.data.dataset import MixedDataset +from mantidimaging.core.data.dataset import Dataset if TYPE_CHECKING: from .view import StackVisualiserView # pragma: no cover @@ -114,17 +114,17 @@ def dupe_stack(self): "The data is being copied, this may take a while.", self.view): new_images = self.images.copy(flip_axes=False) new_images.name = self.images.name - self.add_mixed_dataset_to_model_and_update_view(new_images) + self.add_new_dataset_to_model_and_update_view(new_images) def dupe_stack_roi(self): with operation_in_progress("Copying data, this may take a while", "The data is being copied, this may take a while.", self.view): new_images = self.images.copy_roi(SensibleROI.from_points(*self.view.image_view.get_roi())) new_images.name = self.images.name - self.add_mixed_dataset_to_model_and_update_view(new_images) + self.add_new_dataset_to_model_and_update_view(new_images) - def add_mixed_dataset_to_model_and_update_view(self, images: ImageStack): - dataset = MixedDataset(stacks=[images], name=images.name) + def add_new_dataset_to_model_and_update_view(self, images: ImageStack): + dataset = Dataset(stacks=[images], name=images.name) self.view._main_window.presenter.model.add_dataset_to_model(dataset) self.view._main_window.presenter.update_dataset_tree() self.view._main_window.presenter.create_dataset_stack_visualisers(dataset) From 9c5e1e3adc457f8ec9ff93175289fcebb874abd7 Mon Sep 17 00:00:00 2001 From: Sam Tygier Date: Fri, 15 Nov 2024 09:11:25 +0000 Subject: [PATCH 4/5] Remove MixedDataset from ReconstructionWindowTest, DatasetSelectorWidgetPresenterTests, SpectrumViewerWindowPresenterTest --- mantidimaging/eyes_tests/reconstruct_window_test.py | 4 ++-- .../gui/widgets/dataset_selector/test/presenter_test.py | 4 ++-- .../gui/windows/spectrum_viewer/test/presenter_test.py | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/mantidimaging/eyes_tests/reconstruct_window_test.py b/mantidimaging/eyes_tests/reconstruct_window_test.py index 8f8557b59a1..902b715d3fd 100644 --- a/mantidimaging/eyes_tests/reconstruct_window_test.py +++ b/mantidimaging/eyes_tests/reconstruct_window_test.py @@ -8,7 +8,7 @@ from mantidimaging.eyes_tests.base_eyes import BaseEyesTest from mantidimaging.test_helpers.unit_test_helper import generate_images -from mantidimaging.core.data.dataset import MixedDataset +from mantidimaging.core.data.dataset import Dataset from mantidimaging.test_helpers.qt_test_helpers import wait_until @@ -56,7 +56,7 @@ def test_reconstruction_window_reconstruct_tab(self): def test_negative_nan_overlay(self): images = generate_images(seed=10) images.name = "bad_data" - ds = MixedDataset(stacks=[images]) + ds = Dataset(stacks=[images]) self.imaging.presenter.model.add_dataset_to_model(ds) self.imaging.presenter.create_single_tabbed_images_stack(images) QApplication.sendPostedEvents() diff --git a/mantidimaging/gui/widgets/dataset_selector/test/presenter_test.py b/mantidimaging/gui/widgets/dataset_selector/test/presenter_test.py index d5373c41553..5b08cdf0f96 100644 --- a/mantidimaging/gui/widgets/dataset_selector/test/presenter_test.py +++ b/mantidimaging/gui/widgets/dataset_selector/test/presenter_test.py @@ -5,7 +5,7 @@ import unittest from unittest import mock -from mantidimaging.core.data.dataset import StrictDataset, MixedDataset +from mantidimaging.core.data.dataset import StrictDataset, Dataset from mantidimaging.gui.widgets.dataset_selector.presenter import DatasetSelectorWidgetPresenter, Notification from mantidimaging.gui.widgets.dataset_selector.view import DatasetSelectorWidgetView @@ -33,7 +33,7 @@ def setUp(self) -> None: self.ds1.name = "Dataset 1" self.ds2 = StrictDataset(sample=self.img2, flat_before=self.img3) self.ds2.name = "Dataset 2" - self.ds3 = MixedDataset(stacks=[self.img4]) + self.ds3 = Dataset(stacks=[self.img4]) self.ds3.name = "Dataset 3" def test_handle_selection_no_matching_index_found(self): diff --git a/mantidimaging/gui/windows/spectrum_viewer/test/presenter_test.py b/mantidimaging/gui/windows/spectrum_viewer/test/presenter_test.py index a6fb345fd5c..01953fe8686 100644 --- a/mantidimaging/gui/windows/spectrum_viewer/test/presenter_test.py +++ b/mantidimaging/gui/windows/spectrum_viewer/test/presenter_test.py @@ -10,7 +10,7 @@ from PyQt5.QtWidgets import QPushButton, QActionGroup, QGroupBox, QAction, QCheckBox, QTabWidget from parameterized import parameterized -from mantidimaging.core.data.dataset import StrictDataset, MixedDataset +from mantidimaging.core.data.dataset import StrictDataset, Dataset from mantidimaging.core.utility.sensible_roi import SensibleROI from mantidimaging.gui.windows.main import MainWindowView from mantidimaging.gui.windows.spectrum_viewer import SpectrumViewerWindowView, SpectrumViewerWindowPresenter @@ -103,9 +103,9 @@ def test_handle_sample_change_dataset_unchanged(self): self.presenter.main_window.get_dataset.assert_not_called() self.assertEqual(self.view.current_dataset_id, initial_dataset_id) - def test_handle_sample_change_to_MixedDataset(self): + def test_handle_sample_change_to_dataset_no_sample(self): self.presenter.get_dataset_id_for_stack = mock.Mock(return_value=uuid.uuid4()) - new_dataset = MixedDataset(stacks=[generate_images()]) + new_dataset = Dataset(stacks=[generate_images()]) self.presenter.main_window.get_dataset = mock.Mock(return_value=new_dataset) self.presenter.main_window.get_stack = mock.Mock(return_value=generate_images()) self.presenter.show_new_sample = mock.Mock() From 38fc0bb2baca617ab8313d3e5d7869c58a171767 Mon Sep 17 00:00:00 2001 From: Sam Tygier Date: Fri, 15 Nov 2024 09:19:55 +0000 Subject: [PATCH 5/5] Remove MixedDataset Has been replaced by unified Dataset --- mantidimaging/core/data/dataset.py | 4 -- .../core/data/test/mixeddataset_test.py | 61 ------------------- 2 files changed, 65 deletions(-) delete mode 100644 mantidimaging/core/data/test/mixeddataset_test.py diff --git a/mantidimaging/core/data/dataset.py b/mantidimaging/core/data/dataset.py index 60c49d160cb..b0121a83567 100644 --- a/mantidimaging/core/data/dataset.py +++ b/mantidimaging/core/data/dataset.py @@ -201,10 +201,6 @@ def is_processed(self) -> bool: return False -class MixedDataset(Dataset): - pass - - class StrictDataset(Dataset): pass diff --git a/mantidimaging/core/data/test/mixeddataset_test.py b/mantidimaging/core/data/test/mixeddataset_test.py deleted file mode 100644 index 8ec61d0b11c..00000000000 --- a/mantidimaging/core/data/test/mixeddataset_test.py +++ /dev/null @@ -1,61 +0,0 @@ -# Copyright (C) 2024 ISIS Rutherford Appleton Laboratory UKRI -# SPDX - License - Identifier: GPL-3.0-or-later -from __future__ import annotations - -import unittest - -from mantidimaging.core.data.dataset import MixedDataset, _get_stack_data_type -from mantidimaging.test_helpers.unit_test_helper import generate_images - - -class MixedDatasetTest(unittest.TestCase): - - def setUp(self) -> None: - self.image_stacks = [generate_images() for _ in range(3)] - self.mixed_dataset = MixedDataset(stacks=self.image_stacks) - - def test_all(self): - self.assertListEqual(self.mixed_dataset.all, self.image_stacks) - - def test_delete_stack_from_stacks_list(self): - prev_stacks = self.image_stacks.copy() - self.mixed_dataset.delete_stack(self.image_stacks[-1].id) - self.assertListEqual(self.mixed_dataset.all, prev_stacks[:-1]) - - def test_delete_stack_from_recons_list(self): - [self.mixed_dataset.add_recon(generate_images()) for _ in range(2)] - recons = self.mixed_dataset.recons.copy() - - id_to_remove = recons[-1].id - self.mixed_dataset.delete_stack(id_to_remove) - self.assertNotIn(recons[-1], self.mixed_dataset.all) - - def test_delete_stack_failure(self): - with self.assertRaises(KeyError): - self.mixed_dataset.delete_stack("nonexistent-id") - - def test_all_ids(self): - self.assertListEqual(self.mixed_dataset.all_image_ids, [image_stack.id for image_stack in self.image_stacks]) - - def test_sinograms_in_all(self): - self.assertListEqual(self.mixed_dataset._stacks, self.mixed_dataset.all) - self.mixed_dataset.sinograms = sinograms = generate_images() - self.assertListEqual(self.mixed_dataset._stacks + [sinograms], self.mixed_dataset.all) - - def test_delete_sinograms(self): - self.mixed_dataset.sinograms = sinograms = generate_images() - self.mixed_dataset.delete_stack(sinograms.id) - self.assertNotIn(sinograms, self.mixed_dataset.all) - - def test_get_stack_data_type_returns_recon(self): - recon = generate_images() - recon_id = recon.id - dataset = MixedDataset() - dataset.recons.append(recon) - self.assertEqual(_get_stack_data_type(recon_id, dataset), "Recon") - - def test_get_stack_data_type_returns_images(self): - images = generate_images() - images_id = images.id - dataset = MixedDataset(stacks=[images]) - self.assertEqual(_get_stack_data_type(images_id, dataset), "Images")