hdf#
Methods for dealing with HDF files.
Parts of the code in the module are based on: https://codereview.stackexchange.com/a/121308
- hsr4hci.hdf.create_hdf_dir(experiment_dir, create_on_work=False)[source]#
Create a directory in which the HDF results files for an HSR experiment can be stores and return the Path to the directory.
Attention
Unless you are working on the MPI-IS cluster in TΓΌbingen, you always want to use
create_on_work=False!Background
This is slightly complicated, because the exact location depends on the machine on which this code is running. When running locally, it should simply be created directly in the respective
experiment_dir. However, when this code is running on the MPI-IS cluster, we want to store the (large) HDF files on/work, with a symlink connecting it to the rest of the experiment_dir.- Parameters:
experiment_dir (Path) β The Path to the experiment directory for which we are going to create a hdf results directory.
create_on_work (bool) β If True, the HDF directory is created on
/workand a symlink is created inexperiment_dir. If False, the HDF directory is created directly inexperiment_dir.
- Returns:
The Path to the
hdfdirectory for theexperiment_dir.- Return type:
- hsr4hci.hdf.load_dict_from_hdf(file_path)[source]#
Load the contents of an HDF file into a dictionary to replicate the internal structure (group, subgroups, β¦) of the HDF file.
- hsr4hci.hdf.recursively_load_dict_contents_from_group(hdf_object, path='')[source]#
Auxiliary function for recursively looping over the contents of a given
hdf_objectand loading them into a dictionary.
- hsr4hci.hdf.recursively_save_dict_contents_to_group(hdf_object, prefix, dictionary)[source]#
Auxiliary function for recursively looping over the contents of a dictionary and saving them to an HDF file.
- Parameters:
- Return type:
None
- hsr4hci.hdf.save_data_to_hdf(hdf_file, location, name, data, overwrite=True)[source]#
Auxiliary function to write data to an open HDF file that provides automatic overwriting (which requires deleting and re-creating data sets that already exist).
- Parameters:
hdf_file (File) β An open HDF file (in write mode).
location (str) β The path (βgroup_1/group_2/β¦/group_nβ) at which to create the new data set in the HDF file. Can be empty.
name (str) β The name of the data set.
data (Any) β The data to be written to the data set.
overwrite (bool) β Whether to overwrite a data set of the same name that already exists in the given location.
- Return type:
None
- hsr4hci.hdf.save_dict_to_hdf(dictionary, file_path, mode='a', prefix='')[source]#
Save the given
dictionaryas an HDF file at thefile_path. If thedictionaryis nested, the HDF file will replicate this structure using groups.- Parameters:
dictionary (dict) β A (possibly nested) dictionary to be saved.
file_path (Union[Path, str]) β The path to the target file (including name and file ending).
mode (str) β The mode (i.e., βwβ or βaβ) that is used when opening the HDF file for writing.
prefix (str) β Prefix to use when writing to the HDF file. This can be used, for example, to write the dictionary into its own group inside the HDF file.
- Return type:
None