2.23.2.1. pycsamt.format.schema#

In-memory PCSF schema: geometries, stations and topography.

The implementation lives in the standalone pcsf package (pcsf.core.schema), 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.schema

Implementation.

class pycsamt.format.schema.DerivedVolume(grid, resistivity, derivation_method='linear_interp', derived_from=<factory>, synthesized=True)

Bases: PCSFObject

Optional 3-D volume synthesized from stacked lines.

The volume is always labelled as synthesized, so that a reader never mistakes an interpolated stack of 2-D sections for a 3-D inversion (rule C7).

Parameters:
  • grid (Grid3DGeometry) – Grid of the volume.

  • resistivity (ndarray of shape (n_z, n_y, n_x)) – Resistivity in ohm m.

  • derivation_method (str, default "linear_interp") – One of DERIVATION_METHODS.

  • derived_from (list of str) – Identifiers of the lines used.

  • synthesized (bool, default True) – Must stay True for a conforming file.

Examples

>>> import numpy as np
>>> from pcsf.core.schema import DerivedVolume, Grid3DGeometry
>>> grid = Grid3DGeometry(x=[0.0, 10.0], y=[0.0, 100.0], z=[5.0])
>>> vol = DerivedVolume(grid, np.full((1, 2, 2), 100.0),
...                     derived_from=["L0", "L1"])
>>> vol.synthesized
True
grid: Grid3DGeometry
resistivity: ndarray
derivation_method: str = 'linear_interp'
derived_from: list[str]
synthesized: bool = True
validate()

Check the consistency of the arrays.

Raises:

GeometryError – If the resistivity shape does not match the grid or derivation_method is unknown.

Return type:

None

class pycsamt.format.schema.Grid2DGeometry(x, z, x_nodes=None, z_nodes=None, origin=None, azimuth_deg=None)

Bases: PCSFObject

Rectilinear geometry of one 2-D section (Occam2D).

Parameters:
  • x (ndarray (n_x,)) – Real station chainage, metres — never a solver’s mesh-local frame (see the Occam2D coordinate-frame note in the Occam2D adapter).

  • z (ndarray (n_z,)) – Depth cell centres, metres, positive downward.

  • x_nodes (ndarray, optional) – Cell-edge coordinates, one longer than x/z.

  • z_nodes (ndarray, optional) – Cell-edge coordinates, one longer than x/z.

  • origin (ndarray (2,), optional) – Real-world offset when x is locally referenced.

  • azimuth_deg (float, optional) – Profile bearing, for georeferencing back to the survey line.

See also

Grid3DGeometry, UnstructuredMeshGeometry

Examples

>>> from pcsf import Grid2DGeometry
>>> g = Grid2DGeometry(x=[0.0, 50.0, 100.0], z=[5.0, 15.0])
>>> g.resistivity_shape
(2, 3)
kind: ClassVar[str] = 'grid2d'
x: ndarray
z: ndarray
x_nodes: ndarray | None = None
z_nodes: ndarray | None = None
origin: ndarray | None = None
azimuth_deg: float | None = None
validate()

Check the consistency of the arrays.

Raises:

GeometryError – If x or z is not 1-D, a node array does not have one more element than its centres, or origin does not have shape (2,).

Return type:

None

property resistivity_shape: tuple[int, int]

Shape (n_z, n_x) of the resistivity array.

class pycsamt.format.schema.Grid3DGeometry(x, y, z, x_nodes=None, y_nodes=None, z_nodes=None, origin=None, rotation_deg=0.0, n_air=0)

Bases: PCSFObject

Native 3-D tensor volume geometry (ModEM).

Parameters:
  • x (ndarray) – Cell-centre coordinates, metres.

  • y (ndarray) – Cell-centre coordinates, metres.

  • z (ndarray) – Cell-centre coordinates, metres.

  • x_nodes (ndarray, optional) – Cell-edge coordinates.

  • y_nodes (ndarray, optional) – Cell-edge coordinates.

  • z_nodes (ndarray, optional) – Cell-edge coordinates.

  • origin (ndarray (3,), optional) – Real-world grid origin.

  • rotation_deg (float, default 0.0) – Grid rotation about the vertical axis.

  • n_air (int, default 0) – Explicit air-layer count (unlike Occam2D’s inferred count).

Examples

