2.14.4.5. pycsamt.emtools.lcurve#

Functions

lcurve_from_mare2dem(path, **kwargs)

Build an LCurveData sweep from a MARE2DEM convergence log.

lcurve_from_modem(path, **kwargs)

Build an LCurveData sweep from a ModEM NLCG log.

lcurve_from_occam2d(path, **kwargs)

Build an LCurveData sweep from an Occam2D convergence log.

lcurve_table(misfit, rough[, lam, sort, ...])

plot_lcurve(misfit, rough[, lam, labels, ...])

Classes

LCurveData(misfit, rough, lam, iterations, ...)

Misfit/roughness/lambda sweep extracted from a real inversion log.

pycsamt.emtools.lcurve.lcurve_table(misfit, rough, lam=None, *, sort='auto', method='curvature', smooth=3, skip=1, return_dict=False)[source]
Parameters:
class pycsamt.emtools.lcurve.LCurveData(misfit, rough, lam, iterations, backend, source)[source]

Bases: object

Misfit/roughness/lambda sweep extracted from a real inversion log.

misfit[i], rough[i], lam[i], and iterations[i] all describe the same iteration, so the arrays can be passed straight into lcurve_table() or plot_lcurve() – which is exactly what table() and plot() do.

Parameters:
misfit: ndarray
rough: ndarray
lam: ndarray
iterations: ndarray
backend: str
source: Path
table(**kwargs)[source]

Call lcurve_table() on this sweep.

Parameters:

kwargs (Any)

plot(**kwargs)[source]

Call plot_lcurve() on this sweep.

Parameters:

kwargs (Any)

pycsamt.emtools.lcurve.lcurve_from_occam2d(path, **kwargs)[source]

Build an LCurveData sweep from an Occam2D convergence log.

Reads the per-iteration LogFile.logfile written by the Occam2D Fortran binary with pycsamt.models.occam2d.log.OccamLog, which already parses accepted RMS misfit, roughness, and Lagrange multiplier for every completed iteration. Rows with a non-finite or non-positive misfit or roughness (for example a final iteration that stopped on “Convergence problems” before writing ROUGHNESS IS) are dropped, since lcurve_table() requires strictly positive values for its log-log scoring.

Parameters:
  • path (path-like) – Path to an Occam2D log file, typically LogFile.logfile.

  • **kwargs – Forwarded to OccamLog.read (for example verbose).

Returns:

rough holds Occam’s reported ROUGHNESS IS values, misfit the accepted RMS, and lam the accepted Lagrange multiplier (linear scale, not log10).

Return type:

LCurveData

Examples

>>> from pycsamt.emtools.lcurve import lcurve_from_occam2d
>>> sweep = lcurve_from_occam2d("data/occam2D/LogFile.logfile")
>>> sweep.backend
'occam2d'
>>> ax = sweep.plot()
pycsamt.emtools.lcurve.lcurve_from_modem(path, **kwargs)[source]

Build an LCurveData sweep from a ModEM NLCG log.

Reads the per-iteration Completed NLCG iteration blocks written by ModEM with pycsamt.models.modem.log.ModEmLog. ModEM reports the model-regularization term directly as m2 rather than a roughness norm, so rough here is m2 – the same quantity \(\lambda\,\Phi_m(m)\) trades off against data misfit in ModEM’s objective function, and it plays the identical x-axis role on an L-curve.

Parameters:
  • path (path-like) – Path to a ModEM log file, typically Modular_NLCG.log.

  • **kwargs – Forwarded to ModEmLog.read (for example verbose).

Returns:

rough holds ModEM’s m2 model-norm term, misfit the reported rms, and lam the damping parameter lambda.

Return type:

LCurveData

Examples

>>> from pycsamt.emtools.lcurve import lcurve_from_modem
>>> sweep = lcurve_from_modem(
...     "data/modem/willy_27freq_watex_line02_sample/Modular_NLCG.log"
... )
>>> sweep.backend
'modem'
>>> ax = sweep.plot()
pycsamt.emtools.lcurve.lcurve_from_mare2dem(path, **kwargs)[source]

Build an LCurveData sweep from a MARE2DEM convergence log.

Reads the per-iteration ** Iteration N ** blocks written by MARE2DEM with pycsamt.models.mare2dem.log.Mare2DEMLog, which already parses Model Misfit, Roughness, and Optimal Mu for every completed iteration. MARE2DEM reports Optimal Mu as \(\log_{10}\mu\), so it is converted back to linear scale here to match the convention used by the other two adapters.

Parameters:
  • path (path-like) – Path to a MARE2DEM log file, typically *.logfile.

  • **kwargs – Accepted for interface symmetry with the other adapters; Mare2DEMLog takes no extra keyword arguments.

Returns:

rough holds MARE2DEM’s reported roughness, misfit the model misfit, and lam the optimal mu converted to linear scale (10 ** log10_mu).

Return type:

LCurveData

Examples

>>> from pycsamt.emtools.lcurve import lcurve_from_mare2dem
>>> sweep = lcurve_from_mare2dem(
...     "data/mare2dem/demo_mt_inversion/demo.logfile"
... )
>>> sweep.backend
'mare2dem'
>>> ax = sweep.plot()
pycsamt.emtools.lcurve.plot_lcurve(misfit, rough, lam=None, *, labels=None, colors=None, cmap='viridis', marker='o', ms=3.0, lw=1.4, alpha=0.9, show_points=True, show_path=True, arrow_every=0, method='curvature', smooth=3, skip=1, show_corner=True, corner_style=None, show_inset=True, inset_loc=(0.62, 0.12, 0.32, 0.32), label_every=0, label_prefix='', label_fontsize=7.0, target_misfit=None, target_label='target misfit', figsize=(6.0, 4.6), ax=None)[source]
Parameters: