Configuration#

pyCSAMT can be used with almost no configuration for a first survey, but a real project usually needs a few choices to be explicit:

  • where outputs are written;

  • how progress and CLI output should look;

  • whether dataframe-like results are wrapped in pyCSAMT view objects;

  • which plot style should be used;

  • which AI backend should be selected;

  • whether AI-assisted agents may call an LLM provider;

  • how much LLM cost is allowed in one session.

Most v2 configuration follows the same pattern:

1configure_something(...)
2reset_something()
3
4with PYCSAMT_SOMETHING.context(...):
5    ...

Use global configuration for a notebook or application session. Use context managers when one workflow needs temporary settings.

Quick project setup#

This is a reasonable starting configuration for a local project.

 1from pycsamt.api import (
 2    configure_api_view,
 3    configure_cli,
 4    configure_pipe,
 5    configure_style,
 6)
 7from pycsamt.backends import set_backend
 8
 9configure_api_view(backend="pycsamt")
10
11configure_cli(
12    log__level=1,
13    output__format="text",
14    output__dir="results",
15    build__n_jobs=4,
16)
17
18configure_pipe(
19    output_root="results/pipeline",
20    plot_dpi=200,
21    plot_fmt="png",
22    show_progress=True,
23    on_step_error="warn",
24)
25
26configure_style(
27    multiline__mode="gradient",
28    multiline__base_color="blue",
29    mt__xy__color="#003f88",
30    mt__yx__color="#d62828",
31)
32
33# Optional: only needed for AI/model-zoo workflows.
34set_backend("auto")

This does not configure LLM agents. Agents can still run deterministic steps where supported, but LLM interpretation remains disabled until a provider key is configured.

Configuration layers#

pyCSAMT has several configuration layers because different parts of the package solve different problems.

Layer

Main object

What it controls

API view

PYCSAMT_API_VIEW

Whether dataframe-like results are returned as pyCSAMT view objects or raw pandas-style objects.

CLI

PYCSAMT_CLI

Verbosity, color, output format, output directory, cache, and job count for command-line workflows.

Pipeline

PYCSAMT_PIPE

Pipeline output directories, progress style, plot format, report format, and step error policy.

Style

PYCSAMT_STYLE

Plot colors, line styles, rose diagrams, component colors, and publication-style visual defaults.

AI backend

pycsamt.backends

PyTorch/TensorFlow backend selection for AI inversion and model-zoo workflows.

Agents

AGENT_CONFIG

LLM provider, model, API keys, pricing, and session budget.

Inspect current settings#

The global configuration objects are normal Python objects. You can print them or inspect their attributes.

1from pycsamt.api import PYCSAMT_CLI, PYCSAMT_PIPE
2from pycsamt.api.view import PYCSAMT_API_VIEW
3from pycsamt.backends import get_backend, list_backends
4
5print(PYCSAMT_CLI)
6print(PYCSAMT_PIPE)
7print(PYCSAMT_API_VIEW)
8print(get_backend())
9print(list_backends())

For agents:

1from pycsamt.agents import AGENT_CONFIG
2
3print(AGENT_CONFIG.info())

Temporary configuration#

Context managers are useful when a single block of code needs different settings without changing the rest of the session.

 1from pycsamt.api import PYCSAMT_PIPE
 2from pycsamt.pipeline import Pipeline, Step
 3
 4pipe = Pipeline([
 5    ("notch", Step("NR001", mains_hz=50)),
 6    ("band", Step("FREQ001")),
 7])
 8
 9with PYCSAMT_PIPE.context(
10    output_root="results/publication",
11    plot_dpi=300,
12    plot_fmt="pdf",
13    show_progress=False,
14):
15    result = pipe.run(sites)
16
17# The previous pipeline settings are restored here.

API view configuration#

Many public helpers return dataframe-like data. The API view layer controls whether those results are wrapped in pyCSAMT’s lightweight view objects.

Default behavior uses pyCSAMT wrappers:

1from pycsamt.api import configure_api_view, read_edis
2
3configure_api_view(backend="pycsamt")
4survey = read_edis("data/willy/edis")

To receive raw pandas-style objects where applicable:

1from pycsamt.api import configure_api_view
2
3configure_api_view(backend="pandas")

Accepted values:

Value

Meaning

"pycsamt", "api", "view", True

Return pyCSAMT API view wrappers.

"pandas", "raw", "none", False

Return the raw dataframe-like object.

callable

Call wrapper(data, **metadata) and return the custom wrapper result.

Environment variable:

1export PYCSAMT_API_VIEW=pandas

CLI configuration#