>>> from pcsf.core.schema import Grid3DGeometry
>>> g = Grid3DGeometry(x=[0.0, 1.0], y=[0.0], z=[1.0, 2.0, 3.0])
>>> g.resistivity_shape
(3, 1, 2)
kind: ClassVar[str] = 'grid3d'
x: ndarray
y: ndarray
z: ndarray
x_nodes: ndarray | None = None
y_nodes: ndarray | None = None
z_nodes: ndarray | None = None
origin: ndarray | None = None
rotation_deg: float = 0.0
n_air: int = 0
validate()

Check the consistency of the arrays.

Raises:

GeometryError – If a centre array is not 1-D or a node array does not have one more element than its centres.

Return type:

None

property resistivity_shape: tuple[int, int, int]
class pycsamt.format.schema.LineEntry(line_id, geometry, resistivity, offset_y=0.0, offset_kind='synthetic', azimuth_deg=None)

Bases: PCSFObject

One profile within a MultilineGeometry.

Parameters:
  • line_id (str) – Unique identifier for this line.

  • geometry (Grid2DGeometry) – The line’s own 2-D section geometry.

  • resistivity (ndarray (n_z, n_x)) – Canonical linear ohm.m resistivity for this line.

  • offset_y (float) – Cross-line position, metres.

  • offset_kind ({"real", "synthetic"}, default "synthetic") – Whether offset_y comes from real survey geometry or is a placeholder spacing for display only.

  • azimuth_deg (float, optional) – Line bearing.

Examples

>>> from pcsf.core.schema import Grid2DGeometry, LineEntry
>>> line = LineEntry(
...     "L1", Grid2DGeometry(x=[0.0, 10.0], z=[5.0]),
...     resistivity=[[100.0, 200.0]], offset_y=250.0,
...     offset_kind="real",
... )
>>> line.validate()
line_id: str
geometry: Grid2DGeometry
resistivity: ndarray
offset_y: float = 0.0
offset_kind: str = 'synthetic'
azimuth_deg: float | None = None
validate()

Check the consistency of the arrays.

Raises:

GeometryError – If the resistivity shape does not match the geometry or offset_kind is unknown.

Return type:

None

class pycsamt.format.schema.MultilineGeometry(lines=<factory>, derived_volume=None)

Bases: PCSFObject

A set of 2-D profiles with their real positions.

Each line carries its own geometry and resistivity, so that fence and block views are built from stored data rather than reconstructed at render time. The optional derived volume is a documented, reproducible synthesis.

Parameters:
  • lines (list of LineEntry) – Profiles, with unique identifiers.

  • derived_volume (DerivedVolume, optional) – Volume interpolated from the lines.

Examples

>>> from pcsf.core.schema import (Grid2DGeometry, LineEntry,
...                               MultilineGeometry)
>>> geo = Grid2DGeometry(x=[0.0, 10.0], z=[5.0])
>>> lines = [LineEntry(f"L{i}", geo, [[100.0, 200.0]], 100.0 * i)
...          for i in range(2)]
>>> MultilineGeometry(lines).validate()
kind: ClassVar[str] = 'multiline'
lines: list[LineEntry]
derived_volume: DerivedVolume | None = None
validate()

Check the consistency of the arrays.

Raises:

GeometryError – If there is no line, line identifiers repeat, or a line or the derived volume is invalid.

Return type:

None

class pycsamt.format.schema.PCSFModel(geometry, resistivity=None, resistivity_native=None, resistivity_native_encoding=None, uncertainty=None, sensitivity=None, resistivity_by_region=None, resistivity_by_node=None, stations=None, topography=None, survey=<factory>, history=<factory>, source_backend='generic', created_by='', created_at='', crs=None, description='', metadata=<factory>, boreholes=None)

Bases: PCSFObject, MetadataMixin

Solver-neutral resistivity model; one PCSF file.

