From 21699dc84ccf86ca94faccacb5dea063b24bc9a0 Mon Sep 17 00:00:00 2001 From: Sam Tygier Date: Fri, 15 Nov 2024 12:00:04 +0000 Subject: [PATCH 1/6] DatasetSelectorWidget: remove relevant_dataset_types This used to be used to filter datasets by type, but that is no longer needed since the unification. The test_do_reload_datasets_by_dataset_type() test is also no loner needed. --- .../gui/widgets/dataset_selector/presenter.py | 18 ++++++------------ .../dataset_selector/test/presenter_test.py | 13 ------------- .../gui/widgets/dataset_selector/view.py | 6 ++---- .../dataset_selector_dialog.py | 5 +---- 4 files changed, 9 insertions(+), 33 deletions(-) diff --git a/mantidimaging/gui/widgets/dataset_selector/presenter.py b/mantidimaging/gui/widgets/dataset_selector/presenter.py index 18524f2c9ae..981a93bf27e 100644 --- a/mantidimaging/gui/widgets/dataset_selector/presenter.py +++ b/mantidimaging/gui/widgets/dataset_selector/presenter.py @@ -24,15 +24,11 @@ class DatasetSelectorWidgetPresenter(BasePresenter): view: DatasetSelectorWidgetView show_stacks: bool - def __init__(self, - view: DatasetSelectorWidgetView, - show_stacks: bool = False, - relevant_dataset_types: type | tuple[type] | None = None): + def __init__(self, view: DatasetSelectorWidgetView, show_stacks: bool = False): super().__init__(view) self.current_dataset: UUID | None = None self.show_stacks = show_stacks - self.relevant_dataset_types = relevant_dataset_types def notify(self, signal: Notification) -> None: try: @@ -74,13 +70,11 @@ def do_reload_datasets(self) -> None: def _get_dataset_list(self) -> list[tuple[UUID, str]]: result = [] for dataset in self.view.main_window.presenter.datasets: - # If no relevant dataset types have been specified then all should be included - if not self.relevant_dataset_types or isinstance(dataset, self.relevant_dataset_types): - if not self.show_stacks: - result.append((dataset.id, dataset.name)) - else: - for stack in dataset.all: - result.append((stack.id, stack.name)) + if not self.show_stacks: + result.append((dataset.id, dataset.name)) + else: + for stack in dataset.all: + result.append((stack.id, stack.name)) return result diff --git a/mantidimaging/gui/widgets/dataset_selector/test/presenter_test.py b/mantidimaging/gui/widgets/dataset_selector/test/presenter_test.py index 5b08cdf0f96..282ee2e47be 100644 --- a/mantidimaging/gui/widgets/dataset_selector/test/presenter_test.py +++ b/mantidimaging/gui/widgets/dataset_selector/test/presenter_test.py @@ -104,16 +104,3 @@ def test_do_reload_datasets_stacks(self): self.view.addItem.assert_any_call(self.img2.name, self.img2.id) self.view.addItem.assert_any_call(self.img3.name, self.img3.id) self.view.addItem.assert_any_call(self.img4.name, self.img4.id) - - def test_do_reload_datasets_by_dataset_type(self): - self.view.main_window.presenter.datasets = [self.ds1, self.ds2, self.ds3] - self.presenter.show_stacks = True - self.presenter.relevant_dataset_types = StrictDataset - self.view.datasets_updated.emit = mock.Mock() - self.view.stack_selected_uuid.emit = mock.Mock() - - self.presenter.do_reload_datasets() - self.assertEqual(self.view.addItem.call_count, 3) - self.view.addItem.assert_any_call(self.img1.name, self.img1.id) - self.view.addItem.assert_any_call(self.img2.name, self.img2.id) - self.view.addItem.assert_any_call(self.img3.name, self.img3.id) diff --git a/mantidimaging/gui/widgets/dataset_selector/view.py b/mantidimaging/gui/widgets/dataset_selector/view.py index be2a5dc32b4..3117cb7004d 100644 --- a/mantidimaging/gui/widgets/dataset_selector/view.py +++ b/mantidimaging/gui/widgets/dataset_selector/view.py @@ -28,12 +28,10 @@ class DatasetSelectorWidgetView(QComboBox): main_window: MainWindowView - def __init__(self, parent, show_stacks: bool = False, relevant_dataset_types: type | tuple[type] | None = None): + def __init__(self, parent, show_stacks: bool = False): super().__init__(parent) - self.presenter = DatasetSelectorWidgetPresenter(self, - show_stacks=show_stacks, - relevant_dataset_types=relevant_dataset_types) + self.presenter = DatasetSelectorWidgetPresenter(self, show_stacks=show_stacks) self.currentIndexChanged[int].connect(self.presenter.handle_selection) def subscribe_to_main_window(self, main_window: MainWindowView) -> None: diff --git a/mantidimaging/gui/widgets/dataset_selector_dialog/dataset_selector_dialog.py b/mantidimaging/gui/widgets/dataset_selector_dialog/dataset_selector_dialog.py index 9a0c29b77c0..e1178c8bd57 100644 --- a/mantidimaging/gui/widgets/dataset_selector_dialog/dataset_selector_dialog.py +++ b/mantidimaging/gui/widgets/dataset_selector_dialog/dataset_selector_dialog.py @@ -6,7 +6,6 @@ from PyQt5.QtWidgets import QDialog, QVBoxLayout, QLabel, QHBoxLayout, QPushButton -from mantidimaging.core.data.dataset import StrictDataset from mantidimaging.gui.mvp_base import BaseDialogView from mantidimaging.gui.widgets.dataset_selector.view import DatasetSelectorWidgetView @@ -40,9 +39,7 @@ def __init__(self, self.vertical_layout.addWidget(self.message_label) # Dataset selector - self.dataset_selector_widget = DatasetSelectorWidgetView(self, - relevant_dataset_types=StrictDataset, - show_stacks=show_stacks) + self.dataset_selector_widget = DatasetSelectorWidgetView(self, show_stacks=show_stacks) self.dataset_selector_widget.subscribe_to_main_window(main_window) # type: ignore self.vertical_layout.addWidget(self.dataset_selector_widget) From 2a18d30bc808e162579344ce0158a3311ac35792 Mon Sep 17 00:00:00 2001 From: Sam Tygier Date: Fri, 15 Nov 2024 13:30:02 +0000 Subject: [PATCH 2/6] Remove StrictDataset from Main Window --- mantidimaging/gui/windows/main/model.py | 6 +-- mantidimaging/gui/windows/main/presenter.py | 8 ++-- .../gui/windows/main/test/model_test.py | 42 +++++++++---------- .../gui/windows/main/test/presenter_test.py | 2 +- 4 files changed, 29 insertions(+), 29 deletions(-) diff --git a/mantidimaging/gui/windows/main/model.py b/mantidimaging/gui/windows/main/model.py index 1bd8283fe64..b4fc34e22dc 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, Dataset +from mantidimaging.core.data.dataset import Dataset from mantidimaging.core.io import loader, saver from mantidimaging.core.io.filenames import FilenameGroup from mantidimaging.core.io.loader.loader import LoadingParameters, ImageParameters @@ -36,13 +36,13 @@ def get_images_by_uuid(self, images_uuid: uuid.UUID) -> ImageStack | None: return image return None - def do_load_dataset(self, parameters: LoadingParameters, progress: Progress) -> StrictDataset: + def do_load_dataset(self, parameters: LoadingParameters, progress: Progress) -> Dataset: def load(im_param: ImageParameters) -> ImageStack: return loader.load_stack_from_image_params(im_param, progress, dtype=parameters.dtype) sample = load(parameters.image_stacks[FILE_TYPES.SAMPLE]) - ds = StrictDataset(sample=sample) + ds = Dataset(sample=sample) sample._is_sinograms = parameters.sinograms sample.pixel_size = parameters.pixel_size diff --git a/mantidimaging/gui/windows/main/presenter.py b/mantidimaging/gui/windows/main/presenter.py index d9929eff49c..628f7873338 100644 --- a/mantidimaging/gui/windows/main/presenter.py +++ b/mantidimaging/gui/windows/main/presenter.py @@ -625,16 +625,16 @@ def _move_stack(self, origin_dataset_id: uuid.UUID, stack_id: uuid.UUID, destina f"Unable to find destination dataset with ID {destination_dataset_id} when attempting to move stack") stack_to_move = self.get_stack(stack_id) - stack_to_move.name = self._create_strict_dataset_stack_name(destination_stack_type, destination_dataset.name) + stack_to_move.name = self._create_dataset_stack_name(destination_stack_type, destination_dataset.name) origin_dataset.delete_stack(stack_id) self.add_images_to_existing_dataset(destination_dataset_id, stack_to_move, destination_stack_type) @staticmethod - def _create_strict_dataset_stack_name(stack_type: str, dataset_name: str) -> str: + def _create_dataset_stack_name(stack_type: str, dataset_name: str) -> str: """ - Creates a name for strict dataset stacks by using the dataset name and the image type. - :param stack_type: The type of stack in the StrictDataset. + Creates a name for dataset stacks by using the dataset name and the image type. + :param stack_type: The type of stack in the Dataset. :param dataset_name: The name of the dataset. :return: A string for the stack name. """ diff --git a/mantidimaging/gui/windows/main/test/model_test.py b/mantidimaging/gui/windows/main/test/model_test.py index 60c630ea864..4d69dc2ee2c 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, Dataset +from mantidimaging.core.data.dataset import 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 @@ -101,7 +101,7 @@ def test_do_load_stack_sample_indicies(self, load_mock: mock.Mock): shutter_count_file=None) @mock.patch('mantidimaging.gui.windows.main.model.loader.load_stack_from_image_params') - @mock.patch('mantidimaging.gui.windows.main.model.StrictDataset') + @mock.patch('mantidimaging.gui.windows.main.model.Dataset') def test_do_load_stack_sample_and_flat(self, dataset_mock: mock.Mock, load_mock: mock.Mock): lp = LoadingParameters() log_file_mock = mock.Mock() @@ -142,7 +142,7 @@ def test_do_load_stack_sample_and_flat(self, dataset_mock: mock.Mock, load_mock: ]) @mock.patch('mantidimaging.gui.windows.main.model.loader.load_stack_from_image_params') - @mock.patch('mantidimaging.gui.windows.main.model.StrictDataset') + @mock.patch('mantidimaging.gui.windows.main.model.Dataset') def test_do_load_stack_sample_and_dark_and_180deg(self, dataset_mock: mock.Mock, load_mock: mock.Mock): lp = LoadingParameters() log_file_mock = mock.Mock() @@ -290,11 +290,11 @@ def test_remove_dataset_from_model(self): images = [generate_images() for _ in range(5)] ids = [image_stack.id for image_stack in images] - ds = StrictDataset(sample=images[0], - flat_before=images[1], - flat_after=images[2], - dark_before=images[3], - dark_after=images[4]) + ds = Dataset(sample=images[0], + flat_before=images[1], + flat_after=images[2], + dark_before=images[3], + dark_after=images[4]) self.model.datasets[ds.id] = ds stacks_to_close = self.model.remove_container(ds.id) @@ -307,7 +307,7 @@ def test_failed_remove_container(self): def test_remove_empty_dataset_from_model(self): sample = generate_images() - ds = StrictDataset(sample=sample) + ds = Dataset(sample=sample) self.model.datasets[ds.id] = ds self.model.remove_container(sample.id) @@ -320,7 +320,7 @@ def test_remove_non_sample_images_from_dataset_with_sample(self): images = [generate_images() for _ in range(2)] # Set the sample 180 to check this isn't removed images[0].proj180deg = generate_images() - ds = StrictDataset(sample=images[0], flat_before=images[1]) + ds = Dataset(sample=images[0], flat_before=images[1]) self.model.datasets[ds.id] = ds id_to_remove = images[-1].id @@ -331,7 +331,7 @@ def test_remove_non_sample_images_from_dataset_with_sample(self): def test_remove_non_sample_images_from_dataset_without_sample(self): images = [generate_images() for _ in range(2)] - ds = StrictDataset(sample=images[0], flat_before=images[1]) + ds = Dataset(sample=images[0], flat_before=images[1]) ds.sample = None self.model.datasets[ds.id] = ds id_to_remove = images[-1].id @@ -344,7 +344,7 @@ def test_remove_non_sample_images_from_dataset_without_sample(self): def test_remove_sample_with_180_from_dataset(self): sample = generate_images() sample.proj180deg = generate_images() - ds = StrictDataset(sample=sample) + ds = Dataset(sample=sample) self.model.datasets[ds.id] = ds expected_result = [sample.id, sample.proj180deg.id] @@ -355,7 +355,7 @@ def test_remove_sample_with_180_from_dataset(self): def test_remove_sample_without_180_from_dataset(self): sample = generate_images() - ds = StrictDataset(sample=sample) + ds = Dataset(sample=sample) self.model.datasets[ds.id] = ds expected_result = [sample.id] @@ -377,7 +377,7 @@ def test_remove_images_from_mixed_dataset(self): self.assertListEqual([id_to_remove], deleted_stacks) def test_add_dataset_to_model(self): - ds = StrictDataset(sample=generate_images()) + ds = Dataset(sample=generate_images()) self.model.add_dataset_to_model(ds) self.assertIn(ds, self.model.datasets.values()) @@ -386,14 +386,14 @@ def test_image_ids(self): for _ in range(3): images = [generate_images() for _ in range(3)] all_ids += [image.id for image in images] - ds = StrictDataset(sample=images[0], flat_before=images[1], flat_after=images[2]) + ds = Dataset(sample=images[0], flat_before=images[1], flat_after=images[2]) self.model.add_dataset_to_model(ds) self.assertListEqual(all_ids, self.model.image_ids) def test_proj180s(self): - ds1 = StrictDataset(sample=generate_images()) - ds2 = StrictDataset(sample=generate_images()) + ds1 = Dataset(sample=generate_images()) + ds2 = Dataset(sample=generate_images()) ds3 = Dataset(stacks=[generate_images()]) proj180s = [ImageStack(ds1.sample.data[0]), ImageStack(ds2.sample.data[0])] @@ -406,19 +406,19 @@ def test_proj180s(self): self.assertListEqual(self.model.proj180s, proj180s) - def test_get_parent_strict_dataset_success(self): - ds = StrictDataset(sample=generate_images()) + def test_get_parent_dataset_success(self): + ds = Dataset(sample=generate_images()) self.model.add_dataset_to_model(ds) self.assertIs(self.model.get_parent_dataset(ds.sample.id), ds.id) def test_get_parent_dataset_doesnt_find_any_parent(self): - ds = StrictDataset(sample=generate_images()) + ds = Dataset(sample=generate_images()) self.model.add_dataset_to_model(ds) with self.assertRaises(RuntimeError): self.model.get_parent_dataset("unrecognised-id") def test_delete_all_recons_in_dataset(self): - ds = StrictDataset(sample=generate_images()) + ds = Dataset(sample=generate_images()) [ds.add_recon(generate_images()) for _ in range(3)] recon_ids = ds.recons.ids self.model.add_dataset_to_model(ds) diff --git a/mantidimaging/gui/windows/main/test/presenter_test.py b/mantidimaging/gui/windows/main/test/presenter_test.py index 2b9f7ac66f3..38067fc909b 100644 --- a/mantidimaging/gui/windows/main/test/presenter_test.py +++ b/mantidimaging/gui/windows/main/test/presenter_test.py @@ -780,7 +780,7 @@ def test_move_stack_to_strict_dataset(self): self.view.move_stack_dialog = mock.Mock() self.view.move_stack_dialog.destination_stack_type = data_type = "Flat After" new_stack_name = "New Dataset Flat After" - self.presenter._create_strict_dataset_stack_name = mock.Mock(return_value=new_stack_name) + self.presenter._create_dataset_stack_name = mock.Mock(return_value=new_stack_name) self.presenter._move_stack(origin_dataset.id, stack_to_move.id, data_type, destination_dataset.id) self.presenter.get_stack.assert_called_once_with(stack_to_move.id) From f97ecc9b5a866c1ff655e48a1a08bd18a032313f Mon Sep 17 00:00:00 2001 From: Sam Tygier Date: Fri, 15 Nov 2024 15:33:57 +0000 Subject: [PATCH 3/6] Remove StrictDataset from NexusLoadPresenter --- .../windows/nexus_load_dialog/presenter.py | 26 +++++++++---------- .../nexus_load_dialog/test/presenter_test.py | 4 +-- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/mantidimaging/gui/windows/nexus_load_dialog/presenter.py b/mantidimaging/gui/windows/nexus_load_dialog/presenter.py index acd0db1a20d..4c30ab587bb 100644 --- a/mantidimaging/gui/windows/nexus_load_dialog/presenter.py +++ b/mantidimaging/gui/windows/nexus_load_dialog/presenter.py @@ -11,7 +11,7 @@ import numpy as np from mantidimaging.core.data import ImageStack -from mantidimaging.core.data.dataset import StrictDataset +from mantidimaging.core.data.dataset import Dataset from mantidimaging.core.io.utility import NEXUS_PROCESSED_DATA_PATH from mantidimaging.core.parallel import utility as pu from mantidimaging.core.utility.data_containers import ProjectionAngles @@ -297,7 +297,7 @@ def _find_data_title(self) -> str: logger.info("A valid title couldn't be found. Using 'NeXus Data' instead.") return "NeXus Data" - def get_dataset(self) -> tuple[StrictDataset, str]: + def get_dataset(self) -> tuple[Dataset, str]: """ Create a LoadingDataset and title using the arrays that have been retrieved from the NeXus file. :return: A tuple containing the Dataset and the data title string. @@ -306,16 +306,16 @@ def get_dataset(self) -> tuple[StrictDataset, str]: sample_images.name = self.title assert self.flat_before_array is not None and self.flat_after_array is not None assert self.dark_before_array is not None and self.dark_after_array is not None - ds = StrictDataset(sample=sample_images, - flat_before=self._create_images_if_required(self.flat_before_array, "Flat Before", - ImageKeys.FlatField.value), - flat_after=self._create_images_if_required(self.flat_after_array, "Flat After", - ImageKeys.FlatField.value), - dark_before=self._create_images_if_required(self.dark_before_array, "Dark Before", - ImageKeys.DarkField.value), - dark_after=self._create_images_if_required(self.dark_after_array, "Dark After", - ImageKeys.DarkField.value), - name=self.title) + ds = Dataset(sample=sample_images, + flat_before=self._create_images_if_required(self.flat_before_array, "Flat Before", + ImageKeys.FlatField.value), + flat_after=self._create_images_if_required(self.flat_after_array, "Flat After", + ImageKeys.FlatField.value), + dark_before=self._create_images_if_required(self.dark_before_array, "Dark Before", + ImageKeys.DarkField.value), + dark_after=self._create_images_if_required(self.dark_after_array, "Dark After", + ImageKeys.DarkField.value), + name=self.title) self._add_recons_to_dataset(ds) @@ -372,6 +372,6 @@ def _create_images_if_required(self, data_array: np.ndarray, name: str, image_ke image_stack.set_projection_angles(ProjectionAngles(projection_angles)) return image_stack - def _add_recons_to_dataset(self, ds: StrictDataset) -> None: + def _add_recons_to_dataset(self, ds: Dataset) -> None: for recon_array in self.recon_data: ds.add_recon(ImageStack(recon_array)) diff --git a/mantidimaging/gui/windows/nexus_load_dialog/test/presenter_test.py b/mantidimaging/gui/windows/nexus_load_dialog/test/presenter_test.py index b8bdd23e2cc..485b71651c7 100644 --- a/mantidimaging/gui/windows/nexus_load_dialog/test/presenter_test.py +++ b/mantidimaging/gui/windows/nexus_load_dialog/test/presenter_test.py @@ -12,7 +12,7 @@ from mantidimaging.core.io.saver import NEXUS_PROCESSED_DATA_PATH from mantidimaging.test_helpers.unit_test_helper import generate_images, gen_img_numpy_rand -from mantidimaging.core.data.dataset import StrictDataset +from mantidimaging.core.data.dataset import Dataset from mantidimaging.gui.windows.nexus_load_dialog.presenter import _missing_data_message, TOMO_ENTRY, DATA_PATH, \ IMAGE_KEY_PATH, NexusLoadPresenter, ROTATION_ANGLE_PATH from mantidimaging.gui.windows.nexus_load_dialog.presenter import logger as nexus_logger @@ -157,7 +157,7 @@ def test_open_nexus_file_in_read_mode(self): def test_complete_file_returns_expected_dataset_and_title(self): self.nexus_loader.scan_nexus_file() dataset, title = self.nexus_loader.get_dataset() - self.assertIsInstance(dataset, StrictDataset) + self.assertIsInstance(dataset, Dataset) self.assertEqual(title, self.title) self.assertEqual(dataset.sample.pixel_size, self.expected_pixel_size) From 58591907402ba2f3092e8ddd87f91ccdcfa85bc0 Mon Sep 17 00:00:00 2001 From: Sam Tygier Date: Fri, 15 Nov 2024 15:40:44 +0000 Subject: [PATCH 4/6] Remove StrictDataset from io.saver --- mantidimaging/core/io/saver.py | 6 ++-- mantidimaging/core/io/test/io_test.py | 44 +++++++++++++-------------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/mantidimaging/core/io/saver.py b/mantidimaging/core/io/saver.py index 587f3579da0..740081ffb9d 100644 --- a/mantidimaging/core/io/saver.py +++ b/mantidimaging/core/io/saver.py @@ -182,7 +182,7 @@ def image_save(images: ImageStack, def nexus_save(dataset: Dataset, path: str, sample_name: str, save_as_float: bool) -> None: """ - Uses information from a StrictDataset to create a NeXus file. + Uses information from a Dataset to create a NeXus file. :param dataset: The dataset to save as a NeXus file. :param path: The NeXus file path. :param sample_name: The sample name. @@ -204,9 +204,9 @@ def nexus_save(dataset: Dataset, path: str, sample_name: str, save_as_float: boo def _nexus_save(nexus_file: h5py.File, dataset: Dataset, sample_name: str, save_as_float: bool) -> None: """ - Takes a NeXus file and writes the StrictDataset information to it. + Takes a NeXus file and writes the Dataset information to it. :param nexus_file: The NeXus file. - :param dataset: The StrictDataset. + :param dataset: The Dataset. :param sample_name: The sample name. """ # Top-level group diff --git a/mantidimaging/core/io/test/io_test.py b/mantidimaging/core/io/test/io_test.py index 6e23f7512b9..b4b72693887 100644 --- a/mantidimaging/core/io/test/io_test.py +++ b/mantidimaging/core/io/test/io_test.py @@ -17,7 +17,7 @@ import mantidimaging.test_helpers.unit_test_helper as th from mantidimaging.core.data import ImageStack -from mantidimaging.core.data.dataset import StrictDataset +from mantidimaging.core.data.dataset import Dataset from mantidimaging.core.io import loader from mantidimaging.core.io import saver from mantidimaging.core.io.saver import _rescale_recon_data, _save_recon_to_nexus, _save_processed_data_to_nexus, \ @@ -199,7 +199,7 @@ def test_nexus_simple_dataset_save(self): sample.data *= 12 sample._projection_angles = sample.projection_angles() - sd = StrictDataset(sample=sample) + sd = Dataset(sample=sample) sd.sample.record_operation("", "") path = "nexus/file/path" @@ -243,7 +243,7 @@ def test_nexus_missing_projection_angles_save_as_zeros(self): flat_before = th.generate_images(shape) flat_before._projection_angles = flat_before.projection_angles() - sd = StrictDataset(sample=sample, flat_before=flat_before) + sd = Dataset(sample=sample, flat_before=flat_before) path = "nexus/file/path" sample_name = "sample-name" @@ -267,11 +267,11 @@ def test_nexus_complex_processed_dataset_save(self): image_stacks.append(image_stack) image_stack._projection_angles = image_stack.projection_angles() - sd = StrictDataset(sample=image_stacks[0], - flat_before=image_stacks[1], - flat_after=image_stacks[2], - dark_before=image_stacks[3], - dark_after=image_stacks[4]) + sd = Dataset(sample=image_stacks[0], + flat_before=image_stacks[1], + flat_after=image_stacks[2], + dark_before=image_stacks[3], + dark_after=image_stacks[4]) sd.sample.record_operation("", "") with h5py.File("nexus/file/path", "w", driver="core", backing_store=False) as nexus_file: @@ -306,11 +306,11 @@ def test_nexus_unprocessed_dataset_save(self): image_stacks.append(image_stack) image_stack._projection_angles = image_stack.projection_angles() - sd = StrictDataset(sample=image_stacks[0], - flat_before=image_stacks[1], - flat_after=image_stacks[2], - dark_before=image_stacks[3], - dark_after=image_stacks[4]) + sd = Dataset(sample=image_stacks[0], + flat_before=image_stacks[1], + flat_after=image_stacks[2], + dark_before=image_stacks[3], + dark_after=image_stacks[4]) with h5py.File("nexus/file/path", "w", driver="core", backing_store=False) as nexus_file: saver._nexus_save(nexus_file, sd, "sample-name", True) @@ -327,7 +327,7 @@ def test_nexus_unprocessed_dataset_save(self): def test_h5py_os_error_returns(self, nexus_save_mock: mock.Mock, file_mock: mock.Mock): file_mock.side_effect = OSError with self.assertRaises(RuntimeError): - saver.nexus_save(StrictDataset(sample=th.generate_images()), "path", "sample-name", True) + saver.nexus_save(Dataset(sample=th.generate_images()), "path", "sample-name", True) nexus_save_mock.assert_not_called() @mock.patch("mantidimaging.core.io.saver.h5py.File") @@ -337,14 +337,14 @@ def test_failed_nexus_save_deletes_file(self, os_mock: mock.Mock, nexus_save_moc nexus_save_mock.side_effect = OSError save_path = "failed/save/path" with self.assertRaises(RuntimeError): - saver.nexus_save(StrictDataset(sample=th.generate_images()), save_path, "sample-name", True) + saver.nexus_save(Dataset(sample=th.generate_images()), save_path, "sample-name", True) file_mock.return_value.close.assert_called_once() os_mock.remove.assert_called_once_with(save_path) @mock.patch("mantidimaging.core.io.saver.h5py.File") @mock.patch("mantidimaging.core.io.saver._nexus_save") def test_successful_nexus_save_closes_file(self, nexus_save_mock: mock.Mock, file_mock: mock.Mock): - saver.nexus_save(StrictDataset(sample=th.generate_images()), "path", "sample-name", True) + saver.nexus_save(Dataset(sample=th.generate_images()), "path", "sample-name", True) file_mock.return_value.close.assert_called_once() @mock.patch("mantidimaging.core.io.saver._save_recon_to_nexus") @@ -352,7 +352,7 @@ def test_save_recons_if_present(self, recon_save_mock: mock.Mock): sample = _create_sample_with_filename() sample._projection_angles = sample.projection_angles() - sd = StrictDataset(sample=sample) + sd = Dataset(sample=sample) sd.recons.data = [th.generate_images(), th.generate_images()] with h5py.File("path", "w", driver="core", backing_store=False) as nexus_file: @@ -361,7 +361,7 @@ def test_save_recons_if_present(self, recon_save_mock: mock.Mock): self.assertEqual(recon_save_mock.call_count, len(sd.recons)) def test_save_process(self): - ds = StrictDataset(sample=th.generate_images()) + ds = Dataset(sample=th.generate_images()) process_path = "processed-data/process" with h5py.File("path", "w", driver="core", backing_store=False) as nexus_file: rotation_angle = nexus_file.create_dataset("rotation_angle", dtype="float") @@ -381,7 +381,7 @@ def test_dont_save_recons_if_none_present(self, recon_save_mock: mock.Mock): sample = th.generate_images() sample._projection_angles = sample.projection_angles() - sd = StrictDataset(sample=sample) + sd = Dataset(sample=sample) with h5py.File("path", "w", driver="core", backing_store=False) as nexus_file: saver._nexus_save(nexus_file, sd, "sample-name", True) @@ -393,7 +393,7 @@ def test_save_recon_to_nexus(self): sample = _create_sample_with_filename() sample._projection_angles = sample.projection_angles() - sd = StrictDataset(sample=sample) + sd = Dataset(sample=sample) recon = th.generate_images(seed=2) recon.metadata[TIMESTAMP] = None @@ -432,7 +432,7 @@ def test_use_recon_date_from_image_stack(self): sample = _create_sample_with_filename() sample._projection_angles = sample.projection_angles() - sd = StrictDataset(sample=sample) + sd = Dataset(sample=sample) recon = th.generate_images(seed=2) recon.name = recon_name = "Recon" @@ -470,7 +470,7 @@ def test_raw_file_field(self): self.sample_path) def test_save_image_stacks_to_nexus_as_int(self): - ds = StrictDataset(sample=th.generate_images()) + ds = Dataset(sample=th.generate_images()) with h5py.File("path", "w", driver="core", backing_store=False) as nexus_file: data = nexus_file.create_group("data") From 2c6238d5db1433231b2667b153b7b2511419e3bf Mon Sep 17 00:00:00 2001 From: Sam Tygier Date: Fri, 15 Nov 2024 15:46:17 +0000 Subject: [PATCH 5/6] Remove StrictDataset from BaseEyesTest, SpectrumViewerWindowTest, DatasetSelectorWidgetPresenterTests, SpectrumViewerWindowPresenterTest --- mantidimaging/eyes_tests/base_eyes.py | 4 ++-- mantidimaging/eyes_tests/spectrum_viewer_test.py | 4 ++-- .../gui/widgets/dataset_selector/test/presenter_test.py | 6 +++--- .../gui/windows/spectrum_viewer/test/presenter_test.py | 8 ++++---- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/mantidimaging/eyes_tests/base_eyes.py b/mantidimaging/eyes_tests/base_eyes.py index fef25feadff..ebf2eab1c76 100644 --- a/mantidimaging/eyes_tests/base_eyes.py +++ b/mantidimaging/eyes_tests/base_eyes.py @@ -13,7 +13,7 @@ from PyQt5.QtWidgets import QMainWindow, QMenu, QWidget, QApplication from mantidimaging.core.data import ImageStack -from mantidimaging.core.data.dataset import StrictDataset, Dataset +from mantidimaging.core.data.dataset import Dataset from mantidimaging.core.io.loader import loader from mantidimaging.core.utility.data_containers import Indices from mantidimaging.eyes_tests.eyes_manager import EyesManager @@ -101,7 +101,7 @@ def _load_strict_data_set(self, set_180: bool = False): filename_group = FilenameGroup.from_file(Path(LOAD_SAMPLE)) filename_group.find_all_files() image_stack = loader.load(filename_group, indices=Indices(0, 100, 2)) - dataset = StrictDataset(sample=image_stack) + dataset = Dataset(sample=image_stack) image_stack.name = "Stack 1" self.imaging.presenter.model.add_dataset_to_model(dataset) self.imaging.presenter._add_dataset_to_view(dataset) diff --git a/mantidimaging/eyes_tests/spectrum_viewer_test.py b/mantidimaging/eyes_tests/spectrum_viewer_test.py index a8cefe7b18e..a024d0e3dec 100644 --- a/mantidimaging/eyes_tests/spectrum_viewer_test.py +++ b/mantidimaging/eyes_tests/spectrum_viewer_test.py @@ -2,7 +2,7 @@ # SPDX - License - Identifier: GPL-3.0-or-later from __future__ import annotations from PyQt5.QtWidgets import QApplication -from mantidimaging.core.data.dataset import StrictDataset +from mantidimaging.core.data.dataset import Dataset from mantidimaging.test_helpers.unit_test_helper import generate_images from mantidimaging.eyes_tests.base_eyes import BaseEyesTest @@ -15,7 +15,7 @@ def _generate_spectrum_dataset(self): sample_stack.name = "Sample Stack" open_stack = generate_images(seed=666, shape=(20, 10, 10)) open_stack.name = "Open Beam Stack" - dataset = StrictDataset(sample=sample_stack, flat_before=open_stack) + dataset = Dataset(sample=sample_stack, flat_before=open_stack) self.imaging.presenter.model.add_dataset_to_model(dataset) 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 282ee2e47be..b163bb011f4 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, Dataset +from mantidimaging.core.data.dataset import Dataset from mantidimaging.gui.widgets.dataset_selector.presenter import DatasetSelectorWidgetPresenter, Notification from mantidimaging.gui.widgets.dataset_selector.view import DatasetSelectorWidgetView @@ -29,9 +29,9 @@ def setUp(self) -> None: self.img3.name = "Image 3" self.img4 = mock.Mock(id="img4") self.img4.name = "Image 4" - self.ds1 = StrictDataset(sample=self.img1) + self.ds1 = Dataset(sample=self.img1) self.ds1.name = "Dataset 1" - self.ds2 = StrictDataset(sample=self.img2, flat_before=self.img3) + self.ds2 = Dataset(sample=self.img2, flat_before=self.img3) self.ds2.name = "Dataset 2" self.ds3 = Dataset(stacks=[self.img4]) self.ds3.name = "Dataset 3" diff --git a/mantidimaging/gui/windows/spectrum_viewer/test/presenter_test.py b/mantidimaging/gui/windows/spectrum_viewer/test/presenter_test.py index d6cd7383119..ef6292285fd 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, Dataset +from mantidimaging.core.data.dataset import 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 @@ -54,7 +54,7 @@ def test_get_dataset_id_for_stack(self): def test_handle_sample_change_has_flat_before(self): self.presenter.get_dataset_id_for_stack = mock.Mock(return_value=uuid.uuid4()) - new_dataset = StrictDataset(sample=generate_images([10, 11, 12]), flat_before=generate_images()) + new_dataset = Dataset(sample=generate_images([10, 11, 12]), flat_before=generate_images()) new_dataset.flat_before.name = 'Flat_before' self.presenter.main_window.get_dataset = mock.Mock(return_value=new_dataset) self.presenter.main_window.get_stack = mock.Mock(return_value=generate_images()) @@ -68,7 +68,7 @@ def test_handle_sample_change_has_flat_before(self): def test_handle_sample_change_has_flat_after(self): self.presenter.get_dataset_id_for_stack = mock.Mock(return_value=uuid.uuid4()) - new_dataset = StrictDataset(sample=generate_images(), flat_after=generate_images()) + new_dataset = Dataset(sample=generate_images(), flat_after=generate_images()) new_dataset.flat_after.name = 'Flat_after' self.presenter.main_window.get_dataset = mock.Mock(return_value=new_dataset) self.presenter.main_window.get_stack = mock.Mock(return_value=generate_images()) @@ -118,7 +118,7 @@ def test_handle_sample_change_to_dataset_no_sample(self): def test_handle_sample_change_no_flat(self): self.presenter.get_dataset_id_for_stack = mock.Mock(return_value=uuid.uuid4()) - new_dataset = StrictDataset(sample=generate_images()) + new_dataset = Dataset(sample=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 2b7887a73783592ddc5ccc699af7ad91ead4167c Mon Sep 17 00:00:00 2001 From: Sam Tygier Date: Fri, 15 Nov 2024 15:49:04 +0000 Subject: [PATCH 6/6] Remove StrictDataset --- mantidimaging/core/data/dataset.py | 6 +- .../core/data/test/strictdataset_test.py | 293 ------------------ 2 files changed, 1 insertion(+), 298 deletions(-) delete mode 100644 mantidimaging/core/data/test/strictdataset_test.py diff --git a/mantidimaging/core/data/dataset.py b/mantidimaging/core/data/dataset.py index b0121a83567..f90c06dd76e 100644 --- a/mantidimaging/core/data/dataset.py +++ b/mantidimaging/core/data/dataset.py @@ -176,7 +176,7 @@ def set_stack(self, file_type: FILE_TYPES, image_stack: ImageStack) -> None: if hasattr(self, attr_name): setattr(self, attr_name, image_stack) else: - raise AttributeError(f"StrictDataset does not have an attribute for {attr_name}") + raise AttributeError(f"Dataset does not have an attribute for {attr_name}") def set_stack_by_type_name(self, file_type_name: str, image_stack: ImageStack) -> None: file_type_name = file_type_name.upper().replace(" ", "_") @@ -201,10 +201,6 @@ def is_processed(self) -> bool: return False -class StrictDataset(Dataset): - pass - - def _get_stack_data_type(stack_id: uuid.UUID, dataset: Dataset) -> str: """ Find the data type as a string of a stack. diff --git a/mantidimaging/core/data/test/strictdataset_test.py b/mantidimaging/core/data/test/strictdataset_test.py deleted file mode 100644 index 7864966356e..00000000000 --- a/mantidimaging/core/data/test/strictdataset_test.py +++ /dev/null @@ -1,293 +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 unittest import mock - -import numpy as np - -from mantidimaging.core.data import ImageStack -from mantidimaging.core.data.dataset import StrictDataset, _delete_stack_error_message, _image_key_list, \ - _get_stack_data_type -from mantidimaging.test_helpers.unit_test_helper import generate_images - - -def test_delete_stack_error_message(): - assert _delete_stack_error_message("stack-id") == "Unable to delete stack: ImageStack with ID stack-id not " \ - "present in dataset." - - -def test_image_key_list(): - assert _image_key_list(2, 5) == [2, 2, 2, 2, 2] - - -def _set_fake_projection_angles(image_stack: ImageStack): - """ - Sets the private projection angles attribute. - :param image_stack: The ImageStack object. - """ - image_stack._projection_angles = image_stack.projection_angles() - - -class StrictDatasetTest(unittest.TestCase): - - def setUp(self) -> None: - self.images = [generate_images() for _ in range(5)] - self.strict_dataset = StrictDataset(sample=self.images[0], - flat_before=self.images[1], - flat_after=self.images[2], - dark_before=self.images[3], - dark_after=self.images[4]) - - def test_attribute_not_set_returns_none(self): - sample = generate_images() - dataset = StrictDataset(sample=sample) - - self.assertIsNone(dataset.flat_before) - self.assertIsNone(dataset.flat_after) - self.assertIsNone(dataset.dark_before) - self.assertIsNone(dataset.dark_after) - - def test_cant_change_dataset_id(self): - with self.assertRaises(AttributeError): - self.strict_dataset.id = "id" - - def test_set_flat_before(self): - flat_before = generate_images() - self.strict_dataset.flat_before = flat_before - self.assertIs(flat_before, self.strict_dataset.flat_before) - - def test_set_flat_after(self): - flat_after = generate_images() - self.strict_dataset.flat_after = flat_after - self.assertIs(flat_after, self.strict_dataset.flat_after) - - def test_set_dark_before(self): - dark_before = generate_images() - self.strict_dataset.dark_before = dark_before - self.assertIs(dark_before, self.strict_dataset.dark_before) - - def test_set_dark_after(self): - dark_after = generate_images() - self.strict_dataset.dark_after = dark_after - self.assertIs(dark_after, self.strict_dataset.dark_after) - - def test_all(self): - self.assertListEqual(self.strict_dataset.all, self.images) - - def test_all_images_ids(self): - self.assertListEqual(self.strict_dataset.all_image_ids, [images.id for images in self.images]) - - def test_contains_returns_true(self): - self.assertIn(self.images[2].id, self.strict_dataset) - - def test_contains_returns_false(self): - self.assertNotIn(generate_images().id, self.strict_dataset) - - def test_delete_sample(self): - self.strict_dataset.delete_stack(self.images[0].id) - self.assertIsNone(self.strict_dataset.sample) - - def test_delete_flat_before(self): - self.strict_dataset.delete_stack(self.images[1].id) - self.assertIsNone(self.strict_dataset.flat_before) - - def test_delete_flat_after(self): - self.strict_dataset.delete_stack(self.images[2].id) - self.assertIsNone(self.strict_dataset.flat_after) - - def test_delete_dark_before(self): - self.strict_dataset.delete_stack(self.images[3].id) - self.assertIsNone(self.strict_dataset.dark_before) - - def test_delete_dark_after(self): - self.strict_dataset.delete_stack(self.images[4].id) - self.assertIsNone(self.strict_dataset.dark_after) - - def test_delete_recon(self): - [self.strict_dataset.add_recon(generate_images()) for _ in range(3)] - recons = self.strict_dataset.recons.copy() - - id_to_remove = recons[-1].id - self.strict_dataset.delete_stack(id_to_remove) - self.assertNotIn(recons[-1], self.strict_dataset.all) - - def test_delete_failure(self): - with self.assertRaises(KeyError): - self.strict_dataset.delete_stack("nonexistent-id") - - def test_name(self): - self.strict_dataset.name = dataset_name = "name" - self.assertEqual(self.strict_dataset.name, dataset_name) - - def test_default_name_from_image(self): - mock_sample = mock.create_autospec(ImageStack) - mock_sample.name = "image_name" - ds = StrictDataset(sample=mock_sample) - self.assertEqual(ds.name, "image_name") - - def test_set_180(self): - _180 = generate_images((1, 200, 200)) - self.strict_dataset.proj180deg = _180 - self.assertIs(self.strict_dataset.proj180deg, _180) - self.assertIs(self.strict_dataset.sample.proj180deg, _180) - - def test_remove_180(self): - _180 = generate_images((1, 200, 200)) - self.strict_dataset.proj180deg = _180 - self.strict_dataset.delete_stack(_180.id) - self.assertIsNone(self.strict_dataset.proj180deg) - self.assertIsNone(self.strict_dataset.sample.proj180deg) - - def test_sinograms(self): - self.strict_dataset.sinograms = sinograms = generate_images() - self.assertIs(self.strict_dataset.sinograms, sinograms) - - def test_delete_sinograms(self): - self.strict_dataset.sinograms = sinograms = generate_images() - self.strict_dataset.delete_stack(sinograms.id) - self.assertIsNone(self.strict_dataset.sinograms) - - def test_delete_all_recons(self): - [self.strict_dataset.add_recon(generate_images()) for _ in range(3)] - self.strict_dataset.delete_recons() - self.assertListEqual(self.strict_dataset.recons.stacks, []) - - def test_nexus_stack_order(self): - self.assertListEqual(self.strict_dataset._nexus_stack_order, [ - self.strict_dataset.dark_before, self.strict_dataset.flat_before, self.strict_dataset.sample, - self.strict_dataset.flat_after, self.strict_dataset.dark_after - ]) - - def test_nexus_arrays(self): - self.assertListEqual(self.strict_dataset.nexus_arrays, [ - self.strict_dataset.dark_before.data, self.strict_dataset.flat_before.data, self.strict_dataset.sample.data, - self.strict_dataset.flat_after.data, self.strict_dataset.dark_after.data - ]) - - def test_image_keys(self): - self.strict_dataset.dark_before = generate_images((2, 5, 5)) - self.strict_dataset.flat_before = generate_images((2, 5, 5)) - self.strict_dataset.sample = generate_images((2, 5, 5)) - self.strict_dataset.flat_after = generate_images((2, 5, 5)) - self.strict_dataset.dark_after = generate_images((2, 5, 5)) - - self.assertListEqual(self.strict_dataset.image_keys, [2, 2, 1, 1, 0, 0, 1, 1, 2, 2]) - - def test_missing_dark_before_image_keys(self): - self.strict_dataset.dark_before = None - self.strict_dataset.flat_before = generate_images((2, 5, 5)) - self.strict_dataset.sample = generate_images((2, 5, 5)) - self.strict_dataset.flat_after = generate_images((2, 5, 5)) - self.strict_dataset.dark_after = generate_images((2, 5, 5)) - - self.assertListEqual(self.strict_dataset.image_keys, [1, 1, 0, 0, 1, 1, 2, 2]) - - def test_missing_flat_before_image_keys(self): - self.strict_dataset.dark_before = generate_images((2, 5, 5)) - self.strict_dataset.flat_before = None - self.strict_dataset.sample = generate_images((2, 5, 5)) - self.strict_dataset.flat_after = generate_images((2, 5, 5)) - self.strict_dataset.dark_after = generate_images((2, 5, 5)) - - self.assertListEqual(self.strict_dataset.image_keys, [2, 2, 0, 0, 1, 1, 2, 2]) - - def test_missing_flat_after_image_keys(self): - self.strict_dataset.dark_before = generate_images((2, 5, 5)) - self.strict_dataset.flat_before = generate_images((2, 5, 5)) - self.strict_dataset.sample = generate_images((2, 5, 5)) - self.strict_dataset.flat_after = None - self.strict_dataset.dark_after = generate_images((2, 5, 5)) - - self.assertListEqual(self.strict_dataset.image_keys, [2, 2, 1, 1, 0, 0, 2, 2]) - - def test_missing_dark_after_image_keys(self): - self.strict_dataset.dark_before = generate_images((2, 5, 5)) - self.strict_dataset.flat_before = generate_images((2, 5, 5)) - self.strict_dataset.sample = generate_images((2, 5, 5)) - self.strict_dataset.flat_after = generate_images((2, 5, 5)) - self.strict_dataset.dark_after = None - - self.assertListEqual(self.strict_dataset.image_keys, [2, 2, 1, 1, 0, 0, 1, 1]) - - def test_no_sample_image_keys(self): - self.strict_dataset.sample = None - with self.assertRaises(RuntimeError): - _ = self.strict_dataset.image_keys - - def test_rotation_angles(self): - for stack in self.strict_dataset._nexus_stack_order: - _set_fake_projection_angles(stack) - assert np.array_equal(self.strict_dataset.nexus_rotation_angles, [ - self.strict_dataset.dark_before.projection_angles().value, - self.strict_dataset.flat_before.projection_angles().value, - self.strict_dataset.sample.projection_angles().value, - self.strict_dataset.flat_after.projection_angles().value, - self.strict_dataset.dark_after.projection_angles().value - ]) - - def test_incomplete_nexus_rotation_angles(self): - expected_list = [] - for stack in self.strict_dataset._nexus_stack_order: - expected_list.append(np.zeros(stack.num_images)) - - assert np.array_equal(expected_list, self.strict_dataset.nexus_rotation_angles) - - def test_partially_incomplete_nexus_rotation_angles(self): - _set_fake_projection_angles(self.strict_dataset.dark_before) - _set_fake_projection_angles(self.strict_dataset.flat_before) - _set_fake_projection_angles(self.strict_dataset.dark_after) - expected_list = [ - self.strict_dataset.dark_before.projection_angles().value, - self.strict_dataset.flat_before.projection_angles().value, - np.zeros(self.strict_dataset.sample.num_images), - np.zeros(self.strict_dataset.flat_after.num_images), - self.strict_dataset.dark_after.projection_angles().value - ] - - assert np.array_equal(expected_list, self.strict_dataset.nexus_rotation_angles) - - def test_get_stack_data_type_returns_sample(self): - sample = generate_images() - sample_id = sample.id - dataset = StrictDataset(sample=sample) - self.assertEqual(_get_stack_data_type(sample_id, dataset), "Sample") - - def test_get_stack_data_type_returns_flat_before(self): - flat_before = generate_images() - flat_before_id = flat_before.id - dataset = StrictDataset(sample=generate_images(), flat_before=flat_before) - self.assertEqual(_get_stack_data_type(flat_before_id, dataset), "Flat Before") - - def test_get_stack_data_type_returns_flat_after(self): - flat_after = generate_images() - flat_after_id = flat_after.id - dataset = StrictDataset(sample=generate_images(), flat_after=flat_after) - self.assertEqual(_get_stack_data_type(flat_after_id, dataset), "Flat After") - - def test_get_stack_data_type_returns_dark_before(self): - dark_before = generate_images() - dark_before_id = dark_before.id - dataset = StrictDataset(sample=generate_images(), dark_before=dark_before) - self.assertEqual(_get_stack_data_type(dark_before_id, dataset), "Dark Before") - - def test_get_stack_data_type_returns_dark_after(self): - dark_after = generate_images() - dark_after_id = dark_after.id - dataset = StrictDataset(sample=generate_images(), dark_after=dark_after) - self.assertEqual(_get_stack_data_type(dark_after_id, dataset), "Dark After") - - def test_get_stack_data_type_raises(self): - empty_ds = StrictDataset(sample=generate_images()) - with self.assertRaises(RuntimeError): - _get_stack_data_type("bad-id", empty_ds) - - def test_processed_is_true(self): - ds = StrictDataset(sample=generate_images()) - ds.sample.record_operation("", "") - self.assertTrue(ds.is_processed) - - def test_processed_is_false(self): - ds = StrictDataset(sample=generate_images()) - self.assertFalse(ds.is_processed)