pycsamt.inversion.backends.occam2d#
Occam2D adapter backend.
This module connects pycsamt.inversion to the Occam2D workflow helpers
under pycsamt.models.occam2d. It prepares Occam2D input directories,
validates runner files, optionally executes the external binary when
run_external=True, and loads finished Occam2D results into the common
pycsamt.inversion.results.InversionResult container.
Classes
|
Adapt PyCSAMT inversion workflows to Occam2D. |
- class pycsamt.inversion.backends.occam2d.Occam2DBackend(config)[source]#
Bases:
BaseInversionBackendAdapt PyCSAMT inversion workflows to Occam2D.
Occam2DBackendis the external-run adapter for smooth 2-D EM inversion with Occam2D-style workflows. It usespycsamt.models.occam2dto prepare input files, assemble runner commands, optionally launch the external executable, and load completed model sections. The actual inversion physics are provided by Occam2D, while PyCSAMT keeps a consistent configuration and result interface.The adapter supports MT, AMT, CSAMT, and EMAP in 2-D mode. Its main purpose is to make external Occam2D projects reproducible from
pycsamt.inversion.config.InversionConfigand to return a commonpycsamt.inversion.results.InversionResult.- Parameters:
config (pycsamt.inversion.config.InversionConfig) – Inversion configuration. Important fields are
method,dimension,workdir,data,backend_options,run_external,error_floor,phase_error, andmetadata.- Variables:
Notes
backend_optionscan contain:configAn
OccamConfiginstance or dictionary used to configure file names and binary settings.filesMapping from roles
"data","mesh","model", and"startup"to existing or expected paths. Relative paths are resolved insideworkdir.runnerRunner-only options such as
binary_path,startup_file,max_iter,target_misfit, andauto_compile.binary_pathConvenience runner executable path when not supplied inside
runner.
When a data source is supplied,
InputBuilderreceives the source and the configured error floors. Without a data source, the adapter treatsbackend_options["files"]as an existing Occam2D project and only validates whether it is ready to run or load.Examples
Validate an existing Occam2D directory without executing the binary:
>>> from pycsamt.inversion.backends.occam2d import Occam2DBackend >>> from pycsamt.inversion.config import InversionConfig >>> cfg = InversionConfig( ... method="mt", ... dimension="2d", ... backend="occam2d", ... workdir="occam_run", ... backend_options={ ... "files": { ... "data": "OccamData.dat", ... "mesh": "OccamMesh", ... "model": "OccamModel", ... "startup": "Startup", ... } ... }, ... ) >>> result = Occam2DBackend(cfg).run() >>> result.status in {"ready", "loaded", "needs_review"} True
Run through the high-level workflow and allow external execution:
>>> from pycsamt.inversion.workflow import run_inversion >>> result = run_inversion( ... method="csamt", ... dimension="2d", ... backend="occam2d", ... workdir="occam_csamt", ... run_external=True, ... backend_options={ ... "runner": { ... "binary_path": "Occam2D", ... "startup_file": "Startup", ... "target_misfit": 1.0, ... }, ... "files": { ... "data": "OccamData.dat", ... "mesh": "OccamMesh", ... "model": "OccamModel", ... "startup": "Startup", ... }, ... }, ... )
See also
pycsamt.inversion.workflow.InversionWorkflowHigh-level entry point that instantiates this backend.
pycsamt.inversion.backends.modem.ModEMBackendSimilar external-run adapter for ModEM.
pycsamt.inversion.results.InversionResultBackend-neutral result returned by
run().
References
- name = 'occam2d'#
- supports: tuple[tuple[str, str], ...] = (('mt', '2d'), ('amt', '2d'), ('csamt', '2d'), ('emap', '2d'))#
- run(data=None)[source]#
Prepare, validate, optionally run, and load Occam2D outputs.
- Parameters:
data (object, mapping, path-like, or sequence, optional) – Input source used by
pycsamt.models.occam2d.InputBuilder. When omitted,self.config.datais used. If no source is supplied, configured file names are resolved insideworkdirand the backend validates whether the runner can be launched.- Returns:
Backend-neutral result. The
filesmapping contains data, mesh, model, and startup file paths when known.metadatastores the command, startup file, binary name, external execution flag, exit code, and whether a runner was executed.- Return type:
- Raises:
ImportError – If
pycsamt.models.occam2dis unavailable.NotImplementedError – If the configured method/dimension pair is not supported.
Notes
External execution is disabled unless
self.config.run_externalisTrue. With the default value, this method prepares or validates the directory and reports the command that would be used when all required files exist.Status values follow the adapter lifecycle:
"prepared"Files were prepared or configured, but the runner is not ready.
"ready"Required files exist and an Occam2D command was assembled.
"executed"The external runner returned exit code
0."loaded"A finished Occam2D result with
rho_2dwas loaded."needs_review"Preparation, runner execution, or result loading needs user review.
Examples
>>> from pycsamt.inversion.backends.occam2d import Occam2DBackend >>> from pycsamt.inversion.config import InversionConfig >>> cfg = InversionConfig( ... method="mt", ... dimension="2d", ... backend="occam2d", ... workdir="occam_run", ... backend_options={ ... "files": { ... "data": "OccamData.dat", ... "mesh": "OccamMesh", ... "model": "OccamModel", ... "startup": "Startup", ... } ... }, ... ) >>> result = Occam2DBackend(cfg).run()