Пример #1
0
 def setUp(self) -> None:
     self.images = [generate_images() for _ in range(5)]
     self.dataset = Dataset(sample=self.images[0],
                            flat_before=self.images[1],
                            flat_after=self.images[2],
                            dark_before=self.images[3],
                            dark_after=self.images[4])
Пример #2
0
    def test_create_new_stack_dataset(self):
        dock_mock = mock.Mock()
        stack_visualiser_mock = mock.Mock()

        dock_mock.widget.return_value = stack_visualiser_mock
        dock_mock.windowTitle.return_value = "somename"
        self.view.create_stack_window.return_value = dock_mock
        self.view.active_stacks_changed.emit = mock.Mock()

        ds = Dataset(sample=generate_images(automatic_free=False),
                     flat_before=generate_images(automatic_free=False),
                     flat_after=generate_images(automatic_free=False),
                     dark_before=generate_images(automatic_free=False),
                     dark_after=generate_images(automatic_free=False))
        ds.flat_before.filenames = ["filename"] * 10
        ds.dark_before.filenames = ["filename"] * 10
        ds.flat_after.filenames = ["filename"] * 10
        ds.dark_after.filenames = ["filename"] * 10

        self.presenter.create_new_stack(ds, "My title")

        self.assertEqual(5, len(self.presenter.model.stack_list))
        self.view.active_stacks_changed.emit.assert_called_once()

        ds.sample.free_memory()
        ds.flat_before.free_memory()
        ds.dark_before.free_memory()
        ds.flat_after.free_memory()
        ds.dark_after.free_memory()
Пример #3
0
    def test_attribute_not_set_returns_none(self):
        sample = generate_images()
        dataset = Dataset(sample)

        self.assertIsNone(dataset.flat_before)
        self.assertIsNone(dataset.flat_after)
        self.assertIsNone(dataset.dark_before)
        self.assertIsNone(dataset.dark_after)
Пример #4
0
 def test_image_ids(self):
     all_ids = []
     for _ in range(3):
         images = [generate_images() for _ in range(3)]
         all_ids += [image.id for image in images]
         ds = Dataset(*images)
         self.model.add_dataset_to_model(ds)
     self.assertListEqual(all_ids, self.model.image_ids)
Пример #5
0
    def test_remove_images_from_dataset(self):
        images = [generate_images() for _ in range(2)]
        ds = Dataset(*images)
        self.model.datasets[ds.id] = ds

        self.assertIsNotNone(ds.flat_before)
        self.model.remove_container(images[-1].id)
        self.assertIsNone(ds.flat_before)
Пример #6
0
    def test_set_images_by_uuid_success(self):
        prev_images = generate_images()
        new_data = generate_images().data
        ds = Dataset(prev_images)
        self.model.datasets[ds.id] = ds

        self.model.set_image_data_by_uuid(prev_images.id, new_data)
        assert_array_equal(ds.sample.data, new_data)
Пример #7
0
    def do_load_stack(self, parameters: LoadingParameters, progress):
        ds = Dataset(loader.load_p(parameters.sample, parameters.dtype, progress))
        ds.sample._is_sinograms = parameters.sinograms
        ds.sample.pixel_size = parameters.pixel_size

        if parameters.sample.log_file:
            ds.sample.log_file = loader.load_log(parameters.sample.log_file)

        if parameters.flat:
            ds.flat = loader.load_p(parameters.flat, parameters.dtype, progress)
            if parameters.flat.log_file:
                ds.flat.log_file = loader.load_log(parameters.flat.log_file)
        if parameters.dark:
            ds.dark = loader.load_p(parameters.dark, parameters.dtype, progress)
        if parameters.proj_180deg:
            ds.sample.proj180deg = loader.load_p(parameters.proj_180deg, parameters.dtype, progress)

        return ds
Пример #8
0
    def test_add_recon_to_dataset(self):
        sample = generate_images()
        sample_id = sample.id
        ds = Dataset(sample)

        recon = generate_images()
        self.model.add_dataset_to_model(ds)
        self.model.add_recon_to_dataset(recon, sample_id)
        self.assertIn(recon, ds.all)
