Example #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))
Example #2
0
def main_tomo_rec():
    # several dependencies (numpy, scipy) are too out-of-date in standard Python 2.6
    # distributions, as found for example on rhel6
    vers = sys.version_info
    if vers < (2, 7, 0):
        raise RuntimeError(
            "Not running this test as it requires Python >= 2.7. Version found: {0}"
            .format(vers))

    import inspect

    import IMAT.tomorec.io as tomoio

    arg_parser = setup_cmd_options()
    args = arg_parser.parse_args()

    # Save myself early. Save command this command line script and all packages/subpackages
    tomoio.self_save_zipped_scripts(
        args.output_path, os.path.abspath(inspect.getsourcefile(lambda: 0)))

    # Grab and check pre-processing options + algorithm setup + post-processing options
    preproc_config = grab_preproc_options(args)
    alg_config = grab_tool_alg_options(args)
    postproc_config = grab_postproc_options(args)

    cmd_line = " ".join(sys.argv)
    cfg = tomocfg.ReconstructionConfig(preproc_config, alg_config,
                                       postproc_config)
    # Does all the real work
    cmd = tomocmd.ReconstructionCommand()
    cmd.do_recon(cfg, cmd_line=cmd_line)
Example #3
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)
Example #4
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
Example #5
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)
Example #6
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)