pycsamt.inversion.export#

Export helpers for pycsamt.inversion results.

Functions

to_archive(result, path, *[, ...])

Write a portable ZIP snapshot of an inversion result.

to_csv(result, path, *[, log_rho])

Export a recovered resistivity model as long-form CSV.

to_geojson(result, path, *[, log_rho])

Export a 2-D inversion section as GeoJSON cell polygons.

to_geotiff(result, path, *[, log_rho, crs])

Export a 2-D inversion section as a single-band GeoTIFF.

to_npz(result, path)

Export common result arrays to a compressed NumPy archive.

to_vtk(result, path, *[, log_rho])

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.files are included under native_files/ when include_native is true.

Parameters:
  • result (InversionResult) – Inversion result to snapshot.

  • path (path-like) – Output .zip path. Parent directories are created automatically.

  • include_native (bool, default True) – Include existing backend-native files listed in result.files under native_files/.

  • log_rho (bool, default True) – Passed to the CSV export stored inside the archive.

Returns:

Path to the written ZIP archive.

Return type:

pathlib.Path

Notes

The archive contains:

  • metadata.json with backend, RMS, warnings, file references, and history/uncertainty metadata.

  • result.npz with numerical arrays.

  • model.csv with 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

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:
Returns:

Path to the written CSV file.

Return type:

pathlib.Path

Examples

>>> from pycsamt.inversion.export import to_csv
>>> to_csv(result, "profile.csv")
>>> to_csv(result, "profile_ohm_m.csv", log_rho=False)

References

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 contains rho_log10_ohm_m. If False, each feature contains rho_ohm_m.

Returns:

Path to the written GeoJSON file.

Return type:

pathlib.Path

Notes

Each model cell is written as one polygon feature. Cell properties include ix, iz, cell-center coordinates, resistivity, and matching uncertainty maps such as uncertainty_confidence when available.

Examples

>>> from pycsamt.inversion.export import to_geojson
>>> to_geojson(result, "profile.geojson")

References

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. If False, 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:

pathlib.Path

Raises:

ImportError – If rasterio is not installed.

Examples

>>> from pycsamt.inversion.export import to_geotiff
>>> to_geotiff(result, "profile.tif")

References

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 .npz path. Parent directories are created automatically.

Returns:

Path to the written compressed NumPy archive.

Return type:

pathlib.Path

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

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_GRID with 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 .vtk path. Parent directories are created automatically.

  • log_rho (bool, default True) – If True, write rho_log10_ohm_m as the primary cell scalar. If False, write rho_ohm_m.

Returns:

Path to the written legacy VTK file.

Return type:

pathlib.Path

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