Forward And Inversion Workflow Agents#

These agents prepare, run, evaluate, or compare physics-based modelling and inversion workflows.

ForwardModelAgent#

ForwardModelAgent runs MT forward modelling from resistivity models. Use it for synthetic checks, sensitivity experiments, or validating how a proposed model should appear in impedance or apparent-resistivity space.

1from pycsamt.agents import ForwardModelAgent
2
3result = ForwardModelAgent().execute({
4    "model": layered_model,
5    "periods": [0.01, 0.1, 1.0, 10.0],
6    "output_dir": "/out/forward",
7})

InversionPrepAgent#

InversionPrepAgent is the general pre-inversion interface. It prepares MT data products for inversion codes and is useful when a workflow should be backend-agnostic or when the exact inversion target is decided later.

1result = InversionPrepAgent().execute({
2    "sites": processed_sites,
3    "output_dir": "/out/inversion_prep",
4})

Occam2DAgent#

Occam2DAgent is the specialized Occam2D preparation agent. It writes the data, mesh, startup, and related files needed to start an Occam2D workflow.

Use it after QC, correction, optional rotation, and frequency selection.

1occam = Occam2DAgent().execute({
2    "sites": processed_sites,
3    "output_dir": "/out/willy_occam2d",
4    "run_external": False,
5})

ModEmAgent#

ModEmAgent prepares ModEM 3-D impedance data files. Use it when the survey and interpretation target require 3-D inversion products.

1modem = ModEmAgent().execute({
2    "sites": processed_sites,
3    "output_dir": "/out/willy_modem",
4})

Mare2DEMAgent#

Mare2DEMAgent orchestrates MARE2DEM 2.5-D EM inversion preparation and, when a compiled binary is available, execution. It is the specialized agent to use when the target workflow needs MARE2DEM .emdata, .resistivity, .settings, and run-directory products rather than Occam2D or ModEM files.

The agent can work in three modes:

"prepare"

Write input files only. This is the safest default and is appropriate when the run will be launched manually on a workstation or cluster.

"run"

Write inputs and launch the configured MARE2DEM binary. Use this only after confirming the binary, MPI configuration, and source tree.

"report"

Inspect an existing run directory and summarize result state without writing new inputs or launching the binary.

Typical input keys include emdata for an existing data file, mt or csem dictionaries for building survey data, optional topo, optional resistivity, output_dir, source_dir, n_procs, max_iterations, target_rms, and initial_rho.

 1from pycsamt.agents import Mare2DEMAgent
 2
 3prepared = Mare2DEMAgent(n_procs=8).execute({
 4    "emdata": "/data/willy.emdata",
 5    "output_dir": "/out/willy_mare2dem",
 6    "mode": "prepare",
 7    "initial_rho": 100.0,
 8    "target_rms": 1.0,
 9})
10
11print(prepared["data_path"])
12print(prepared["settings_path"])
13print(prepared["binary_found"])

When building from survey parameters, pass the MARE2DEM survey configuration through mt or csem:

 1import numpy as np
 2from pycsamt.agents import Mare2DEMAgent
 3
 4result = Mare2DEMAgent(n_procs=16).execute({
 5    "mt": {
 6        "frequencies": list(np.logspace(-3, 3, 20)),
 7        "rx_y": list(np.linspace(-5000, 5000, 20)),
 8        "rx_type": "land",
 9        "lTE": True,
10        "lTM": True,
11    },
12    "topo": 0.0,
13    "output_dir": "/out/synthetic_mare2dem",
14    "mode": "prepare",
15})

Use Mare2DEMAgent after QC, static-shift correction, tensor rotation, and frequency selection. Use InversionEvaluationAgent afterwards when a run directory contains results that need RMS, convergence, or residual summaries.

InversionBackendAgent#

InversionBackendAgent connects agent workflows to pyCSAMT inversion backends. It is the right place for workflows that should select or execute a configured backend rather than only write preparation files.

1backend = InversionBackendAgent().execute({
2    "sites": processed_sites,
3    "backend": "occam2d",
4    "output_dir": "/out/backend_run",
5})

InversionEvaluationAgent#

InversionEvaluationAgent evaluates inversion results. Use it after an Occam2D, ModEM, or backend run to summarize RMS, residuals, misfit sections, and quality indicators.

1evaluation = InversionEvaluationAgent().execute({
2    "result_path": "/out/willy_occam2d",
3    "observed_sites": processed_sites,
4    "output_dir": "/out/willy_eval",
5})

InversionComparisonAgent#

InversionComparisonAgent compares inversion sections or model outputs. Use it for before/after studies, backend comparisons, parameter sweeps, or checking whether correction changed the interpreted structure.

1comparison = InversionComparisonAgent().execute({
2    "reference": "/out/run_a/model.dat",
3    "candidate": "/out/run_b/model.dat",
4    "output_dir": "/out/comparison",
5})

Typical Physics-Based Chain#

MTLoaderAgent -> DataQCAgent -> StaticShiftAgent
-> PhaseAnalysisAgent -> FrequencyDecimationAgent
-> Occam2DAgent or ModEmAgent or Mare2DEMAgent
-> InversionEvaluationAgent

Use InversionComparisonAgent when multiple model outputs need to be compared and documented.