This module offers a set of functions to dump a python dictionary indexed by text strings to following file formats: HDF5, INI, JSON
Write a nested dictionary to a HDF5 file, using keys as member names.
If a dictionary value is a sub-dictionary, a group is created. If it is any other data type, it is cast into a numpy array and written as a h5py dataset. Dictionary keys must be strings and cannot contain the / character.
Note
This function requires h5py to be installed.
Parameters: |
|
---|
Example:
from silx.io.dictdump import dicttoh5
city_area = {
"Europe": {
"France": {
"Isère": {
"Grenoble": "18.44 km2"
},
"Nord": {
"Tourcoing": "15.19 km2"
},
},
},
}
create_ds_args = {'compression': "gzip",
'shuffle': True,
'fletcher32': True}
dicttoh5(city_area, "cities.h5", h5path="/area",
create_dataset_args=create_ds_args)
Read HDF5 file and return a nested dictionary with the complete file structure and all data.
Note
This function requires h5py to be installed.
Note
If you write a dictionary to a HDF5 file with dicttoh5() and then read it back with h5todict(), data types are not preserved. All values are cast to numpy arrays before being written to file, and they are read back as numpy arrays (or scalars). In some cases, you may find that a list of heterogeneous data types is converted to a numpy array of strings.
Parameters: | h5file – File name or h5py.File object |
---|---|
Returns: | dict |
Serialize ddict as a JSON formatted stream to jsonfile.
Parameters: |
|
---|
Output dict as configuration file (similar to Microsoft Windows INI).
Parameters: |
|
---|
Dump dictionary to a file
Parameters: |
|
---|---|
Raises IOError: | if file format is not supported |
Load dictionary from a file
When loading from a JSON or INI file, an OrderedDict is returned to preserve the values’ insertion order.
Parameters: |
|
---|---|
Returns: | Dictionary (ordered dictionary for JSON and INI) |
Raises IOError: | if file format is not supported |