tomopy_cli.file_io

Functions:

read_tomo(sino, proj, params[, ignore_flip])

Read in the tomography data.

blocked_view(proj, theta, params)

binning(proj, flat, dark, params)

Bin the tomography data.

flip_and_stitch(params, img360, flat360, ...)

Stitch together data for flip-and-stitch (0-360 degree offset center) scan.

patch_projection(data, miss_angles)

get_dx_dims(params)

Read array size of a specific group of Data Exchange file.

file_base_name(fname)

path_base_name(path)

auto_read_dxchange(params)

read_rot_center(params)

Read the rotation center from /process group in the HDF file.

read_filter_materials(params)

Read the beam filter configuration.

read_filter_materials_tomoscan(params)

Read the beam filter configuration from the HDF file.

read_pixel_size(params)

Read the pixel size and magnification from the HDF file.

read_scintillator(params)

Read the scintillator type and thickness from the HDF file.

read_bright_ratio(params)

Read the ratio between the bright exposure and other exposures.

check_item_exists_hdf(hdf_filename, item_name)

Checks if an item exists in an HDF file.

convert(params)

write_hdf5(data, fname[, dname, dtype, ...])

Write data to hdf5 file in a specific dataset.

yaml_file_list(file_path)

Open a YAML file and return the list of files within.

tomopy_cli.file_io.auto_read_dxchange(params)[source]
tomopy_cli.file_io.binning(proj, flat, dark, params)[source]

Bin the tomography data.

Parameters
  • proj (projection data, 3D Numpy array)

  • flat (projection flatfield data, 2D Numpy array)

  • dark (projection dark field data, 2D Numpy array)

  • params (parameters for reconstruction)

Returns

  • ndarray – 3D binned projection data.

  • ndarray – 2D binned flat field data.

  • ndarray – 2D binned dark field data.

tomopy_cli.file_io.blocked_view(proj, theta, params)[source]
tomopy_cli.file_io.check_item_exists_hdf(hdf_filename, item_name)[source]

Checks if an item exists in an HDF file. Inputs hdf_filename: str filename or pathlib.Path object for HDF file to check item_name: name of item whose existence needs to be checked path: str path to check. Default to None

tomopy_cli.file_io.convert(params)[source]
tomopy_cli.file_io.file_base_name(fname)[source]
tomopy_cli.file_io.flip_and_stitch(params, img360, flat360, dark360, theta360)[source]

Stitch together data for flip-and-stitch (0-360 degree offset center) scan.

Parameters
  • params (dict of reconstruction parameters)

  • img360 (projection data from 0-360 degrees, 3D Numpy array)

  • flat360 (flatfield data, 2D Numpy array)

  • dark360 (dark field data, 2D Numpy array)

  • params (parameters for reconstruction)

Returns

  • ndarray – 3D binned projection data stitched together, 0-180 degree domain

  • ndarray – 2D binned flat field data stitched together, 0-180 degree domain

  • ndarray – 2D binned dark field data stitched together, 0-180 degree domain

  • ndarray – 1D array of valid theta values, 0-180 degree domain

tomopy_cli.file_io.get_dx_dims(params)[source]

Read array size of a specific group of Data Exchange file.

Parameters
  • fname (str) – String defining the path of file or file name.

  • dataset (str) – Path to the dataset inside hdf5 file where data is located.

Returns

ndarray – Data set size.

tomopy_cli.file_io.patch_projection(data, miss_angles)[source]
tomopy_cli.file_io.path_base_name(path)[source]
tomopy_cli.file_io.read_bright_ratio(params)[source]

Read the ratio between the bright exposure and other exposures.

tomopy_cli.file_io.read_filter_materials(params)[source]

Read the beam filter configuration. This discriminates between files created with tomoScan and the previous meta data format.

tomopy_cli.file_io.read_filter_materials_tomoscan(params)[source]

Read the beam filter configuration from the HDF file.

If params.filter_{n}_auto for n in [1,2,3] is True, then try to read the filter configuration recorded during acquisition in the HDF5 file.

Parameters

params – The global parameter object, should have filter_n_material, filter_n_thickness, and filter_n_auto for n in [1,2,3]

Returns

params – An equivalent object to the params input, optionally with filter_n_material and filter_n_thickness attributes modified to reflect the HDF5 file.

tomopy_cli.file_io.read_pixel_size(params)[source]

Read the pixel size and magnification from the HDF file. Use to compute the effective pixel size.

tomopy_cli.file_io.read_rot_center(params)[source]

Read the rotation center from /process group in the HDF file. Return: rotation center from this dataset or None if it doesn’t exist.

tomopy_cli.file_io.read_scintillator(params)[source]

Read the scintillator type and thickness from the HDF file.

tomopy_cli.file_io.read_tomo(sino, proj, params, ignore_flip=False)[source]

Read in the tomography data.

Parameters
  • sino (tuple of (start_row, end_row) rows to be read in)

  • proj (tuple of (start_proj, end_proj) projections to be read in)

  • params (parameters for reconstruction)

Returns

  • ndarray – 3D tomographic data.

  • ndarray – 3D flat field data.

  • ndarray – 3D dark field data.

  • ndarray – 1D theta in radian.

  • float – location of the rotation axis

tomopy_cli.file_io.write_hdf5(data, fname, dname='volume', dtype=None, dest_idx=None, maxsize=None, overwrite=False)[source]

Write data to hdf5 file in a specific dataset.

This function supports partial writing of data through af combination of maxsize and dest_idx options. For example, to write slices 10 to 16 of a (32, 32, 32) volume:

assert data.shape == (32, 32, 32)
file_io.write_hdf5(data[10:16], maxsize=data.shape, dest_idx=slice(10,16), ...)
Parameters
  • data (ndarray) – Array data to be saved.

  • fname (str) – File name to which the data is saved. .h5 extension will be appended if it does not already have one.

  • dname (str, optional) – Name for dataset where data will be written.

  • dtype (data-type, optional) – By default, the data-type is inferred from the input data.

  • dest_idx (optional) – A valid index for the dataset such that dataset[target_idx] = data will properly write the data to the dataset.

  • maxsize (int, optional) – Maximum size that the dataset can be resized to along the given axis.

tomopy_cli.file_io.yaml_file_list(file_path: Path) List[Path][source]

Open a YAML file and return the list of files within. This function does not parse the parameters contained inside, merely returns a list of the files that are referenced. For updating parameters on a per-file basis, use config.yaml_args(). :Parameters: file_path – A pathlib Path object pointing to the file to open.

Returns

file_list – The list of file names found. There is no guarantee that these files are suitable for reconsturction, or even exist at all.