Ejemplo n.º 1
0
    def test_do_load_stack_sample_and_flat(self, load_p_mock: mock.Mock, load_log_mock: mock.Mock):
        lp = LoadingParameters()
        sample_mock = mock.Mock()
        lp.sample = sample_mock
        lp.dtype = "dtype_test"
        lp.sinograms = False
        lp.pixel_size = 101

        flat_before_mock = mock.Mock()
        lp.flat_before = flat_before_mock
        flat_after_mock = mock.Mock()
        lp.flat_after = flat_after_mock
        progress_mock = mock.Mock()

        self.model.do_load_stack(lp, progress_mock)

        load_p_mock.assert_has_calls([
            mock.call(sample_mock, lp.dtype, progress_mock),
            mock.call(flat_before_mock, lp.dtype, progress_mock),
            mock.call(flat_after_mock, lp.dtype, progress_mock)
        ])
        load_log_mock.assert_has_calls([
            mock.call(sample_mock.log_file),
            mock.call(flat_before_mock.log_file),
            mock.call(flat_after_mock.log_file)
        ])
Ejemplo n.º 2
0
    def test_do_load_stack_sample_and_sample_log(self, load_p_mock: mock.Mock, load_log_mock: mock.Mock):
        lp = LoadingParameters()
        sample_mock = mock.Mock()
        lp.sample = sample_mock
        lp.dtype = "dtype_test"
        lp.sinograms = False
        lp.pixel_size = 101
        progress_mock = mock.Mock()

        self.model.do_load_stack(lp, progress_mock)

        load_p_mock.assert_called_once_with(sample_mock, lp.dtype, progress_mock)
        load_log_mock.assert_called_once_with(sample_mock.log_file)
Ejemplo n.º 3
0
    def test_do_load_stack_sample_and_flat(self, dataset_mock: mock.Mock,
                                           load_p_mock: mock.Mock,
                                           load_log_mock: mock.Mock):
        lp = LoadingParameters()
        sample_mock = mock.Mock()
        lp.sample = sample_mock
        lp.dtype = "dtype_test"
        lp.sinograms = False
        lp.pixel_size = 101

        flat_before_mock = mock.Mock()
        lp.flat_before = flat_before_mock
        flat_after_mock = mock.Mock()
        lp.flat_after = flat_after_mock
        progress_mock = mock.Mock()

        sample_images_mock = mock.Mock()
        flatb_images_mock = mock.Mock()
        flata_images_mock = mock.Mock()
        load_p_mock.side_effect = [
            sample_images_mock, flatb_images_mock, flata_images_mock
        ]

        ds_mock = dataset_mock.return_value

        self.model.do_load_dataset(lp, progress_mock)

        load_p_mock.assert_has_calls([
            mock.call(sample_mock, lp.dtype, progress_mock),
            mock.call(flat_before_mock, lp.dtype, progress_mock),
            mock.call(flat_after_mock, lp.dtype, progress_mock)
        ])
        load_log_mock.assert_has_calls([
            mock.call(sample_mock.log_file),
            mock.call(flat_before_mock.log_file),
            mock.call(flat_after_mock.log_file)
        ])

        dataset_mock.assert_called_with(sample_images_mock)
        assert ds_mock.flat_before == flatb_images_mock
        assert ds_mock.flat_after == flata_images_mock
Ejemplo n.º 4
0
    def get_parameters(self) -> LoadingParameters:
        lp = LoadingParameters()
        sample_log = self.view.sample_log.path_text(
        ) if self.view.sample_log.use.isChecked() else None
        lp.sample = ImageParameters(input_path=self.view.sample.directory(),
                                    format=self.image_format,
                                    prefix=get_prefix(
                                        self.view.sample.path_text()),
                                    indices=self.view.sample.indices,
                                    log_file=sample_log)

        lp.name = self.view.sample.file()
        lp.pixel_size = self.view.pixelSize.value()

        if self.view.flat_before.use.isChecked(
        ) and self.view.flat_before.path_text() != "":
            flat_before_log = self.view.flat_before_log.path_text() if self.view.flat_before_log.use.isChecked() \
                else None
            lp.flat_before = ImageParameters(
                input_path=self.view.flat_before.directory(),
                prefix=get_prefix(self.view.flat_before.path_text()),
                format=self.image_format,
                log_file=flat_before_log)

        if self.view.flat_after.use.isChecked(
        ) and self.view.flat_after.path_text() != "":
            flat_after_log = self.view.flat_after_log.path_text() if self.view.flat_after_log.use.isChecked() \
                else None
            lp.flat_after = ImageParameters(
                input_path=self.view.flat_after.directory(),
                prefix=get_prefix(self.view.flat_after.path_text()),
                format=self.image_format,
                log_file=flat_after_log)

        if self.view.dark_before.use.isChecked(
        ) and self.view.dark_before.path_text() != "":
            lp.dark_before = ImageParameters(
                input_path=self.view.dark_before.directory(),
                prefix=get_prefix(self.view.dark_before.path_text()),
                format=self.image_format)

        if self.view.dark_after.use.isChecked(
        ) and self.view.dark_after.path_text() != "":
            lp.dark_after = ImageParameters(
                input_path=self.view.dark_after.directory(),
                prefix=get_prefix(self.view.dark_after.path_text()),
                format=self.image_format)

        if self.view.proj_180deg.use.isChecked(
        ) and self.view.proj_180deg.path_text() != "":
            lp.proj_180deg = ImageParameters(
                input_path=self.view.proj_180deg.directory(),
                prefix=os.path.splitext(self.view.proj_180deg.path_text())[0],
                format=self.image_format)

        lp.dtype = self.view.pixel_bit_depth.currentText()
        lp.sinograms = self.view.images_are_sinograms.isChecked()
        lp.pixel_size = self.view.pixelSize.value()

        return lp
