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 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))
def test_config_alg(self): """ Basic consistency check of the tool/algorithm config and some default values """ import IMAT.tomorec.configs as cfgs alg = cfgs.ToolAlgorithmConfig() self.assertEquals(alg.tool, alg.DEF_TOOL) self.assertEquals(alg.algorithm, alg.DEF_ALGORITHM) self.assertEquals(alg.num_iter, None) self.assertEquals(alg.regularization, None)
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
def grab_tool_alg_options(args): """ Get tool and algorithm options from the command line (through an argument parser) @param parser :: arguments parsed already, set up with algorithm/tool options Returns:: an algorithm config object set up according to the user inputs in the command line """ config = tomocfg.ToolAlgorithmConfig() config.tool = args.tool config.algorithm = args.algorithm if args.num_iter: if isinstance(args.num_iter, str) and not args.num_iter.isdigit(): raise RuntimeError("The number of iterations must be an integer") config.num_iter = int(args.num_iter) return config
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)
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)