pycsamt.inversion.backends.modem#
ModEM adapter backend.
This module connects pycsamt.inversion to the ModEM workflow helpers
under pycsamt.models.modem. It does not implement the ModEM
electromagnetic solver itself. Instead, it prepares or locates ModEM input
files, validates the external-run lifecycle, optionally calls the runner when
run_external=True, and loads finished results back into a common
pycsamt.inversion.results.InversionResult.
Classes
|
Adapt PyCSAMT inversion workflows to ModEM. |
- class pycsamt.inversion.backends.modem.ModEMBackend(config)[source]#
Bases:
BaseInversionBackendAdapt PyCSAMT inversion workflows to ModEM.
ModEMBackendis the external-run adapter for 2-D and 3-D MT/AMT inversions. It shares the samepycsamt.inversion.workflow.InversionWorkflowinterface as the runnable in-process backends, but the numerical inversion is performed by the ModEM ecosystem throughpycsamt.models.modem.The backend handles four lifecycle steps:
normalize ModEM configuration from
backend_options;prepare input files with
InputBuilderwhen a data source is supplied;validate required runner files and assemble the external command; and
optionally run ModEM and load finished result files.
- Parameters:
config (pycsamt.inversion.config.InversionConfig) – Inversion configuration. Important fields are
method,dimension,workdir,data,backend_options,run_external, andmetadata. The adapter supports MT and AMT in 2-D or 3-D mode.- Variables:
Notes
backend_optionscan contain:configA
ModEmConfiginstance or dictionary used to configure file names, binary names, MPI settings, and mode-specific options.filesMapping from roles such as
"data","model","control", and"covariance"to existing or expected file paths. Relative paths are resolved insideworkdir.runnerRunner-only options including
use_mpi,n_procs,extra_args,timeout, andload_result.data_file,model_file,control_file,covariance_fileConvenience aliases for file names when a full
filesmapping is not supplied.
By default the backend prepares and validates files but does not execute the external binary. Set
run_external=Trueinpycsamt.inversion.config.InversionConfigto allow execution.Examples
Validate an existing 3-D ModEM run directory without execution:
>>> from pycsamt.inversion.backends.modem import ModEMBackend >>> from pycsamt.inversion.config import InversionConfig >>> cfg = InversionConfig( ... method="mt", ... dimension="3d", ... backend="modem", ... workdir="modem_run", ... backend_options={ ... "files": { ... "data": "ModEM_Data.dat", ... "model": "ModEM_Model.rho", ... "control": "ModEM_Control.inv", ... "covariance": "covariance.cov", ... } ... }, ... ) >>> result = ModEMBackend(cfg).run() >>> result.status in {"ready", "loaded", "needs_review"} True
Use the high-level inversion workflow and request execution:
>>> from pycsamt.inversion.workflow import run_inversion >>> result = run_inversion( ... method="amt", ... dimension="2d", ... backend="modem", ... workdir="modem_2d", ... run_external=True, ... backend_options={ ... "runner": {"use_mpi": False, "timeout": 600}, ... "files": { ... "data": "ModEM_Data.dat", ... "model": "ModEM_Model.rho", ... "control": "ModEM_Control.inv", ... }, ... }, ... )
See also
pycsamt.inversion.workflow.InversionWorkflowHigh-level entry point that instantiates this backend.
pycsamt.inversion.backends.occam2d.Occam2DBackendSimilar external-run adapter for Occam2D.
pycsamt.inversion.results.InversionResultBackend-neutral result returned by
run().
References
- name = 'modem'#
- run(data=None)[source]#
Prepare, validate, optionally run, and load ModEM outputs.
- Parameters:
data (object, mapping, path-like, or sequence, optional) – Input source used by
pycsamt.models.modem.InputBuilderwhen it is available. When omitted,self.config.datais used. If no source is supplied, configured file names are resolved inside the work directory and the backend only validates runner readiness.- Returns:
Backend-neutral result. The
filesmapping contains prepared or configured ModEM file paths,metadata["command"]records the command that would be executed, andnativestores the builder, runner, loaded ModEM result, or another backend-native object.- Return type:
- Raises:
ImportError – If
pycsamt.models.modemis unavailable.NotImplementedError – If the configured method/dimension pair is not supported by this adapter.
Notes
External execution is disabled unless
self.config.run_externalisTrue. With the default value, the method prepares or validates the ModEM directory and reports the command that would be executed when the runner files are complete.The returned status describes the lifecycle stage:
"prepared"Input files were built or configured, but runner readiness was not fully established.
"ready"Required files exist and a command string could be assembled.
"executed"The external runner completed without loading a result object.
"loaded"A ModEM result object was found and attached to
native."needs_review"Preparation, runner execution, or validation raised a recoverable issue. Details are stored in
warnings.
Examples
>>> from pycsamt.inversion.backends.modem import ModEMBackend >>> from pycsamt.inversion.config import InversionConfig >>> cfg = InversionConfig( ... method="mt", ... dimension="3d", ... backend="modem", ... workdir="modem_run", ... backend_options={ ... "files": { ... "data": "ModEM_Data.dat", ... "model": "ModEM_Model.rho", ... "control": "ModEM_Control.inv", ... "covariance": "covariance.cov", ... } ... }, ... ) >>> result = ModEMBackend(cfg).run()