Пример #9
0
    def test_remove_dataset_from_model(self):
        images = [generate_images() for _ in range(5)]
        ids = [image_stack.id for image_stack in images]

        ds = Dataset(*images)
        self.model.datasets[ds.id] = ds

        stacks_to_close = self.model.remove_container(ds.id)
        self.assertNotIn(ds, self.model.datasets.values())
        self.assertListEqual(stacks_to_close, ids)
Пример #10
0
    def test_add_180_deg_to_dataset(self, load: mock.Mock):
        _180_file = "180 file"
        dataset_id = "id"
        self.model.datasets[dataset_id] = dataset_mock = Dataset(
            generate_images())
        load.return_value.sample = _180_stack = generate_images()
        self.model.add_180_deg_to_dataset(dataset_id=dataset_id,
                                          _180_deg_file=_180_file)

        load.assert_called_with(file_names=[_180_file])
        self.assertEqual(_180_stack, dataset_mock.proj180deg)
Пример #11
0
 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.
     """
     sample_images = self._create_sample_images()
     sample_images.name = self.title
     return Dataset(
         sample=sample_images,
         flat_before=self._create_images_if_required(
             self.flat_before_array, "Flat Before"),
         flat_after=self._create_images_if_required(self.flat_after_array,
                                                    "Flat After"),
         dark_before=self._create_images_if_required(
             self.dark_before_array, "Dark Before"),
         dark_after=self._create_images_if_required(self.dark_after_array,
                                                    "Dark After"),
         name=self.title), self.title
Пример #12
0
    def setUp(self):
        self.view = mock.create_autospec(MainWindowView)
        self.view.load_dialogue = mock.create_autospec(MWLoadDialog)
        self.presenter = MainWindowPresenter(self.view)
        self.images = [generate_images() for _ in range(5)]
        self.dataset = Dataset(sample=self.images[0],
                               flat_before=self.images[1],
                               flat_after=self.images[2],
                               dark_before=self.images[3],
                               dark_after=self.images[4])
        self.presenter.model = self.model = mock.Mock()

        self.view.create_stack_window.return_value = dock_mock = mock.Mock()
        self.view.model_changed = mock.Mock()
        self.view.dataset_tree_widget = mock.Mock()

        def stack_id():
            return uuid.uuid4()

        type(dock_mock).uuid = mock.PropertyMock(side_effect=stack_id)
Пример #13
0
    def test_dataset_list(self):
        dataset_1 = Dataset(generate_images())
        dataset_1.name = "dataset-1"
        dataset_2 = Dataset(generate_images())
        dataset_2.name = "dataset-2"
        stack_dataset = StackDataset([generate_images()])

        self.model.datasets = {
            "id1": dataset_1,
            "id2": dataset_2,
            "id3": stack_dataset
        }

        dataset_list = self.presenter.dataset_list
        assert len(dataset_list) == 2
Пример #14
0
    def do_load_dataset(self, parameters: LoadingParameters,
                        progress) -> Dataset:
        sample = loader.load_p(parameters.sample, parameters.dtype, progress)
        ds = Dataset(sample)

        sample._is_sinograms = parameters.sinograms
        sample.pixel_size = parameters.pixel_size

        if parameters.sample.log_file:
            ds.sample.log_file = loader.load_log(parameters.sample.log_file)

        if parameters.flat_before:
            flat_before = loader.load_p(parameters.flat_before,
                                        parameters.dtype, progress)
            ds.flat_before = flat_before
            if parameters.flat_before.log_file:
                flat_before.log_file = loader.load_log(
                    parameters.flat_before.log_file)
        if parameters.flat_after:
            flat_after = loader.load_p(parameters.flat_after, parameters.dtype,
                                       progress)
            ds.flat_after = flat_after
            if parameters.flat_after.log_file:
                flat_after.log_file = loader.load_log(
                    parameters.flat_after.log_file)

        if parameters.dark_before:
            dark_before = loader.load_p(parameters.dark_before,
                                        parameters.dtype, progress)
            ds.dark_before = dark_before
        if parameters.dark_after:
            dark_after = loader.load_p(parameters.dark_after, parameters.dtype,
                                       progress)
            ds.dark_after = dark_after

        if parameters.proj_180deg:
            sample.proj180deg = loader.load_p(parameters.proj_180deg,
                                              parameters.dtype, progress)

        self.datasets[ds.id] = ds
        return ds
Пример #15
0
class DatasetTest(unittest.TestCase):
    def setUp(self) -> None:
        self.images = [generate_images() for _ in range(5)]
        self.dataset = Dataset(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 = Dataset(sample)

        self.assertIsNone(dataset.flat_before)
        self.assertIsNone(dataset.flat_after)
        self.assertIsNone(dataset.dark_before)
        self.assertIsNone(dataset.dark_after)

    def test_replace_success(self):
        sample_id = self.images[0].id
        new_sample_data = generate_images().data
        self.dataset.replace(sample_id, new_sample_data)
        assert array_equal(self.dataset.sample.data, new_sample_data)

    def test_replace_failure(self):
        with self.assertRaises(KeyError):
            self.dataset.replace("nonexistent-id", generate_images().data)

    def test_cant_change_dataset_id(self):
        with self.assertRaises(Exception):
            self.dataset.id = "id"

    def test_set_flat_before(self):
        flat_before = generate_images()
        self.dataset.flat_before = flat_before
        assert flat_before is self.dataset.flat_before

    def test_set_flat_after(self):
        flat_after = generate_images()
        self.dataset.flat_after = flat_after
        assert flat_after is self.dataset.flat_after

    def test_set_dark_before(self):
        dark_before = generate_images()
        self.dataset.dark_before = dark_before
        assert dark_before is self.dataset.dark_before

    def test_set_dark_after(self):
        dark_after = generate_images()
        self.dataset.dark_after = dark_after
        assert dark_after is self.dataset.dark_after

    def test_all(self):
        self.assertListEqual(self.dataset.all, self.images)

    def test_all_images_ids(self):
        self.assertListEqual(self.dataset.all_image_ids, [images.id for images in self.images])

    def test_contains_returns_true(self):
        assert self.images[2].id in self.dataset

    def test_contains_returns_false(self):
        assert not generate_images().id in self.dataset

    def test_delete_sample(self):
        self.dataset.delete_stack(self.images[0].id)
        self.assertIsNone(self.dataset.sample)

    def test_delete_flat_before(self):
        self.dataset.delete_stack(self.images[1].id)
        self.assertIsNone(self.dataset.flat_before)

    def test_delete_flat_after(self):
        self.dataset.delete_stack(self.images[2].id)
        self.assertIsNone(self.dataset.flat_after)

    def test_delete_dark_before(self):
        self.dataset.delete_stack(self.images[3].id)
        self.assertIsNone(self.dataset.dark_before)

    def test_delete_dark_after(self):
        self.dataset.delete_stack(self.images[4].id)
        self.assertIsNone(self.dataset.dark_after)

    def test_delete_recon(self):
        recons = [generate_images() for _ in range(2)]
        self.dataset.recons = recons.copy()

        id_to_remove = recons[-1].id
        self.dataset.delete_stack(id_to_remove)
        self.assertNotIn(recons[-1], self.dataset.all)

    def test_delete_failure(self):
        with self.assertRaises(KeyError):
            self.dataset.delete_stack("nonexistent-id")

    def test_name(self):
        self.dataset.name = dataset_name = "name"
        assert self.dataset.name == dataset_name

    def test_set_180(self):
        _180 = generate_images((1, 200, 200))
        self.dataset.proj180deg = _180
        assert self.dataset.proj180deg is _180
        assert self.dataset.sample.proj180deg is _180

    def test_remove_180(self):
        _180 = generate_images((1, 200, 200))
        self.dataset.proj180deg = _180
        self.dataset.delete_stack(_180.id)
        self.assertIsNone(self.dataset.proj180deg)
        self.assertIsNone(self.dataset.sample.proj180deg)
Пример #16
0
 def test_add_dataset_to_model(self):
     ds = Dataset(generate_images())
     self.model.add_dataset_to_model(ds)
     self.assertIn(ds, self.model.datasets.values())