Ejemplo n.º 5
0
    def get_parameters(self) -> LoadingParameters:
        lp = LoadingParameters()
        lp.sample = ImageParameters(input_path=self.view.sample.directory(),
                                    format=self.image_format,
                                    prefix=get_prefix(
                                        self.view.sample.path_text()),
                                    indices=self.view.sample.indices,
                                    log_file=self.view.sample_log.path_text())

        lp.name = self.view.sample.file()
        lp.pixel_size = self.view.pixelSize.value()

        if self.view.flat.use and self.view.flat.path_text() != "":
            lp.flat = ImageParameters(input_path=self.view.flat.directory(),
                                      prefix=get_prefix(
                                          self.view.flat.path_text()),
                                      format=self.image_format)

        if self.view.dark.use and self.view.dark.path_text() != "":
            lp.dark = ImageParameters(input_path=self.view.dark.directory(),
                                      prefix=get_prefix(
                                          self.view.dark.path_text()),
                                      format=self.image_format)
        if self.view.proj_180deg.use and self.view.proj_180deg.path_text(
        ) != "":
            lp.proj_180deg = ImageParameters(
                input_path=self.view.proj_180deg.directory(),
                prefix=get_prefix(self.view.proj_180deg.path_text()),
                format=self.image_format)

        lp.dtype = self.view.pixel_bit_depth.currentText()
        lp.sinograms = self.view.images_are_sinograms.isChecked()
        lp.pixel_size = self.view.pixelSize.value()

        return lp
Ejemplo n.º 6
0
def create_loading_parameters_for_file_path(
        file_path: str,
        logger: Optional[Logger] = None) -> Optional[LoadingParameters]:
    sample_file = find_first_file_that_is_possibly_a_sample(file_path)
    if sample_file is None:
        return None

    loading_parameters = LoadingParameters()
    loading_parameters.dtype = DEFAULT_PIXEL_DEPTH
    loading_parameters.pixel_size = DEFAULT_PIXEL_SIZE
    loading_parameters.sinograms = DEFAULT_IS_SINOGRAM
    loading_parameters.name = os.path.basename(sample_file)
    _, image_format = os.path.splitext(sample_file)
    sample_directory = os.path.dirname(sample_file)
    last_file_info = read_in_file_information(
        sample_directory,
        in_prefix=get_prefix(sample_file),
        in_format=image_format)

    try:
        sample_log: Optional[str] = find_and_verify_sample_log(
            sample_directory, last_file_info.filenames)
    except FileNotFoundError:
        sample_log = None

    loading_parameters.sample = ImageParameters(input_path=sample_directory,
                                                format=image_format,
                                                prefix=get_prefix(sample_file),
                                                log_file=sample_log)

    # Flat before
    flat_before_images = find_images(Path(sample_directory),
                                     "Flat",
                                     suffix="Before",
                                     look_without_suffix=True,
                                     image_format=image_format,
                                     logger=logger)
    if len(flat_before_images) > 0:
        flat_before_image = flat_before_images[0]
        flat_before_directory = os.path.dirname(flat_before_image)
        flat_before_log = find_log(Path(sample_directory),
                                   flat_before_directory, logger)

        loading_parameters.flat_before = ImageParameters(
            input_path=flat_before_directory,
            format=image_format,
            prefix=get_prefix(flat_before_image),
            log_file=flat_before_log)

    # Flat after
    flat_after_images = find_images(Path(sample_directory),
                                    "Flat",
                                    suffix="After",
                                    image_format=image_format,
                                    logger=logger)
    if len(flat_after_images) > 0:
        flat_after_image = flat_after_images[0]
        flat_after_directory = os.path.dirname(flat_after_image)
        flat_after_log = find_log(Path(sample_directory), flat_after_directory,
                                  logger)

        loading_parameters.flat_after = ImageParameters(
            input_path=flat_after_directory,
            format=image_format,
            prefix=get_prefix(flat_after_image),
            log_file=flat_after_log)

    # Dark before
    dark_before_images = find_images(Path(sample_directory),
                                     "Dark",
                                     suffix="Before",
                                     look_without_suffix=True,
                                     image_format=image_format,
                                     logger=logger)
    if len(dark_before_images) > 0:
        dark_before_image = dark_before_images[0]
        dark_before_directory = os.path.dirname(dark_before_image)
        loading_parameters.dark_before = ImageParameters(
            input_path=dark_before_directory,
            prefix=get_prefix(dark_before_image),
            format=image_format)

    # Dark after
    dark_after_images = find_images(Path(sample_directory),
                                    "Dark",
                                    suffix="After",
                                    image_format=image_format,
                                    logger=logger)
    if len(dark_after_images) > 0:
        dark_after_image = dark_after_images[0]
        dark_after_directory = os.path.dirname(dark_after_image)
        loading_parameters.dark_after = ImageParameters(
            input_path=dark_after_directory,
            prefix=get_prefix(dark_after_image),
            format=image_format)

    # 180 Degree projection
    proj_180deg = find_180deg_proj(Path(sample_directory), image_format,
                                   logger)
    if proj_180deg != "":
        loading_parameters.proj_180deg = ImageParameters(
            input_path=proj_180deg,
            prefix=get_prefix(proj_180deg),
            format=image_format)

    return loading_parameters