psi_io

psi_io#

Routines for reading and writing PSI-style HDF5 and HDF4 data files.

This module provides a unified interface for interacting with PSI’s HDF data ecosystem. It handles both HDF4 (.hdf) and HDF5 (.h5) file formats, automatically dispatching to the appropriate backend based on the file extension.

Key interfaces#

Reading full datasets:

read_hdf_data(), rdhdf_1d(), rdhdf_2d(), rdhdf_3d()

Writing full datasets:

write_hdf_data(), wrhdf_1d(), wrhdf_2d(), wrhdf_3d()

Reading file metadata:

read_hdf_meta(), read_rtp_meta()

Reading dataset subsets:

get_scales_1d(), get_scales_2d(), get_scales_3d(), read_hdf_by_index(), read_hdf_by_value(), read_hdf_by_ivalue()

Interpolating data:

np_interpolate_slice_from_hdf(), sp_interpolate_slice_from_hdf(), interpolate_positions_from_hdf()

Converting between formats:

convert(), convert_psih4_to_psih5()

See Also#

psi_io.data :

Helpers for fetching example HDF data files.

Examples#

Read a 3D PSI-style HDF5 file:

>>> from psi_io import read_hdf_data
>>> from psi_io.data import get_3d_data
>>> filepath = get_3d_data()
>>> data, r, t, p = read_hdf_data(filepath)
>>> data.shape
(181, 100, 151)

Classes

HdfDataMeta(name, type, shape, attr, scales)

Named tuple for HDF dataset metadata

HdfScaleMeta(name, type, shape, imin, imax)

Named tuple storing metadata for a single HDF scale (coordinate) dimension.

Functions

convert(ifile[, ofile, strict])

Convert an HDF file between HDF4 (.hdf) and HDF5 (.h5) formats.

convert_psih4_to_psih5(ifile[, ofile])

Convert a PSI-convention HDF4 file to an HDF5 file.

get_scales_1d(filename)

Return the coordinate scale of a 1D PSI-style HDF5 or HDF4 dataset.

get_scales_2d(filename)

Return the coordinate scales of a 2D PSI-style HDF5 or HDF4 dataset.

get_scales_3d(filename)

Return the coordinate scales of a 3D PSI-style HDF5 or HDF4 dataset.

instantiate_linear_interpolator(*args, **kwargs)

Instantiate a linear interpolator using the provided data and scales.

interpolate_point_from_1d_slice(xi, scalex, ...)

Interpolate a point from a 1D slice using linear interpolation.

interpolate_point_from_2d_slice(xi, yi, ...)

Interpolate a point from a 2D slice using bilinear interpolation.

interpolate_positions_from_hdf(ifile, *xi, ...)

Interpolate at a list of scale positions using SciPy's RegularGridInterpolator.

np_interpolate_slice_from_hdf(ifile, /, *xi)

Interpolate a slice from HDF data using linear interpolation.

rdhdf_1d(hdf_filename)

Read a 1D PSI-style HDF5 or HDF4 file.

rdhdf_2d(hdf_filename)

Read a 2D PSI-style HDF5 or HDF4 file.

rdhdf_3d(hdf_filename)

Read a 3D PSI-style HDF5 or HDF4 file.

read_hdf_by_index(ifile, /, *xi[, ...])

Read data from an HDF4 (.hdf) or HDF5 (.h5) file by index.

read_hdf_by_ivalue(ifile, /, *xi[, ...])

Read data from an HDF4 (.hdf) or HDF5 (.h5) file by subindex value.

read_hdf_by_value(ifile, /, *xi[, ...])

Read data from an HDF4 (.hdf) or HDF5 (.h5) file by value.

read_hdf_data(ifile, /[, dataset_id, ...])

Read data from an HDF4 (.hdf) or HDF5 (.h5) file.

read_hdf_meta(ifile, /[, dataset_id])

Read metadata from an HDF4 (.hdf) or HDF5 (.h5) file.

read_rtp_meta(ifile, /)

Read the scale metadata for PSI's 3D cubes.

sp_interpolate_slice_from_hdf(*xi, **kwargs)

Interpolate a slice from HDF data using SciPy's RegularGridInterpolator.

wrhdf_1d(hdf_filename, x, f, **kwargs)

Write a 1D PSI-style HDF5 or HDF4 file.

wrhdf_2d(hdf_filename, x, y, f, **kwargs)

Write a 2D PSI-style HDF5 or HDF4 file.

wrhdf_3d(hdf_filename, x, y, z, f, **kwargs)

Write a 3D PSI-style HDF5 or HDF4 file.

write_hdf_data(ifile, /, data, *scales[, ...])

Write data to an HDF4 (.hdf) or HDF5 (.h5) file.

Attributes

HDFEXT

Set of possible HDF file extensions

HdfExtType

Type alias for possible HDF file extensions

PathLike

Type alias for file paths, accepting either pathlib.Path or str

PSI_DATA_ID

Mapping of PSI standard dataset names for HDF4 and HDF5 files

PSI_SCALE_ID

Mapping of PSI standard scale names for HDF4 and HDF5 files

SDC_TYPE_CONVERSIONS

Helper dictionary for mapping HDF4 types to numpy dtypes