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 save_preproc_images(self, output_dir, preproc_data, preproc_cfg, out_dtype='uint16'): """ Save (pre-processed) images from a data array to image files. @param output_dir :: where results are being saved, including the pre-proc images/slices @param preproc_data :: data volume with pre-processed images @param preproc_cfg :: pre-processing configuration set up for a reconstruction @param out_dtype :: dtype used for the pixel type/depth in the output image files """ print " * Pre-processed images (preproc_data) dtype:", preproc_data.dtype min_pix = np.amin(preproc_data) max_pix = np.amax(preproc_data) print " with min_pix: {0}, max_pix: {1}".format(min_pix, max_pix) if preproc_cfg.save_preproc_imgs: preproc_dir = os.path.join(output_dir, self._PREPROC_IMGS_SUBDIR_NAME) print "* Saving pre-processed images into: {0}".format(preproc_dir) tomoio.make_dirs_if_needed(preproc_dir) for idx in range(0, preproc_data.shape[0]): # rescale_intensity has issues with float64=>int16 tomoio.write_image(preproc_data[idx, :, :], min_pix, max_pix, os.path.join(preproc_dir, 'out_preproc_proj_image' + str(idx).zfill(6)), img_format=preproc_cfg.out_img_format, dtype=out_dtype) else: print "* NOTE: not saving pre-processed images..."