Upload essd_scripts/run_paired_diagnostics_all.py
Browse files
essd_scripts/run_paired_diagnostics_all.py
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Run paired snippet/stream diagnostics for all released picker outputs."""
|
| 3 |
+
|
| 4 |
+
from __future__ import annotations
|
| 5 |
+
|
| 6 |
+
import argparse
|
| 7 |
+
import csv
|
| 8 |
+
import json
|
| 9 |
+
import subprocess
|
| 10 |
+
import sys
|
| 11 |
+
from pathlib import Path
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
PICKERS = [
|
| 15 |
+
("lppnm", "data/picks/lppnm.phase.jsonl", "eval_picks/eval_lppnm"),
|
| 16 |
+
("phasenet", "data/picks/phasenet.pick.jsonl", "eval_picks/eval_phasenet"),
|
| 17 |
+
("pnsn_v1", "data/picks/pnsn_v1.phase.jsonl", "eval_picks/eval_pnsn_v1"),
|
| 18 |
+
("pnsn_v3_5120", "data/picks/pnsn_v3_5120.phase.jsonl", "eval_picks/eval_pnsn_v3_5120"),
|
| 19 |
+
("pnsn_v3_diff", "data/picks/pnsn.v3.diff.phase.jsonl", "eval_picks/eval_pnsn_v3_diff"),
|
| 20 |
+
("seismicxm", "data/picks/seismicxm.01.phase.jsonl", "eval_picks/eval_seismicxm"),
|
| 21 |
+
("seist", "data/picks/seist.phase.jsonl", "eval_picks/eval_seist"),
|
| 22 |
+
("skynet", "data/picks/skynet.phase.jsonl", "eval_picks/eval_skynet"),
|
| 23 |
+
("ustc_sc", "data/picks/ustc_sc.phase.jsonl", "eval_picks/eval_ustc_sc"),
|
| 24 |
+
]
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def main() -> None:
|
| 28 |
+
parser = argparse.ArgumentParser(description=__doc__)
|
| 29 |
+
root = Path(__file__).resolve().parents[1]
|
| 30 |
+
parser.add_argument("--root", type=Path, default=root)
|
| 31 |
+
parser.add_argument("--outdir", type=Path, default=root / "paired_eval_all")
|
| 32 |
+
parser.add_argument("--label-json", type=Path, default=root / "data/label/annotations_for_continuous_hdf5.json")
|
| 33 |
+
parser.add_argument("--half-width-s", nargs="+", default=["5", "10", "30", "60"])
|
| 34 |
+
parser.add_argument("--only", nargs="*", default=None, help="Optional picker names to run.")
|
| 35 |
+
args = parser.parse_args()
|
| 36 |
+
|
| 37 |
+
args.outdir.mkdir(parents=True, exist_ok=True)
|
| 38 |
+
script = args.root / "essd_scripts/paired_snippet_stream_diagnostic.py"
|
| 39 |
+
|
| 40 |
+
selected = PICKERS
|
| 41 |
+
if args.only:
|
| 42 |
+
keep = set(args.only)
|
| 43 |
+
selected = [item for item in PICKERS if item[0] in keep]
|
| 44 |
+
missing = sorted(keep - {item[0] for item in selected})
|
| 45 |
+
if missing:
|
| 46 |
+
raise SystemExit(f"unknown picker name(s): {', '.join(missing)}")
|
| 47 |
+
|
| 48 |
+
for name, auto_jsonl, eval_dir in selected:
|
| 49 |
+
out = args.outdir / name
|
| 50 |
+
cmd = [
|
| 51 |
+
sys.executable,
|
| 52 |
+
str(script),
|
| 53 |
+
"--auto-jsonl",
|
| 54 |
+
str(args.root / auto_jsonl),
|
| 55 |
+
"--matches-jsonl",
|
| 56 |
+
str(args.root / eval_dir / "matches.jsonl"),
|
| 57 |
+
"--summary-json",
|
| 58 |
+
str(args.root / eval_dir / "summary.json"),
|
| 59 |
+
"--label-json",
|
| 60 |
+
str(args.label_json),
|
| 61 |
+
"--outdir",
|
| 62 |
+
str(out),
|
| 63 |
+
"--half-width-s",
|
| 64 |
+
*args.half_width_s,
|
| 65 |
+
]
|
| 66 |
+
print(f"[RUN] {name}", flush=True)
|
| 67 |
+
subprocess.run(cmd, check=True)
|
| 68 |
+
|
| 69 |
+
combined = []
|
| 70 |
+
for name, _auto_jsonl, _eval_dir in selected:
|
| 71 |
+
p = args.outdir / name / "paired_snippet_stream_summary.json"
|
| 72 |
+
data = json.loads(p.read_text(encoding="utf-8"))
|
| 73 |
+
for row in data["rows"]:
|
| 74 |
+
combined.append({"picker": name, **row})
|
| 75 |
+
|
| 76 |
+
json_path = args.outdir / "combined_paired_snippet_stream_summary.json"
|
| 77 |
+
json_path.write_text(json.dumps(combined, indent=2), encoding="utf-8")
|
| 78 |
+
|
| 79 |
+
fields = [
|
| 80 |
+
"picker",
|
| 81 |
+
"mode",
|
| 82 |
+
"n_label_with_waveform",
|
| 83 |
+
"n_tp_with_waveform",
|
| 84 |
+
"coverage_aware_recall",
|
| 85 |
+
"automatic_picks",
|
| 86 |
+
"automatic_picks_per_day",
|
| 87 |
+
"catalog_relative_explained_fraction",
|
| 88 |
+
"automatic_picks_per_covered_tp",
|
| 89 |
+
"selected_window_seconds_station_time",
|
| 90 |
+
"n_residual",
|
| 91 |
+
"abs_p95_s",
|
| 92 |
+
"tail_gt_1p5_fraction",
|
| 93 |
+
]
|
| 94 |
+
tsv_path = args.outdir / "combined_paired_snippet_stream_summary.tsv"
|
| 95 |
+
with tsv_path.open("w", encoding="utf-8", newline="") as f:
|
| 96 |
+
writer = csv.DictWriter(f, fieldnames=fields, delimiter="\t", extrasaction="ignore")
|
| 97 |
+
writer.writeheader()
|
| 98 |
+
writer.writerows(combined)
|
| 99 |
+
|
| 100 |
+
print(f"[OUT] {json_path}")
|
| 101 |
+
print(f"[OUT] {tsv_path}")
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
if __name__ == "__main__":
|
| 105 |
+
main()
|