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 |
|
Whether dataframe-like results are returned as pyCSAMT view objects or raw pandas-style objects. |
CLI |
|
Verbosity, color, output format, output directory, cache, and job count for command-line workflows. |
Pipeline |
|
Pipeline output directories, progress style, plot format, report format, and step error policy. |
Style |
|
Plot colors, line styles, rose diagrams, component colors, and publication-style visual defaults. |
AI backend |
|
PyTorch/TensorFlow backend selection for AI inversion and model-zoo workflows. |
Agents |
|
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 |
|---|---|
|
Return pyCSAMT API view wrappers. |
|
Return the raw dataframe-like object. |
callable |
Call |
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 |
|---|---|---|
|
|
Quiet, info, or debug verbosity. |
|
|
Enable colored terminal output. |
|
|
Preferred command output format. |
|
path-like |
Default output directory. |
|
|
Whether existing output may be overwritten. |
|
integer >= 1 |
Number of jobs for CLI workflows that support parallel execution. |
|
|
Enable command cache where supported. |
Environment variables loaded at import time:
Variable |
Meaning |
|---|---|
|
Integer verbosity level, usually |
|
Any non-empty value disables color. |
|
Output format: |
|
Default output directory. |
|
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 |
|---|---|---|
|
|
Root directory used when |
|
|
Subdirectory for processed EDI files. |
|
|
Subdirectory for QC and diagnostic figures. |
|
|
Step failure policy: |
|
|
Save EDI snapshots after each step. |
|
|
Show progress during pipeline execution. |
|
|
Progress style: |
|
|
DPI for saved figures. |
|
|
Figure format, for example |
|
|
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:
multilinefor multi-station and multi-profile lines;mtfor MT component colors;rosefor rose diagrams;correctionfor before/after correction figures;rawfor 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:
Explicit
set_backend(...)call in the current Python session.PYCSAMT_AI_BACKENDenvironment variable.~/.pycsamt/config.jsonkey"ai_backend".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 |
|---|---|
|
|
|
|
|
|
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.
Recommended setups#
Notebook exploration:
1from pycsamt.api import configure_api_view, configure_pipe, use_style
2
3configure_api_view(backend="pycsamt")
4configure_pipe(output_root="notebook_results", show_progress=True)
5use_style("publication")
Batch processing:
1from pycsamt.api import configure_cli, configure_pipe
2
3configure_cli(log__level=1, output__format="json", build__n_jobs=8)
4configure_pipe(
5 output_root="batch_results",
6 progress_style="log",
7 on_step_error="warn",
8 save_intermediate=True,
9)
AI inversion:
1from pycsamt.backends import set_backend
2from pycsamt.agents import AGENT_CONFIG
3
4set_backend("auto")
5AGENT_CONFIG.set_budget(usd=5.0)
6
7# Add provider only when LLM explanation is needed.
8# AGENT_CONFIG.configure(provider="claude")
Report/publication figures:
1from pycsamt.api import configure_pipe, use_style
2
3use_style("publication")
4configure_pipe(plot_dpi=300, plot_fmt="pdf")
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 |
Pipeline writes to an unexpected directory |
Pass |
CLI ignores environment changes |
Set environment variables before importing pyCSAMT or call
|
Plots are inconsistent across notebooks |
Configure style once at the start of the session. |
Raw pandas objects are needed |
Use |
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.