The CLI configuration uses section-style keys with double underscores:

 1from pycsamt.api import PYCSAMT_CLI, configure_cli, reset_cli
 2
 3configure_cli(
 4    log__level=1,
 5    log__color=True,
 6    output__format="json",
 7    output__dir="results/cli",
 8    output__overwrite=False,
 9    build__n_jobs=4,
10    build__cache=True,
11)
12
13print(PYCSAMT_CLI.summary())
14
15reset_cli()

Important keys:

Key

Values

Meaning

log__level

0, 1, 2

Quiet, info, or debug verbosity.

log__color

True or False

Enable colored terminal output.

output__format

"text", "json", "csv"

Preferred command output format.

output__dir

path-like

Default output directory.

output__overwrite

True or False

Whether existing output may be overwritten.

build__n_jobs

integer >= 1

Number of jobs for CLI workflows that support parallel execution.

build__cache

True or False

Enable command cache where supported.

Environment variables loaded at import time:

Variable

Meaning

PYCSAMT_VERBOSE

Integer verbosity level, usually 0, 1, or 2.

PYCSAMT_NO_COLOR

Any non-empty value disables color.

PYCSAMT_OUTPUT

Output format: text, json, or csv.

PYCSAMT_OUTPUT_DIR

Default output directory.

PYCSAMT_JOBS

Integer job count.

Example shell setup:

1export PYCSAMT_VERBOSE=1
2export PYCSAMT_OUTPUT=json
3export PYCSAMT_OUTPUT_DIR=results/cli
4export PYCSAMT_JOBS=4

Pipeline configuration#

Pipeline configuration controls the default behavior of pycsamt.pipeline.Pipeline.run.

 1from pycsamt.api import PYCSAMT_PIPE, configure_pipe, reset_pipe
 2
 3configure_pipe(
 4    output_root="results/pipeline",
 5    processed_subdir="processed",
 6    plots_subdir="plots",
 7    on_step_error="warn",
 8    save_intermediate=False,
 9    show_progress=True,
10    progress_style="bar",
11    plot_dpi=150,
12    plot_fmt="png",
13    report_formats=("html", "txt"),
14)
15
16print(PYCSAMT_PIPE)
17
18reset_pipe()

Key settings:

Setting

Default

Meaning

output_root

"pipe_results"

Root directory used when Pipeline.run is called without outdir.

processed_subdir

"processed"

Subdirectory for processed EDI files.

plots_subdir

"plots"

Subdirectory for QC and diagnostic figures.

on_step_error

"warn"

Step failure policy: "raise", "warn", or "skip".

save_intermediate

False

Save EDI snapshots after each step.

show_progress

True

Show progress during pipeline execution.

progress_style

"bar"

Progress style: "bar", "log", or "silent".

plot_dpi

150

DPI for saved figures.

plot_fmt

"png"

Figure format, for example "png", "pdf", or "svg".

report_formats

("html", "txt")

Pipeline report formats.

Use stricter error behavior when validating a new workflow:

1from pycsamt.api import PYCSAMT_PIPE
2
3with PYCSAMT_PIPE.context(on_step_error="raise"):
4    result = pipe.run(sites, outdir="results/debug")

Plot style configuration#

Plot style configuration keeps figures consistent across notebooks, tutorials, reports, and agent-generated outputs.

Use named style presets where available:

1from pycsamt.api import use_style
2
3use_style("publication")

Override specific style attributes with double-underscore paths:

 1from pycsamt.api import configure_style
 2
 3configure_style(
 4    multiline__mode="gradient",
 5    multiline__base_color="teal",
 6    multiline__lw=1.8,
 7    mt__xy__color="#003f88",
 8    mt__yx__color="#d62828",
 9    correction__before__color="#808080",
10    correction__after__color="#005f73",
11)

Temporary style:

1from pycsamt.api import PYCSAMT_STYLE
2
3with PYCSAMT_STYLE.context("dark"):
4    fig = plot_function(...)

The exact style sections are documented in the API reference, but the most common sections are:

  • multiline for multi-station and multi-profile lines;

  • mt for MT component colors;

  • rose for rose diagrams;

  • correction for before/after correction figures;

  • raw for diagnostic raw-data traces.

AI backend configuration#

AI inversion and model-zoo workflows can use PyTorch or TensorFlow. Neither backend is required for the base package. Backend packages are loaded lazily when AI functionality is used.

Inspect available backends:

1from pycsamt.backends import get_backend, list_backends
2
3print(list_backends())
4print(get_backend())

Select a backend for this session:

1from pycsamt.backends import set_backend
2
3set_backend("torch")
4# or
5set_backend("tensorflow")
6# or
7set_backend("auto")

Persist a backend choice to ~/.pycsamt/config.json:

