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.schemaImplementation.
- class pycsamt.format.schema.DerivedVolume(grid, resistivity, derivation_method='linear_interp', derived_from=<factory>, synthesized=True)
Bases:
PCSFObjectOptional 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:
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'
- 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:
PCSFObjectRectilinear 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,UnstructuredMeshGeometryExamples
>>> from pcsf import Grid2DGeometry >>> g = Grid2DGeometry(x=[0.0, 50.0, 100.0], z=[5.0, 15.0]) >>> g.resistivity_shape (2, 3)
- x: ndarray
- z: ndarray
- 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
- 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:
PCSFObjectNative 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)
- x: ndarray
- y: ndarray
- z: ndarray
- 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
- class pycsamt.format.schema.LineEntry(line_id, geometry, resistivity, offset_y=0.0, offset_kind='synthetic', azimuth_deg=None)
Bases:
PCSFObjectOne 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'
- 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:
PCSFObjectA 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()
- 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,MetadataMixinSolver-neutral resistivity model; one PCSF file.
- Parameters:
geometry (geometry object) – The model’s geometry, discriminated by
geometry.kind: aGrid2DGeometry,Grid3DGeometry,UnstructuredMeshGeometryorMultilineGeometry.resistivity (ndarray, optional) – Canonical linear ohm.m resistivity. Required for
grid2d/grid3d/mesh_unstructuredgeometries; must beNoneformultiline(each line carries its own resistivity — seeLineEntry).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_unstructuredonly), alongside the per-cell resistivity expanded from it.resistivity_by_node (ndarray, optional) – Per-node resistivity table (
mesh_unstructuredonly), 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 (seepcsf.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 anInversionHistory-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.validateNotes
Arrays are converted to
float64on construction but not checked; callvalidate()(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
- stations: StationTable | None = None
- topography: TopographyPerStation | TopographyRaster | None = None
- source_backend: str = 'generic'
- created_by: str = ''
- created_at: str = ''
- description: str = ''
- 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:
PCSFObjectSurvey station positions, shared by all geometry kinds.
- Parameters:
x (ndarray of shape (n,)) – Positions in the model frame, in metres: chainage along the profile for
grid2d, the grid frame forgrid3d, the mesh frame formesh_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 forgrid3d, the mesh frame formesh_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 forgrid3d, the mesh frame formesh_unstructured. They are never geographic coordinates.line_id (list of str, optional) – Line of each station, for
multilinemodels.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 ...
- x: ndarray
- y: ndarray
- z: ndarray
- 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:
PCSFObjectElevation of each station.
- Parameters:
Examples
>>> from pcsf.core.schema import TopographyPerStation >>> topo = TopographyPerStation(["S1", "S2"], [312.5, 298.0]) >>> topo.validate()
- 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:
PCSFObjectGridded 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 fromx,yandelevationarrays 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 conventionnumpy.meshgrid(x, y)(defaultindexing="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()
- 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:
PCSFObjectNative 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 asplane="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
- 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.