2.23.2.2. pycsamt.format.io#
Reading and writing .pcsf (HDF5) files.
The implementation lives in the standalone pcsf package
(pcsf.core.hdf5), the reference implementation of the format.
This module re-exports it under its pyCSAMT name, so that existing
imports keep working and pyCSAMT objects are the pcsf objects
themselves.
See also
pcsf.core.hdf5Implementation.
- pycsamt.format.io.read_pcsf(path)
Read a
PCSFModelback from a.pcsf(HDF5) file.- Parameters:
path (path-like) – Source file.
- Returns:
Fully reconstructed and re-validated model.
- Return type:
- Raises:
FormatError – If
pcsf_versionor the geometry group is missing, or the geometry kind is unknown.VersionError – If
pcsf_versionis malformed or of another major version (specification, section 5).GeometryError, EncodingError – If the reconstructed model fails
PCSFModel.validate().
- Warns:
UserWarning – If the file’s minor version is newer than this reader’s; fields added since then are ignored.
See also
write_pcsfInverse operation.
pcsf.readRead either encoding.
pcsf.api.registry.register_formatCompanion-format decoders.
Notes
The optional
boreholesgroup is returned as the dictionary it stores, unless a companion format registered under the group’skindattribute ("pcbh") provides afrom_dictcallable, in which casemodel.boreholesis its result.Examples
See
write_pcsf().
- pycsamt.format.io.write_pcsf(model, path)
Write a
PCSFModelto a.pcsf(HDF5) file.- Parameters:
model (PCSFModel) – The model to serialize. Validated before anything is written.
path (path-like) – Destination file. Parent directories are created if missing.
- Returns:
The path written to.
- Return type:
- Raises:
TypeError – If model is not a
PCSFModel.GeometryError, EncodingError – If model fails
PCSFModel.validate().
See also
read_pcsfInverse operation.
pcsf.core.text.write_pcsmText encoding.
Examples
>>> import os, tempfile >>> from pcsf import Grid2DGeometry, PCSFModel >>> from pcsf.core.hdf5 import read_pcsf, write_pcsf >>> model = PCSFModel( ... geometry=Grid2DGeometry(x=[0.0, 100.0], z=[10.0, 50.0]), ... resistivity=[[100.0, 120.0], [50.0, 60.0]], ... source_backend="occam2d", ... ) >>> with tempfile.TemporaryDirectory() as tmp: ... path = write_pcsf(model, os.path.join(tmp, "m.pcsf")) ... back = read_pcsf(path) >>> bool((back.resistivity == model.resistivity).all()) True