twpasolver.file_utils module#
Functions for saving to json and hdf5 files.
This module provides functions to read from and write to JSON and HDF5 files. It includes utility functions to ensure file extensions and directories are correctly handled, as well as recursive functions to handle nested dictionaries when working with HDF5 files.
- twpasolver.file_utils.read_file(savename: str, writer: str = 'json') Dict[str, Any][source]#
Read data from a file and return it as a dictionary.
- twpasolver.file_utils.save_to_file(savename: str, d: Dict[str, Any], writer: str = 'json') None[source]#
Save data to a file in the specified format.
- twpasolver.file_utils.add_extension(filename: str, extension: str) str[source]#
Add the specified extension to the filename if not already present.
- twpasolver.file_utils.ensure_directory_exists(filename: str) None[source]#
Ensure that the directory for the given filename exists; create it if necessary.
- Parameters:
filename (str) – The name of the file.
- twpasolver.file_utils.read_hdf5(savename: str) Dict[str, Any][source]#
Read data from an HDF5 file and return it as a dictionary.
- twpasolver.file_utils.read_json(savename: str) Dict[str, Any][source]#
Read data from a JSON file and return it as a dictionary.
- twpasolver.file_utils.save_to_hdf5(savename: str, d: Dict[str, Any]) None[source]#
Save data to an HDF5 file.
- twpasolver.file_utils.save_to_json(savename: str, d: Dict[str, Any]) None[source]#
Save data to a JSON file.