1from pycsamt.backends import set_backend
2
3set_backend("torch", persist=True)

Environment variable:

1export PYCSAMT_AI_BACKEND=torch

Backend resolution order:

  1. Explicit set_backend(...) call in the current Python session.

  2. PYCSAMT_AI_BACKEND environment variable.

  3. ~/.pycsamt/config.json key "ai_backend".

  4. Auto-detection from installed frameworks.

Agent and LLM configuration#

pyCSAMT agents can run deterministic scientific steps without an LLM when the agent supports fallback behavior. LLM configuration is only needed for natural-language interpretation, report wording, and assistant-style workflow guidance.

Basic setup:

1from pycsamt.agents import configure_agents
2
3configure_agents(
4    provider="claude",
5    api_key="sk-ant-...",
6    model="claude-sonnet-4-6",
7)

Configure with environment variables instead of hard-coding keys:

1export ANTHROPIC_API_KEY="sk-ant-..."
2export OPENAI_API_KEY="sk-..."
3export GOOGLE_API_KEY="AIza..."

Then select the provider in Python:

1from pycsamt.agents import configure_agents
2
3configure_agents(provider="openai")

Provider environment variables:

Provider

Variables checked

"claude"

ANTHROPIC_API_KEY, PYCSAMT_CLAUDE_API_KEY

"openai"

OPENAI_API_KEY, PYCSAMT_OPENAI_API_KEY

"gemini"

GOOGLE_API_KEY, GOOGLE_GENERATIVEAI_API_KEY, PYCSAMT_GEMINI_API_KEY

Use a session budget before experimenting with LLM-assisted agents:

1from pycsamt.agents import AGENT_CONFIG
2
3AGENT_CONFIG.set_budget(usd=2.0)
4print(AGENT_CONFIG.remaining_usd)

Switch providers:

 1from pycsamt.agents import AGENT_CONFIG
 2
 3AGENT_CONFIG.set_key("claude", "sk-ant-...")
 4AGENT_CONFIG.set_key("openai", "sk-...")
 5
 6AGENT_CONFIG.switch("claude")
 7# run Claude-assisted workflow
 8
 9AGENT_CONFIG.switch("openai")
10# run OpenAI-assisted workflow

Temporary LLM override:

1from pycsamt.agents import AGENT_CONFIG, DataQCAgent
2
3with AGENT_CONFIG.using(provider="gemini", api_key="AIza..."):
4    result = DataQCAgent().execute({"path": "data/willy/edis"})
5
6# Original agent settings are restored here.

For the full agent configuration guide, see Agent And LLM Configuration.

Configuration files#

Most day-to-day configuration is done in Python or environment variables. The AI backend layer can also persist the selected backend to:

1~/.pycsamt/config.json

Example content:

1{
2  "ai_backend": "torch"
3}

Pipeline workflows may also be stored as YAML or JSON pipeline configuration files. Those files describe processing steps, not global runtime settings. See the pipeline configuration guide for details: Pipeline Configuration Files.

Logging behavior#

CLI verbosity is controlled by PYCSAMT_CLI and the PYCSAMT_VERBOSE environment variable. Python logging is initialized by the package at import time so command-line and library workflows have a consistent baseline.

For most users:

1export PYCSAMT_VERBOSE=1

For Python scripts:

1from pycsamt.api import configure_cli
2
3configure_cli(log__level=2)

Use log__level=2 for debugging configuration and parsing problems. Use log__level=0 for quiet batch runs.

Reset configuration#

Reset helpers restore package defaults for the current Python session.

1from pycsamt.api import reset_api_view, reset_cli, reset_pipe, reset_style
2from pycsamt.agents import reset_agents
3
4reset_api_view()
5reset_cli()
6reset_pipe()
7reset_style()
8reset_agents()

Backend persistence is separate. If you used set_backend(..., persist=True), edit or remove ~/.pycsamt/config.json to clear the saved backend choice.

Common mistakes#

Problem

Fix

Agent does not produce LLM interpretation

Configure a provider and key, or accept deterministic no-LLM fallback.

AI inversion says no backend is installed

Install PyTorch or TensorFlow, then run set_backend("auto").

Pipeline writes to an unexpected directory

Pass outdir=... to Pipeline.run or configure output_root.

CLI ignores environment changes

Set environment variables before importing pyCSAMT or call PYCSAMT_CLI.load_env().

Plots are inconsistent across notebooks

Configure style once at the start of the session.

Raw pandas objects are needed

Use configure_api_view(backend="pandas").

In short#

For a first project, configure output directories, progress behavior, and plot style. Add AI backend selection only when using AI inversion. Add LLM agent configuration only when natural-language interpretation or assistant guidance is required.