ptyrad.io.handlers

ptyrad.io.handlers#

High-level file handlers (load/save) for generic and hierarchical file formats

Functions

load_array_from_file(path[, key, ndims, ...])

Load array from a file.

save_array(data[, file_dir, file_name, ...])

Save an ND array to the specified file format.

ptyrad.io.handlers.load_array_from_file(path, key=None, ndims=None, shape=None, offset=None, gap=None, selection=None, zarr_kwargs=None)[source]#

Load array from a file. The file type is inferred from the extension. Currently supports .tif, .tiff, .npy, .mat, .h5, .hdf5, .zarr, and .raw.

Parameters:
  • path (str) – Path to the file.

  • key (str) – Key to specify the dataset (optional).

  • ndims (list) – List of desired dimensions for filtering datasets.

  • shape (tuple) – Shape of the data for .raw files (optional).

  • offset (int) – Offset for .raw files (optional).

  • gap (int) – Gap for .raw files (optional).

  • selection – Optional load-time slicing/indexing for .h5, .hdf5, .mat v7.3, and .zarr files.

  • zarr_kwargs (dict) – Optional Zarr-specific settings passed to zarr.open.

Returns:

The loaded array.

Return type:

numpy.ndarray

Raises:

ValueError – If the file type is unsupported or no valid dataset is found.

ptyrad.io.handlers.save_array(data, file_dir='', file_name='ptyrad_init_meas', file_format='hdf5', output_shape=None, append_shape=True, **kwargs)[source]#

Save an ND array to the specified file format.

Parameters:
  • data (numpy.ndarray) – ND array to save.

  • file_dir (str) – Directory to save the file.

  • file_name (str) – Base name of the file (without extension).

  • file_format (str) – File format to save as (“tif”, “npy”, “hdf5”, “mat”).

  • output_shape (tuple, optional) – Desired shape for the output array.

  • append_shape (bool) – Whether to append the array shape to the filename.

  • **kwargs – Additional arguments for specific file formats.