wrhdf_2d

Contents

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_filenamestr

The path to the 2D HDF5 (.h5) or HDF4 (.hdf) file to write.

xnp.ndarray

1D array of scales in the X dimension.

ynp.ndarray

1D array of scales in the Y dimension.

fnp.ndarray

2D array of data, C-ordered as shape(ny,nx) for Python (see note 1).

**kwargs

Additional keyword arguments passed through to the underlying write_hdf_data() routine, specifically:

  • dataset_idstr | None

    The identifier of the dataset to write. If None, a default dataset is used (‘Data-Set-2’ for HDF4 and ‘Data’ for HDF5).

  • sync_dtype: bool

    If 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.

Raises:
ValueError

If the file does not have a .hdf or .h5 extension.

KeyError

If, for HDF4 files, the provided data is of a type not supported by pyhdf. viz. float16 or int64.

See also

write_hdf_data

Generic HDF data writing routine.

Notes

This routine is provided for backwards compatibility with existing PSI codes that expect this API signature. While the underlying implementation has been refactored to dispatch to the newer write_hdf_data() routine – along with a dimensionality check – the API signature and behavior has been largely preserved.

Warning

It is worth reiterating that this routine – when called with its default arguments – will write to the default PSI dataset IDs for HDF4/HDF5 files and synchronize datatypes between the dataset and scales. This behavior is crucial for interacting with certain Fortran-based tools developed by PSI.