pycsamt.format.io#

HDF5 reader/writer for the pyCSAMT Common Subsurface Format (PCSF).

This module is intentionally serialization-only, mirroring pycsamt.io.formats’s philosophy: it knows how to turn a PCSFModel into a .pcsf file and back, but carries no backend-specific (Occam2D/ModEM/MARE2DEM/DUHI) conversion logic — that lives in pycsamt.format.adapters (Phases 2-4 of PYCSAMT-PCSF-INVERSION-FORMAT-PLAN.md).

Functions

read_pcsf(path)

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

write_pcsf(model, path)

Write a PCSFModel to a .pcsf (HDF5) file.

pycsamt.format.io.write_pcsf(model, path)[source]

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:

ValueError – If model fails PCSFModel.validate().

Examples

>>> import numpy as np
>>> from pycsamt.format import Grid2DGeometry, PCSFModel, write_pcsf, read_pcsf
>>> geometry = Grid2DGeometry(x=np.array([0.0, 100.0]), z=np.array([10.0, 50.0]))
>>> model = PCSFModel(
...     geometry=geometry,
...     resistivity=np.array([[100.0, 120.0], [50.0, 60.0]]),
...     source_backend="occam2d",
... )
>>> path = write_pcsf(model, "example.pcsf")
>>> round_tripped = read_pcsf(path)
pycsamt.format.io.read_pcsf(path)[source]

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:

ValueError – If pcsf_version is missing, malformed, or names an unrecognised MAJOR version (see pycsamt/format/SPEC.md section 5); if geometry/kind is missing or not a recognised value; or if the reconstructed model fails PCSFModel.validate().

Warns:

UserWarning – If the file’s pcsf_version MINOR component is newer than this reader’s — fields added since then are silently ignored rather than causing a hard failure.