Parameters:
  • geometry (geometry object) – The model’s geometry, discriminated by geometry.kind: a Grid2DGeometry, Grid3DGeometry, UnstructuredMeshGeometry or MultilineGeometry.

  • resistivity (ndarray, optional) – Canonical linear ohm.m resistivity. Required for grid2d/grid3d/mesh_unstructured geometries; must be None for multiline (each line carries its own resistivity — see LineEntry).

  • resistivity_native (ndarray, optional) – Passthrough of the source backend’s own array, for provenance.

  • resistivity_native_encoding (str, optional) – Encoding of resistivity_native, a name from pcsf.core.encodings.known_encodings(). Required whenever resistivity_native is given; never assumed.

  • uncertainty (ndarray, optional) – Same shape as resistivity, when available from the source.

  • sensitivity (ndarray, optional) – Same shape as resistivity, when available from the source.

  • resistivity_by_region (ndarray, optional) – Per-region resistivity table (mesh_unstructured only), alongside the per-cell resistivity expanded from it.

  • resistivity_by_node (ndarray, optional) – Per-node resistivity table (mesh_unstructured only), shape (n_nodes,) – the natural output shape of a graph-based model (e.g. a GCN) that predicts one value per mesh vertex rather than per cell. Kept alongside the per-cell resistivity derived from it (see pcsf.algorithms.node_to_cell()).

  • stations (StationTable, optional)

  • topography (TopographyPerStation | TopographyRaster, optional)

  • survey (dict) – Free-form survey metadata. Adapters populate this from survey-metadata objects (SurveyMeta, BBox, ProvenanceMeta) via their own dict conversion; PCSF itself does not require a specific metadata class here.

  • history (dict of ndarray) – Optional per-iteration series (e.g. {"rms": ..., "lambda": ...}) from an InversionHistory-like source.

  • source_backend (str, default "generic") – "occam2d" | "modem3d" | "mare2dem" | "duhi" | "generic".

  • created_by (str) – Producing software and ISO 8601 creation time.

  • created_at (str) – Producing software and ISO 8601 creation time.

  • crs (str, optional) – A pyproj-compatible CRS string.

  • description (str) – Free text.

  • metadata (dict) – Free-form metadata, including the inversion record (metadata["inversion"]).

  • boreholes (dict or object, optional) – Borehole association, interpreted by the borehole companion format and stored as JSON.

See also

pcsf.read, pcsf.write, pcsf.validate

Notes

Arrays are converted to float64 on construction but not checked; call validate() (the writers do) to check shapes and encodings.

Examples

>>> import numpy as np
>>> import pcsf
>>> native = np.log10([[100.0, 300.0]])
>>> model = pcsf.PCSFModel(
...     geometry=pcsf.Grid2DGeometry(x=[0.0, 10.0], z=[5.0]),
...     resistivity=10.0**native,
...     resistivity_native=native,
...     resistivity_native_encoding="log10",
...     source_backend="occam2d",
... )
>>> model.validate()
>>> model.kind
'grid2d'
geometry: Grid2DGeometry | Grid3DGeometry | UnstructuredMeshGeometry | MultilineGeometry
resistivity: ndarray | None = None
resistivity_native: ndarray | None = None
resistivity_native_encoding: str | None = None
uncertainty: ndarray | None = None
sensitivity: ndarray | None = None
resistivity_by_region: ndarray | None = None
resistivity_by_node: ndarray | None = None
stations: StationTable | None = None
topography: TopographyPerStation | TopographyRaster | None = None
survey: dict[str, Any]
history: dict[str, ndarray]
source_backend: str = 'generic'
created_by: str = ''
created_at: str = ''
crs: str | None = None
description: str = ''
metadata: dict[str, Any]
boreholes: Any | None = None
property kind: str

Geometry kind, such as "grid2d".

validate()

Check the consistency of the arrays.

Raises:
  • GeometryError – If the geometry is invalid or an array shape does not match it.

  • EncodingError – If source values are given without a known encoding.

  • TypeError – If boreholes is neither a dict nor an object with to_dict().

Return type:

None

class pycsamt.format.schema.StationTable(name=<factory>, x=<factory>, y=<factory>, z=<factory>, line_id=None, lon=None, lat=None)

Bases: PCSFObject

Survey station positions, shared by all geometry kinds.

Parameters:
  • name (list of str) – Station names.

  • x (ndarray of shape (n,)) – Positions in the model frame, in metres: chainage along the profile for grid2d, the grid frame for grid3d, the mesh frame for mesh_unstructured. They are never geographic coordinates.

  • y (ndarray of shape (n,)) – Positions in the model frame, in metres: chainage along the profile for grid2d, the grid frame for grid3d, the mesh frame for mesh_unstructured. They are never geographic coordinates.

  • z (ndarray of shape (n,)) – Positions in the model frame, in metres: chainage along the profile for grid2d, the grid frame for grid3d, the mesh frame for mesh_unstructured. They are never geographic coordinates.

  • line_id (list of str, optional) – Line of each station, for multiline models.

  • lon (ndarray of shape (n,), optional) – WGS84 longitude and latitude in decimal degrees; the only carrier of real-world position. Both or neither must be given.

  • lat (ndarray of shape (n,), optional) – WGS84 longitude and latitude in decimal degrees; the only carrier of real-world position. Both or neither must be given.

