pycsamt.forward.config2d#

Configuration for pyCSAMT 2-D MT forward modelling.

ForwardConfig2D is the configuration object for MT2DForward. It records every parameter needed to build a Grid2D and run the finite-difference solver, and can be exported to Python, JSON, or YAML.

Quick start#

from pycsamt.forward.config2d import ForwardConfig2D

# Write an annotated source-of-truth file
ForwardConfig2D.write_template("my_2d.yml")

# Edit my_2d.yml …

# Load, validate, build grid, run solver
cfg = ForwardConfig2D.from_file("my_2d.yml")
cfg.validate()

grid = cfg.to_grid()
from pycsamt.forward.em2d import MT2DForward
resp = MT2DForward(cfg.freq_grid(), grid).run()

Classes

ForwardConfig2D([freq_min, freq_max, ...])

Collect settings for a 2-D MT finite-difference forward run.

class pycsamt.forward.config2d.ForwardConfig2D(freq_min=0.001, freq_max=1000.0, n_freqs=20, nx=40, nz=30, x_max=10000.0, z_max=6000.0, n_pad=8, pad_factor=1.3, bg_rho=100.0, model_type='halfspace', anomaly_rho=5.0, anomaly_x_lo=2000.0, anomaly_x_hi=6000.0, anomaly_z_lo=300.0, anomaly_z_hi=1500.0, n_stations=10, station_x_max=None, verbose=True)[source]#

Bases: object

Collect settings for a 2-D MT finite-difference forward run.

The configuration covers four areas: frequency grid, FD grid geometry, starting earth model, and station layout.

Parameters:
  • freq_min (float) – Frequency range [Hz].

  • freq_max (float) – Frequency range [Hz].

  • n_freqs (int) – Number of logarithmically spaced frequencies.

  • nx (int) – Core cell counts (x, z).

  • nz (int) – Core cell counts (x, z).

  • x_max (float) – Core region extents [m].

  • z_max (float) – Core region extents [m].

  • n_pad (int) – Padding cells per side.

  • pad_factor (float) – Padding growth factor.

  • bg_rho (float) – Background resistivity [Ω·m].

  • model_type ({'halfspace', 'anomaly', 'random'}) – Grid constructor to use.

  • anomaly_rho (float) – Anomaly resistivity [Ω·m] (model_type=’anomaly’ only).

  • anomaly_x_lo (float) – Horizontal anomaly bounds [m].

  • anomaly_x_hi (float) – Horizontal anomaly bounds [m].

  • anomaly_z_lo (float) – Depth anomaly bounds [m].

  • anomaly_z_hi (float) – Depth anomaly bounds [m].

  • n_stations (int) – Number of equally spaced surface stations.

  • station_x_max (float or None) – Right-most station position [m].

  • verbose (bool)

Examples

Default halfspace:

>>> cfg = ForwardConfig2D()
>>> cfg.model_type
'halfspace'
>>> cfg.validate()

Template round-trip:

>>> import tempfile, os
>>> with tempfile.NamedTemporaryFile(suffix='.yml', delete=False) as f:
...     path = f.name
>>> _ = ForwardConfig2D.write_template(path)
>>> cfg2 = ForwardConfig2D.from_file(path)
>>> os.unlink(path)
freq_min: float = 0.001#
freq_max: float = 1000.0#
n_freqs: int = 20#
nx: int = 40#
nz: int = 30#
x_max: float = 10000.0#
z_max: float = 6000.0#
n_pad: int = 8#
pad_factor: float = 1.3#
bg_rho: float = 100.0#
model_type: str = 'halfspace'#
anomaly_rho: float = 5.0#
anomaly_x_lo: float = 2000.0#
anomaly_x_hi: float = 6000.0#
anomaly_z_lo: float = 300.0#
anomaly_z_hi: float = 1500.0#
n_stations: int = 10#
station_x_max: float | None = None#
verbose: bool = True#
validate()[source]#

Raise ValueError on invalid parameter values.

Return type:

None

freq_grid()[source]#

Return the logarithmically spaced frequency array [Hz].

Return type:

ndarray

to_grid(seed=None)[source]#

Construct a Grid2D from this config.

Parameters:

seed (int or None) – Random seed (used only for model_type='random').

Return type:

Grid2D

to_solver_kwargs()[source]#

Return kwargs for MT2DForward.

Return type:

dict[str, Any]

to_template(path='forward_config_2d.py', *, fmt=None)[source]#

Write to an annotated source-of-truth file.

Parameters:
Return type:

Path

classmethod write_template(path='forward_config_2d.py', *, fmt=None)[source]#

Generate a documented source-of-truth file with default values.

Parameters:
  • path (path-like)

  • fmt ({"py", "json", "yml", "yaml"}, optional)

Return type:

pathlib.Path

classmethod from_file(path, *, strict=True)[source]#

Load from a generated source-of-truth file.

Parameters:
  • path (path-like)

  • strict (bool)

Return type:

ForwardConfig2D

classmethod read(path, *, strict=True)#

Load from a generated source-of-truth file.

Parameters:
  • path (path-like)

  • strict (bool)

Return type:

ForwardConfig2D

summary()[source]#
Return type:

str