Esempio n. 1
0
    def test_recon_fails_ok(self):
        import IMAT.tomorec.reconstruction_command as cmd
        cmd = cmd.ReconstructionCommand()

        with self.assertRaises(ValueError):
            cmd.do_recon('', cmd_line='')

        import IMAT.tomorec.configs as cfgs
        pre_conf = cfgs.PreProcConfig()
        alg_conf = cfgs.ToolAlgorithmConfig()
        post_conf = cfgs.PostProcConfig()
        conf = cfgs.ReconstructionConfig(pre_conf, alg_conf, post_conf)
        with self.assertRaises(ValueError):
            cmd.do_recon(conf, cmd_line='irrelevant')

        pre_conf.input_dir = self.test_input_dir
        import IMAT.tomorec.io as tomoio
        tomoio.make_dirs_if_needed(self.test_input_dir)
        conf = cfgs.ReconstructionConfig(pre_conf, alg_conf, post_conf)
        with self.assertRaises(ValueError):
            cmd.do_recon(conf, cmd_line='irrelevant')

        post_conf.output_dir = self.test_output_dir
        tomoio.make_dirs_if_needed(self.test_output_dir)
        conf = cfgs.ReconstructionConfig(pre_conf, alg_conf, post_conf)
        # should fail because no images found in input dir
        with self.assertRaises(RuntimeError):
            cmd.do_recon(conf, cmd_line='irrelevant')

        import os
        self.assertTrue(os.path.exists(self.test_input_dir))
        self.assertTrue(os.path.exists(os.path.join(self.test_output_dir,
                                                    '0.README_reconstruction.txt')))
        self.assertTrue(os.path.exists(self.test_output_dir))
Esempio n. 2
0
    def test_normalize_flat_raises(self):
        import IMAT.tomorec.reconstruction_command as cmd
        cmd = cmd.ReconstructionCommand()

        import IMAT.tomorec.configs as cfgs
        pre_conf = cfgs.PreProcConfig()
        alg_conf = cfgs.ToolAlgorithmConfig()
        post_conf = cfgs.PostProcConfig()
        conf = cfgs.ReconstructionConfig(pre_conf, alg_conf, post_conf)

        # absolutely invalid data
        with self.assertRaises(ValueError):
            cmd.normalize_flat_dark([], pre_conf, np.ones((10, 23)), None)

        # wrong data dimensions
        with self.assertRaises(ValueError):
            cmd.normalize_flat_dark(np.ones((3, 2)), pre_conf, np.ones((10, 23)), None)

        # wrong dimensions of the flat image
        with self.assertRaises(ValueError):
            cmd.normalize_flat_dark(self.data_vol, pre_conf, np.ones((10, 23)), None)

        # invalid configurations
        with self.assertRaises(ValueError):
            cmd.normalize_flat_dark(self.data_vol, alg_conf, None, None)

        with self.assertRaises(ValueError):
            cmd.normalize_flat_dark(self.data_vol, post_conf, None, None)

        with self.assertRaises(ValueError):
            cmd.normalize_flat_dark(self.data_vol, conf, None, None)
    def __init__(self):
        self._PREPROC_IMGS_SUBDIR_NAME = 'preproc_images'
        self._OUT_README_FNAME = '0.README_reconstruction.txt'
        self._OUT_SLICES_FILENAME_PREFIX='out_recon_slice'
        self._OUT_HORIZ_SLICES_SUBDIR='out_recon_horiz_slice'

        self.preproc_cfg = tomocfg.PreProcConfig()
        self.alg_cfg = tomocfg.ToolAlgorithmConfig
        self.postproc_cfg = tomocfg.PostProcConfig()
Esempio n. 4
0
    def test_config_post(self):
        """
        Basic consistency check of the post-processing config and some default
        values
        """
        import IMAT.tomorec.configs as cfgs

        post = cfgs.PostProcConfig()
        self.assertEquals(post.output_dir, None)
        self.assertEquals(post.circular_mask, 0.94)
