qtcad.device.io module
Functions to save and load simulation results.
- load(path, var_name=None, fmt=None, asarray=False)
Loads a .json or .hdf5 file.
- Parameters:
path (str or pathlib.Path object) – The path to the data file.
fmt (string, optional) – Format of the data file. “json”, “hdf5” or None. If None, guesses from extension. Default: None.
var_name (string, optional) – Name of the variable to load. In hdf5, default name that will be used is “var”.
asarray (bool, optional) – Force to load Fields as numpy arrays. Default: False.
- Returns:
dict – The contents of the file.
Note
For json files, the data is stored in a dictionary by default, unless a specific variable name is specified, in which case this variable is loaded. For hdf5 files, specifying the variable name is mandatory.
- save(path, out_dict, mesh=None, fmt=None, compression_opts=4, var_name='data', length_unit='nm', verbose=True, subsample=None)
Saves a dictionary of arrays or a single array into a .json, .hdf5, .vtu or .vtm file.
- Parameters:
path (str or pathlib.Path object) – The path to the data file.
out_dict (dict) – A dictionary of numpy arrays or fields to save.
fmt (string) – Format of the data file. “json”, “hdf5”, “vtu”, “vtm” or None. If None, guesses from extension. Default: None.
compression_opts (int, optional) – Compression level to use in hdf5 file, from 0 to 9. Default: 4.
mesh (Mesh, optional) – The mesh to use when saving under “vtu” or “vtm” format.
var_name (str, optional) – The variable name to use when exporting a variable in “vtu” or “vtm” format.
length_unit (str) – Units of length to use when exporting into “vtu” format. Default: “nm”. Other choices are: “um”, “mm”, and “m”.
verbose (bool, optional) – Whether messages regarding the file path and size are printed. Default: True.
subsample (tuple or str or None, optional) – Controls mesh subsampling. If a tuple of two floats is provided, it specifies the minimum and maximum characteristic lengths for subsampling. If set to ‘auto’, default subsampling parameters are used. If None, no subsampling is applied. Defaults to None.
- save_device(path, device, attrs=None, fmt=None, compression_opts=4)
Saves a device into an hdf5 or json file.
- Parameters:
path (string or pathlib.Path object) – The path to the file in which to save the device.
device (device) – The device to save.
attrs (list of str or None) – Attributes to save in the .json file. If None, save all of them.
fmt (string) – Format of the data file. “json”, “hdf5” or None. If None, guesses from extension. Default: None.
compression_opts (int, optional) – Compression level to use in hdf5 file, from 0 to 9. Default: 4.