wrhdf_2d#
- wrhdf_2d(hdf_filename, x, y, f, **kwargs)[source]#
Write a 2D PSI-style HDF5 or HDF4 file.
The data in the HDF file will appear as X,Y in Fortran order.
Each dimension requires a 1D “scale” associated with it that describes the rectilinear grid coordinates in each dimension.
- Parameters:
- hdf_filename
PathLike The path to the 2D HDF5 (.h5) or HDF4 (.hdf) file to write.
- x
np.ndarray 1D array of scales in the X dimension.
- y
np.ndarray 1D array of scales in the Y dimension.
- f
np.ndarray 2D data array, C-ordered with shape
(ny, nx)in Python.- **kwargs
Additional keyword arguments passed through to the underlying
write_hdf_data()routine, specifically:dataset_idstr | NoneThe identifier of the dataset to write. If None, a default dataset is used (
'Data-Set-2'for HDF4 and'Data'for HDF5).
sync_dtype: boolIf True, the data type of the scales will be matched to that of the data array.
Omitting these will yield the same behavior as the legacy routines, i.e. writing to the default PSI dataset IDs for HDF4/HDF5 files and synchronizing datatypes between the dataset and scales.
- hdf_filename
- Raises:
ValueErrorIf the file does not have a
.hdfor.h5extension.KeyErrorIf, for HDF4 files, the data or scale dtype is not supported by
pyhdf. Seewrite_hdf_data()for the full dtype support table.
See also
write_hdf_dataGeneric HDF data writing routine.
Notes
This routine is provided for backward compatibility with existing PSI codes that expect this API signature. The underlying implementation dispatches to
write_hdf_data(), but the argument order and default behavior (sync dtype, default dataset IDs) are preserved.Warning
When called with its default arguments this routine writes to the default PSI dataset IDs for HDF4/HDF5 files and synchronizes dtypes between the dataset and scales. This behavior is required for interoperability with certain Fortran-based PSI tools.
Examples
>>> import tempfile, numpy as np >>> from pathlib import Path >>> from psi_io import wrhdf_2d, rdhdf_2d >>> x = np.linspace(0.0, 2*np.pi, 64, dtype=np.float32) >>> y = np.linspace(0.0, np.pi, 32, dtype=np.float32) >>> f = np.outer(np.sin(x), np.cos(y)).astype(np.float32) >>> with tempfile.TemporaryDirectory() as d: ... wrhdf_2d(Path(d) / "out.h5", x, y, f) ... x2, y2, f2 = rdhdf_2d(Path(d) / "out.h5") ... np.array_equal(f, f2) True