Esempio n. 5
0
    def test_config_all(self):
        """
        Basic consistency check of the tomographic reconstruction config and some
        default values
        """
        import IMAT.tomorec.configs as cfgs

        pre_conf = cfgs.PreProcConfig()
        alg_conf = cfgs.ToolAlgorithmConfig()
        post_conf = cfgs.PostProcConfig()
        conf = cfgs.ReconstructionConfig(pre_conf, alg_conf, post_conf)

        self.assertEquals(conf.preproc_cfg, pre_conf)
        self.assertEquals(conf.alg_cfg, alg_conf)
        self.assertEquals(conf.postproc_cfg, post_conf)

        print conf
Esempio n. 6
0
    def test_normalize_air_raises(self):
        import IMAT.tomorec.reconstruction_command as cmd
        cmd = cmd.ReconstructionCommand()

        import IMAT.tomorec.configs as cfgs
        pre_conf = cfgs.PreProcConfig()
        alg_conf = cfgs.ToolAlgorithmConfig()
        post_conf = cfgs.PostProcConfig()
        conf = cfgs.ReconstructionConfig(pre_conf, alg_conf, post_conf)

        normalized = cmd.normalize_air_region(self.data_vol, pre_conf)
        np.testing.assert_allclose(normalized, self.data_vol,
                                   err_msg="Epected normalized data volume not to changed")

        # absolutely invalid data
        with self.assertRaises(ValueError):
            cmd.normalize_air_region([], pre_conf)

        # wrong data dimensions
        with self.assertRaises(ValueError):
            cmd.normalize_air_region(np.ones((3, 2)), pre_conf)

        # invalid configurations
        with self.assertRaises(ValueError):
            cmd.normalize_air_region(self.data_vol, alg_conf)

        with self.assertRaises(ValueError):
            cmd.normalize_air_region(self.data_vol, post_conf)

        with self.assertRaises(ValueError):
            cmd.normalize_air_region(self.data_vol, conf)

        # wrong air-regions
        pre_conf.normalize_air_region = [3]
        with self.assertRaises(ValueError):
            cmd.normalize_air_region(self.data_vol, pre_conf)

        pre_conf.normalize_air_region = (3, 0, 100, 10)
        with self.assertRaises(ValueError):
            cmd.normalize_air_region(self.data_vol, pre_conf)

        pre_conf.normalize_air_region = [3, 0, 100]
        with self.assertRaises(ValueError):
            cmd.normalize_air_region(self.data_vol, pre_conf)
Esempio n. 7
0
def grab_postproc_options(args):
    """
    Get post-processing (on the reconstructed volume) options from the command line
    (through an argument parser)

    @param parser :: arguments parsed already, set up with post-processing options

    Returns:: a post-processing object set up according to the user inputs in the command line
    """
    config = tomocfg.PostProcConfig()
    config.output_dir = args.output_path

    if args.circular_mask:
        config.circular_mask = float(args.circular_mask)

    if args.cut_off:
        config.cut_off_level = float(args.cut_off)

    if args.out_median_filter:
        config.median_filter_size = float(args.out_median_filter)

    return config
Esempio n. 8
0
    def test_rotate_raises(self):
        import IMAT.tomorec.reconstruction_command as cmd
        cmd = cmd.ReconstructionCommand()

        import IMAT.tomorec.configs as cfgs
        pre_conf = cfgs.PreProcConfig()
        alg_conf = cfgs.ToolAlgorithmConfig()
        post_conf = cfgs.PostProcConfig()
        conf = cfgs.ReconstructionConfig(pre_conf, alg_conf, post_conf)

        pre_conf.rotation = 1
        # absolutely invalid data
        with self.assertRaises(ValueError):
            cmd.rotate_stack([], pre_conf)

        # wrong data type or dimensions (for samples / flats / darks
        with self.assertRaises(ValueError):
            cmd.rotate_stack(np.ones((3, 2)), pre_conf)

        with self.assertRaises(ValueError):
            cmd.rotate_stack(self.data_vol, pre_conf, [1])

        with self.assertRaises(ValueError):
            cmd.rotate_stack(self.data_vol, pre_conf, None, np.zeros((3, 3)))

        with self.assertRaises(ValueError):
            cmd.rotate_stack(self.data_vol, pre_conf, None, [0, 1])

        # invalid configurations
        with self.assertRaises(ValueError):
            cmd.rotate_stack(self.data_vol, None)

        with self.assertRaises(ValueError):
            cmd.rotate_stack(self.data_vol, [])

        with self.assertRaises(ValueError):
            cmd.rotate_stack(self.data_vol, conf)