pycsamt.agents.qc#

pycsamt.agents.qc#

DataQCAgent — MT data quality control and frequency editing.

Wraps pycsamt.emtools.qc:

Output figures use PYCSAMT_SECTION so they are consistent with all other pycsamt plots.

Classes

DataQCAgent(*[, api_key, model, ...])

Run data quality control on a MT/AMT dataset.

class pycsamt.agents.qc.DataQCAgent(*, api_key=None, model=None, llm_provider='claude', method='composite', min_frac_ok=0.6, min_snr_med=2.0, max_skew_med=6.0)[source]#

Bases: BaseAgent

Run data quality control on a MT/AMT dataset.

Parameters:
  • api_key (str) – LLM configuration (optional).

  • model (str) – LLM configuration (optional).

  • llm_provider (str) – LLM configuration (optional).

  • method (str) – Confidence scoring method: "composite" (default), "presence", "snr", or "spatial".

  • min_frac_ok (float) – Minimum fraction of OK frequencies for a station to pass (0–1).

  • min_snr_med (float) – Minimum median SNR for a station to pass.

  • max_skew_med (float) – Maximum median |β| skewness for a station to pass.

  • keys (Output data)

  • ----------

  • sites (Sites or path : str) – EDI data to assess.

  • output_dir (str, optional) – Where to save QC figures.

  • period_range ([T_min, T_max], optional) – Restrict QC to this period window.

  • keys

  • ----------------

  • metrics (qc_table pandas DataFrame — per-station)

  • station (flags pandas DataFrame — pass / fail per)

  • scores (confidence_table pandas DataFrame — per-station confidence)

  • confidence (freq_conf_table pandas DataFrame — per-frequency)

  • int (n_flagged)

  • list[str] (flagged_stations)

  • objects (figures dict — matplotlib Figure)

  • set) (figure_paths dict — saved file paths (when output_dir)

Examples

>>> agent  = DataQCAgent()
>>> result = agent.execute({"path": "/data/L22PLT",
...                         "output_dir": "/out/qc"})
>>> result["n_flagged"]
2
>>> result["figures"]["confidence_section"]
<Figure …>
SYSTEM_PROMPT: str = 'You are an expert MT/AMT/CSAMT data quality analyst for pycsamt v2.\nGiven a survey QC summary, write 3–4 sentences that:\n1. State the overall data quality (good / moderate / poor).\n2. Identify specific stations or frequency bands that need attention.\n3. Explain the likely cause (instrument noise, EM interference, near-field).\n4. Recommend the most important next processing step.\nReply in plain English. No bullet points, no markdown headings.\n'#

Override in subclasses to give the LLM its domain expertise.

execute(input_data)[source]#

Run this agent on input_data and return an AgentResult.

Subclasses must implement this method. The contract:

  • Reset self._last_cost = 0.0 at the top.

  • Record wall-clock time with t0 = time.time().

  • Return AgentResult(elapsed_seconds=time.time()-t0, cost_estimate_usd=self._last_cost, ...).

Parameters:

input_data (dict[str, Any])

Return type:

AgentResult