save

emg3d.io.save(fname, **kwargs)[source]

Save surveys, meshes, models, fields, and more to disk.

Serialize and save data to disk in different formats (see parameter description of fname for the supported file formats). The main emg3d-classes (type emg3d.io.KNOWN_CLASSES to get a list) can be collected in corresponding root-folders by setting collect_classes=True.

Any other (non-emg3d) object can be added too, as long as it knows how to serialize itself.

The serialized instances will be de-serialized if loaded with load().

Parameters:
fname : str

File name inclusive ending, which defines the used data format. Implemented are currently:

  • .h5: Uses h5py to store inputs to a hierarchical, compressed binary hdf5 file. Recommended file format, but requires the module h5py.
  • .npz: Uses numpy to store inputs to a flat, compressed binary file.
  • .json: Uses json to store inputs to a hierarchical, plain text file.
compression : int or str, optional

Passed through to h5py, default is ‘gzip’.

json_indent : int or None

Passed through to json, default is 2.

collect_classes : bool

If True, input data is collected in folders for the principal emg3d-classes (type emg3d.io.KNOWN_CLASSES to get a list) and everything else collected in a Data-folder. Defaults to False.

verb : int

If 1 (default) verbose, if 0 silent.

kwargs : Keyword arguments, optional

Data to save using its key as name. The following instances will be properly serialized: emg3d.meshes.TensorMesh, emg3d.fields.Field, and emg3d.models.Model and serialized again if loaded with load(). These instances are collected in their own group if h5py is used.

Note that the provided data cannot contain the before described parameters as keys.