Exemple #1
0
def main(args):
    """Iterate over the folders:
        - check that the folder is valid
        - check if the file exists (overwrite if the
            --overwrite option was specified)
        - analyse the header to save the parameters in the attributes of the
          hdf5 dataset
        - write the data as an hdf5 dataset
        - remove the folder (unless --keep is true)

    """
    output_names = []
    for folder_name in args.folder:
        if not os.path.isdir(folder_name):
            print("make_hdf5.py: not a folder:", folder_name)
            continue
        print("make_hdf5.py: converting", folder_name)
        files = glob(os.path.join(folder_name, "*.raw"))
        output_name = os.path.normpath(folder_name) + ".hdf5"
        output_names.append(output_name)
        if not os.path.exists(output_name) or args.overwrite:
            output_file = h5py.File(output_name, 'w')
        else:
            print()
            print("""make_hdf5.py: file {0} exists.
                    Run with the --overwrite (-o) flag
                    if you want to overwrite it.""".format(output_name))
            print(progress_bar(1))
            print()
            continue
        group = output_file.create_group("raw_images")
        n_files = len(files)
        for i, input_file_name in enumerate(files):
            print(progress_bar((i + 1) / n_files), end="\r")
            (_, exposure_time, min_x, max_x, min_y,
             max_y) = analyse_header(input_file_name)
            image_name = os.path.splitext(os.path.basename(input_file_name))[0]
            image = read_data(input_file_name)
            dataset = group.create_dataset(image_name, data=image)
            dataset.attrs['exposure_time'] = exposure_time
            dataset.attrs['min_x'] = min_x
            dataset.attrs['min_y'] = min_y
            dataset.attrs['max_x'] = max_x
            dataset.attrs['max_y'] = max_y
        if not args.keep:
            print("make_hdf5.py: removing", folder_name)
            shutil.rmtree(folder_name)
        output_file.close()
        print()
        print("make_hdf5.py: written", output_name)
    print("make_hdf5.py: done!")
    return output_names
Exemple #2
0
    def dont_start(self):
        """Hook for doing some operation when no calculation has to be
        performed.

        """
        print("base_analyser: result already saved in file.")
        print(progress_bar(1))
    def calculate_images(self):
        """Calculate the three signals from the phase stepping curves and
        the flat parameters with the get_signals utility function.

        """
        if not self.exists_in_file:
            images = get_signals(self.images, self.flat_parameters,
                                 self.n_periods)
            (self.absorption_image, self.differential_phase_image,
             self.dark_field_image) = images
        else:
            print("dpc_radiography: result already saved in file.")
            print(progress_bar(1))
Exemple #4
0
 def analyse_histogram(self, i, hist):
     """base version just prints the progress bar advancement for
     the index i"""
     print(progress_bar((i + 1) / self.n_images), end='')
Exemple #5
0
 def dont_start(self):
     print("projection_stack: result already saved in file.")
     print(progress_bar(1))