2.21.1.9. pycsamt.inversion.export#
Export helpers for pycsamt.inversion results.
Functions
|
Write a portable ZIP snapshot of an inversion result. |
|
Export a recovered resistivity model as long-form CSV. |
|
Export a 2-D inversion section as GeoJSON cell polygons. |
|
Export a 2-D inversion section as a single-band GeoTIFF. |
|
Export common result arrays to a compressed NumPy archive. |
|
Export a 2-D inversion section as legacy ASCII VTK. |
- pycsamt.inversion.export.to_archive(result, path, *, include_native=True, log_rho=True)[source]
Write a portable ZIP snapshot of an inversion result.
The archive always contains common products (metadata, NPZ, CSV). Existing backend-native files referenced by
result.filesare included undernative_files/when include_native is true.- Parameters:
result (InversionResult) – Inversion result to snapshot.
path (path-like) – Output
.zippath. Parent directories are created automatically.include_native (bool, default True) – Include existing backend-native files listed in
result.filesundernative_files/.log_rho (bool, default True) – Passed to the CSV export stored inside the archive.
- Returns:
Path to the written ZIP archive.
- Return type:
Notes
The archive contains:
metadata.jsonwith backend, RMS, warnings, file references, and history/uncertainty metadata.result.npzwith numerical arrays.model.csvwith the long-form resistivity model.native_files/entries when available and requested.
Examples
>>> from pycsamt.inversion.export import to_archive >>> to_archive(result, "run_snapshot.zip")
References
[to-archive-1]PKWARE Inc. ZIP File Format Specification.
- pycsamt.inversion.export.to_csv(result, path, *, log_rho=True)[source]
Export a recovered resistivity model as long-form CSV.
The CSV writer stores one row per model cell with profile position, depth, resistivity value, and station label. It is the simplest exchange format for spreadsheets, quick inspection, and downstream scripts that do not need mesh topology.
- Parameters:
result (InversionResult) – Inversion result convertible through
pycsamt.inversion.results.InversionResult.to_resistivity_model().path (path-like) – Output CSV path. Parent directories are created automatically.
log_rho (bool, default True) – If
True, writelog10(rho / ohm m)values. IfFalse, write linear resistivity in ohm metres.
- Returns:
Path to the written CSV file.
- Return type:
Examples
>>> from pycsamt.inversion.export import to_csv >>> to_csv(result, "profile.csv") >>> to_csv(result, "profile_ohm_m.csv", log_rho=False)
References
[to-csv-1]Shafranovich, Y. (2005). Common Format and MIME Type for Comma-Separated Values (CSV) Files. RFC 4180.
- pycsamt.inversion.export.to_geojson(result, path, *, log_rho=True)[source]
Export a 2-D inversion section as GeoJSON cell polygons.
Coordinates are profile-distance/depth pairs in metres. Depth is positive downward, matching
pycsamt.interp.ResistivityModel.- Parameters:
result (InversionResult) – Inversion result convertible to a 2-D resistivity model.
path (path-like) – Output GeoJSON path. Parent directories are created automatically.
log_rho (bool, default True) – If
True, each feature containsrho_log10_ohm_m. IfFalse, each feature containsrho_ohm_m.
- Returns:
Path to the written GeoJSON file.
- Return type:
Notes
Each model cell is written as one polygon feature. Cell properties include
ix,iz, cell-center coordinates, resistivity, and matching uncertainty maps such asuncertainty_confidencewhen available.Examples
>>> from pycsamt.inversion.export import to_geojson >>> to_geojson(result, "profile.geojson")
References
[to-geojson-1]Butler, H. et al. (2016). The GeoJSON Format. RFC 7946.
- pycsamt.inversion.export.to_geotiff(result, path, *, log_rho=True, crs=None)[source]
Export a 2-D inversion section as a single-band GeoTIFF.
This writer requires
rasterio. The raster axes are profile distance and depth in metres; pass crs only when those coordinates are already tied to a projected coordinate reference system.- Parameters:
result (InversionResult) – Inversion result convertible to a 2-D resistivity model.
path (path-like) – Output GeoTIFF path. Parent directories are created automatically.
log_rho (bool, default True) – If
True, write log10 resistivity. IfFalse, write linear resistivity in ohm metres.crs (object, optional) – Coordinate reference system passed to
rasterio. Use this only when profile/depth coordinates are already in a projected CRS.
- Returns:
Path to the written GeoTIFF.
- Return type:
- Raises:
ImportError – If
rasteriois not installed.
Examples
>>> from pycsamt.inversion.export import to_geotiff >>> to_geotiff(result, "profile.tif")
References
[to-geotiff-1]Ritter, N. and Ruth, M. (1997). GeoTIFF Format Specification.
[to-geotiff-2]Gillies, S. et al. Rasterio documentation.
- pycsamt.inversion.export.to_npz(result, path)[source]
Export common result arrays to a compressed NumPy archive.
The NPZ writer preserves numerical arrays used by the inversion API: resistivity grid, coordinates, station metadata, RMS, and optional uncertainty/history arrays. It is the preferred lightweight format for Python workflows because arrays are stored without text parsing.
- Parameters:
result (InversionResult) – Inversion result convertible to a resistivity model. Uncertainty and convergence-history arrays are exported when present.
path (path-like) – Output
.npzpath. Parent directories are created automatically.
- Returns:
Path to the written compressed NumPy archive.
- Return type:
Examples
>>> import numpy as np >>> from pycsamt.inversion.export import to_npz >>> path = to_npz(result, "profile.npz") >>> arrays = np.load(path) >>> arrays["rho_2d"].shape (10, 20)
References
[to-npz-1]NumPy Developers.
numpy.savez_compresseddocumentation.
- pycsamt.inversion.export.to_vtk(result, path, *, log_rho=True)[source]
Export a 2-D inversion section as legacy ASCII VTK.
The file is a
RECTILINEAR_GRIDwith one cell in the cross-line direction, suitable for ParaView and other lightweight model viewers.- Parameters:
result (InversionResult) – Inversion result convertible to a 2-D resistivity model.
path (path-like) – Output
.vtkpath. Parent directories are created automatically.log_rho (bool, default True) – If
True, writerho_log10_ohm_mas the primary cell scalar. IfFalse, writerho_ohm_m.
- Returns:
Path to the written legacy VTK file.
- Return type:
Notes
The profile coordinate is written on the VTK X axis, a dummy cross-line axis is written on Y, and positive-down depth is written on Z. Matching 2-D uncertainty arrays are included as additional cell scalars.
Examples
>>> from pycsamt.inversion.export import to_vtk >>> to_vtk(result, "profile.vtk")
References
[to-vtk-1]Schroeder, W., Martin, K. and Lorensen, B. (2006). The Visualization Toolkit, 4th edition.