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.hdf5

Implementation.

pycsamt.format.io.read_pcsf(path)

Read a PCSFModel back from a .pcsf (HDF5) file.

Parameters:

path (path-like) – Source file.

Returns:

Fully reconstructed and re-validated model.

Return type:

PCSFModel

Raises:
  • FormatError – If pcsf_version or the geometry group is missing, or the geometry kind is unknown.

  • VersionError – If pcsf_version is 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_pcsf

Inverse operation.

pcsf.read

Read either encoding.

pcsf.api.registry.register_format

Companion-format decoders.

Notes

The optional boreholes group is returned as the dictionary it stores, unless a companion format registered under the group’s kind attribute ("pcbh") provides a from_dict callable, in which case model.boreholes is its result.

Examples

See write_pcsf().

pycsamt.format.io.write_pcsf(model, path)

Write a PCSFModel to 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:

pathlib.Path

Raises:
  • TypeError – If model is not a PCSFModel.

  • GeometryError, EncodingError – If model fails PCSFModel.validate().

See also

read_pcsf

Inverse operation.

pcsf.core.text.write_pcsm

Text 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