Examples

>>> from pcsf.core.schema import StationTable
>>> st = StationTable(name=["S1", "S2"], x=[0.0, 50.0],
...                   y=[0.0, 0.0], z=[0.0, 0.0],
...                   lon=[-5.0, -5.0])
>>> st.validate()
Traceback (most recent call last):
...
pcsf.exceptions.GeometryError: StationTable.lon and .lat must ...
name: list[str]
x: ndarray
y: ndarray
z: ndarray
line_id: list[str] | None = None
lon: ndarray | None = None
lat: ndarray | None = None
validate()

Check the consistency of the arrays.

Raises:

GeometryError – If an array length differs from the number of names, or only one of lon and lat is set.

Return type:

None

class pycsamt.format.schema.TopographyPerStation(station_id=<factory>, elevation=<factory>)

Bases: PCSFObject

Elevation of each station.

Parameters:
  • station_id (list of str) – Station names, matching StationTable.

  • elevation (ndarray of shape (n,)) – Elevation in metres above the vertical datum.

Examples

>>> from pcsf.core.schema import TopographyPerStation
>>> topo = TopographyPerStation(["S1", "S2"], [312.5, 298.0])
>>> topo.validate()
kind: ClassVar[str] = 'per_station'
station_id: list[str]
elevation: ndarray
validate()

Check the consistency of the arrays.

Raises:

GeometryError – If elevation and station_id differ in length.

Return type:

None

class pycsamt.format.schema.TopographyRaster(x, y, elevation)

Bases: PCSFObject

Gridded elevation surface, independent of stations.

Unlike TopographyPerStation, this carries no station identifiers at all: it is a standalone terrain surface a consumer can sample at any coordinate, not a per-station lookup table. It adds no raster-library dependency: it is built from x, y and elevation arrays obtained by the caller, and pcsf never parses georeferenced raster files.

Parameters:
  • x (ndarray (n_x,)) – Grid x-coordinates (or longitude), increasing.

  • y (ndarray (n_y,)) – Grid y-coordinates (or latitude), increasing.

  • elevation (ndarray (n_y, n_x)) – Elevation surface, metres, sampled on the (y, x) meshgrid implied by x/y — the same row-major convention numpy.meshgrid(x, y) (default indexing="xy") produces.

Examples

>>> import numpy as np
>>> from pcsf.core.schema import TopographyRaster
>>> topo = TopographyRaster(x=[0.0, 10.0, 20.0], y=[0.0, 10.0],
...                         elevation=np.zeros((2, 3)))
>>> topo.validate()
kind: ClassVar[str] = 'raster'
x: ndarray
y: ndarray
elevation: ndarray
validate()

Check the consistency of the arrays.

Raises:

GeometryError – If x or y is not 1-D or elevation does not have shape (len(y), len(x)).

Return type:

None

class pycsamt.format.schema.UnstructuredMeshGeometry(nodes, connectivity, region_ids, plane='xz')

Bases: PCSFObject

Native unstructured triangular mesh geometry (MARE2DEM).

Preserves the mesh as-is (no forced regrid onto a tensor grid), so a MARE2DEM result keeps its real element resolution.

Parameters:
  • nodes (ndarray (n, 2) or (n, 3)) – Node coordinates, metres.

  • connectivity (ndarray (m, 3), int) – Triangle node indices.

  • region_ids (ndarray (m,), int) – Region id per triangle.

  • plane ({"xz", "xy", "3d"}, default "xz") – Physical plane the mesh lives in. MARE2DEM profiles are conventionally in (y, z) but stored generically as plane="xz" with x holding the profile’s own along-line coordinate.

Examples

>>> from pcsf.core.schema import UnstructuredMeshGeometry
>>> mesh = UnstructuredMeshGeometry(
...     nodes=[[0.0, 0.0], [1.0, 0.0], [0.0, 1.0]],
...     connectivity=[[0, 1, 2]],
...     region_ids=[0],
... )
>>> mesh.n_regions
1
kind: ClassVar[str] = 'mesh_unstructured'
nodes: ndarray
connectivity: ndarray
region_ids: ndarray
plane: str = 'xz'
validate()

Check the consistency of the arrays.

Raises:

GeometryError – If an array has the wrong shape, plane is unknown, or the connectivity references a node that does not exist.

Return type:

None

property n_regions: int

Number of distinct region ids.