Exemple #1
0
 def test_full_reconstruction(self):
     """Check that a basic reconstruction completes and produces output tiff files."""
     params = make_params()
     params.reconstruction_type = 'full'
     params.output_format = 'tiff_stack'
     response = rec(params=params)
     # import pdb; pdb.set_trace()
     self.assertTrue(self.full_tiff_dir.exists())
Exemple #2
0
 def test_recon_output_dir(self):
     """Check that ``--reconstruction-type=try`` respects output
     directory.
     
     """
     params = make_params()
     params.reconstruction_type = "try"
     params.center_search_width = 10
     params.output_folder = "{file_name_parent}/_rec"
     params.parameter_file = os.devnull
     response = rec(params=params)
     self.assertTrue(self.output_dir.exists())
Exemple #3
0
 def test_extra_args_no_file(self):
     """Check for behavior if the file is or isn't present in the
     extra_args yaml file.
     
     """
     params = make_params()
     params.reconstruction_type = "try"
     params.center_search_width = 10
     params.output_folder = "{file_name_parent}/_rec"
     params.parameter_file = "/tmp/gweoiuwerw"
     response = rec(params=params)
     self.assertTrue(self.output_dir.exists())
Exemple #4
0
 def test_hdf_output(self):
     params = make_params()
     params.reconstruction_type = 'full'
     params.output_format = "hdf5"
     response = rec(params=params)
     expected_hdf5path = self.output_hdf
     # Check that tiffs are not saved and HDF5 file is saved
     self.assertFalse(os.path.exists(self.full_tiff_dir))
     self.assertTrue(os.path.exists(expected_hdf5path))
     with h5py.File(expected_hdf5path, mode='r') as h5fp:
         vol = h5fp['volume']
         self.assertEqual(vol.shape, (64, 64, 64))
         self.assertFalse(np.any(np.isnan(vol)))
Exemple #5
0
 def test_hdf_output_chunks(self):
     # Test with multiple chunks to ensure they're all written
     params = make_params()
     params.reconstruction_type = 'full'
     params.output_format = 'hdf5'
     params.nsino_per_chunk = 16  # 4 chunks
     response = rec(params=params)
     expected_hdf5path = self.output_hdf
     # Check that tiffs are not saved and HDF5 file is saved
     self.assertFalse(os.path.exists(self.full_tiff_dir))
     self.assertTrue(os.path.exists(expected_hdf5path))
     with h5py.File(expected_hdf5path, mode='r') as h5fp:
         vol = h5fp['volume']
         self.assertEqual(vol.shape, (64, 64, 64))
         self.assertFalse(np.any(np.isnan(vol)))
Exemple #6
0
def run_rec(args):

    log.warning('reconstruction start')
    file_path = Path(args.file_name)
    if str(args.file_format) in KNOWN_FORMATS:
        if file_path.suffix == '.yaml':
            # Load the list of files from a given YAML parameters file
            log.info("Reconstructing files listed in: %s" % file_path)
            file_list = file_io.yaml_file_list(file_path)
            failed_files = []
            for idx, this_fname in enumerate(file_list):
                args.file_name = file_path.parent / this_fname
                log.info("Reconstructing next file (%d/%d): %s",
                         idx, len(file_list), args.file_name)
                try:
                    recon.rec(args)
                except Exception as err:
                    # This file failed, but we can keep going and try the rest of the files
                    failed_files.append(this_fname)
                    # Log the exception and stacktrace
                    log.error("  *** reconstruction failed: %s", repr(err))
                    log_exception(log, err, fmt="      %s")
                else:
                    config.update_config(args)
            # Report list of failed files so it's not buried in the log
            if len(failed_files) > 0:
                log.error("Some tomograms could not be reconstructed: %s",
                          ", ".join([str(f) for f in failed_files]))
        elif file_path.is_file():
            log.info("reconstructing a single file: %s" % args.file_name)
            recon.rec(args)
            config.update_config(args)
        elif file_path.is_dir():
            # Add a trailing slash if missing
            top = os.path.join(args.file_name, '')
            h5_file_list = list(filter(lambda x: x.endswith(('.h5', '.hdf', 'hdf5')), os.listdir(top)))
            if (h5_file_list):
                h5_file_list.sort()
                log.info("found: %s" % h5_file_list) 
                index=0
                for fname in h5_file_list:
                    args.file_name = top + fname
                    log.warning("  *** file %d/%d;  %s" % (index, len(h5_file_list), fname))
                    index += 1
                    recon.rec(args)
                    config.update_config(args)
                log.warning('reconstruction end')
            else:
                log.error("directory %s does not contain any file" % args.file_name)
        else:
            log.error("directory or File Name does not exist: %s" % args.file_name)
    else:
        # add here support for other file formats
        log.error("  *** %s is not a supported file format" % args.file_format)
        log.error("supported data formats are: %s, %s, %s, %s" % tuple(KNOWN_FORMATS))
Exemple #7
0
 def test_extra_args_no_rotation_axis(self):
     """Check for behavior if the file is or isn't present in the
     extra_args yaml file.
     
     """
     params = make_params()
     params.reconstruction_type = "try"
     params.center_search_width = 10
     params.output_folder = "{file_name_parent}/_rec"
     params.parameter_file = self.yaml_file
     # Create the YAML file
     opts = {
         "test_tomogram.h5": {
             "spam": "foo",
         }
     }
     with open(self.yaml_file, mode='w') as fp:
         fp.write(yaml.dump(opts))
     response = rec(params=params)
     self.assertTrue(self.output_dir.exists())
Exemple #8
0
 def test_slice_reconstruction(self):
     """Check that a basic reconstruction completes and produces output tiff files."""
     params = make_params()
     params.reconstruction_type = 'slice'
     response = rec(params=params)
     self.assertTrue(self.output_dir.exists())
Exemple #9
0
 def test_yaml_params(self):
     params = make_params()
     params.parameter_file = self.yaml_file
     response = rec(params=params)