#!/usr/bin/env python3 """Base rate: how often does a place and a moment fall "before an earthquake" by chance? Our analysis for /preseismic-geomagnetic-network/. It uses no number from Wen et al. (2026), whose text could not be read. Every parameter below is illustrative, taken from the open literature on satellite magnetic anomalies, and was fixed before the first run. RULES (fixed before running) Catalogue USGS ComCat, FDSN event service, type earthquake, M >= 5.0, 2014-2025. Shallow means depth < 50 km (De Santis et al. 2019). Versions all the catalogue as it stands light De Santis et al.'s stated rule: remove M <= Mms - 1 within 10 km and 10 days of a larger mainshock gk Gardner and Knopoff (1974) windows, foreshocks and aftershocks, largest events first Magnitudes M >= 5.5, 6.0 and 7.0. Radius Dobrovolsky et al. (1979): R = 10^(0.43 M) km, each event's own magnitude. Lead time 10, 30, 60 and 90 days. A day t0 counts if a qualifying event falls in t0 + 1 ... t0 + T days. t0 runs over the record, stopping T days short of its end. Places (a) an equal-area Fibonacci set of points between 50S and 50N, geographic; (b) named boxes, chosen before running: Japan, Himalaya, Sumatra, Peru-Chile, Anatolia, California, and two quiet comparisons, interior Australia and West Africa; (c) passes: meridians every 5 degrees, 50S to 50N, sampled every degree of latitude, as a stand-in for a near-polar satellite pass. We report the share of pass-days with at least one point inside a qualifying zone, and the mean share of a pass inside. Run: python3 -I base_rate.py Pure Python on purpose, so it runs with -I. """ import csv import json import math import sys from datetime import date, datetime from pathlib import Path RE = 6371.0 BOXES = { "Japan": (30, 46, 129, 146), "Himalaya": (26, 32, 78, 90), "Sumatra": (-8, 6, 94, 106), "Peru-Chile": (-45, -5, -82, -68), "Anatolia": (36, 42, 26, 45), "California": (32, 42, -125, -114), "Interior Australia (quiet)": (-30, -20, 120, 140), "West Africa (quiet)": (5, 15, -10, 10), } MAGS = [5.5, 6.0, 7.0] LEADS = [10, 30, 60, 90] START, END = date(2014, 1, 1), date(2026, 1, 1) NDAYS = (END - START).days def unit(lat, lon): a, b = math.radians(lat), math.radians(lon) return (math.cos(a) * math.cos(b), math.cos(a) * math.sin(b), math.sin(a)) def dobrovolsky(m): return 10 ** (0.43 * m) def load(folder): rows = [] seen = set() for p in sorted(Path(folder).glob("usgs-m5-*.csv")): with open(p, encoding="utf-8", newline="") as f: for r in csv.DictReader(f): if r["type"] != "earthquake" or r["id"] in seen: continue seen.add(r["id"]) t = datetime.strptime(r["time"][:19], "%Y-%m-%dT%H:%M:%S") rows.append( { "id": r["id"], "t": t, "day": (t.date() - START).days, "lat": float(r["latitude"]), "lon": float(r["longitude"]), "dep": float(r["depth"] or 0), "m": float(r["mag"]), } ) rows.sort(key=lambda e: e["t"]) return rows def dist_km(a, b): ua, ub = unit(a["lat"], a["lon"]), unit(b["lat"], b["lon"]) c = min(1.0, max(-1.0, ua[0] * ub[0] + ua[1] * ub[1] + ua[2] * ub[2])) return RE * math.acos(c) def decluster(rows, rule): """Largest events first. Returns the kept events, in time order. Rules: light, gk.""" order = sorted(range(len(rows)), key=lambda i: -rows[i]["m"]) removed = [False] * len(rows) times = [e["t"] for e in rows] for i in order: if removed[i]: continue e = rows[i] if rule == "light": dt, dkm, dm = 10.0, 10.0, 1.0 else: # gk dkm = 10 ** (0.1238 * e["m"] + 0.983) dt = 10 ** (0.032 * e["m"] + 2.7389) if e["m"] >= 6.5 else 10 ** (0.5409 * e["m"] - 0.547) dm = 0.0 # Scan outward in time from i; events are time-sorted. for step in (1, -1): j = i + step while 0 <= j < len(rows): gap = abs((times[j] - times[i]).total_seconds()) / 86400.0 if gap > dt: break if not removed[j] and rows[j]["m"] <= e["m"] - dm and j != i: # An equal-magnitude later neighbour counts as dependent only under gk. if dist_km(e, rows[j]) <= dkm: removed[j] = True j += step return [e for e, r in zip(rows, removed) if not r] def fibonacci_points(n, latmax=50.0): pts = [] golden = math.pi * (3 - math.sqrt(5)) for k in range(n): z = 1 - 2 * (k + 0.5) / n lat = math.degrees(math.asin(z)) if abs(lat) > latmax: continue lon = math.degrees((k * golden) % (2 * math.pi)) - 180 pts.append((lat, lon, 1.0)) return pts def box_points(box, step=1.0): la0, la1, lo0, lo1 = box pts = [] la = la0 + step / 2 while la < la1: lo = lo0 + step / 2 while lo < lo1: pts.append((la, lo, math.cos(math.radians(la)))) lo += step la += step return pts def track_points(): tracks = [] for lon in range(-180, 180, 5): tracks.append([(float(la), float(lon), math.cos(math.radians(la))) for la in range(-50, 51)]) return tracks def hits_by_point(pts, events): """For each point, the indices of events whose zone contains it.""" uv = [unit(p[0], p[1]) for p in pts] out = [[] for _ in pts] for idx, e in enumerate(events): ex, ey, ez = unit(e["lat"], e["lon"]) cr = math.cos(min(dobrovolsky(e["m"]) / RE, math.pi)) for k, (x, y, z) in enumerate(uv): if x * ex + y * ey + z * ez >= cr: out[k].append(idx) return out def covered_days(days, lead, last): """Number of integer days t0 in [0, last] with some d in days and 1 <= d - t0 <= lead.""" total, end = 0, -1 for d in sorted(days): a, b = max(d - lead, 0), min(d - 1, last) if b < a: continue if a <= end: a = end + 1 if b >= a: total += b - a + 1 end = b return total def share(pts, lists, events, mmin, lead): last = NDAYS - lead - 1 num = den = 0.0 for p, lst in zip(pts, lists): days = [events[i]["day"] for i in lst if events[i]["m"] >= mmin] num += p[2] * covered_days(days, lead, last) den += p[2] * (last + 1) return num / den def run_coverage(events): res = {"n_events": {str(m): sum(e["m"] >= m for e in events) for m in MAGS}} glob = fibonacci_points(12000) gl = hits_by_point(glob, events) res["n_points_global"] = len(glob) res["global"] = {f"M{m}": {str(T): round(100 * share(glob, gl, events, m, T), 1) for T in LEADS} for m in MAGS} res["boxes"] = {} for name, box in BOXES.items(): pts = box_points(box) ls = hits_by_point(pts, events) res["boxes"][name] = {f"M{m}": {str(T): round(100 * share(pts, ls, events, m, T), 1) for T in LEADS} for m in MAGS} # Passes. tracks = track_points() flat = [p for tr in tracks for p in tr] fl = hits_by_point(flat, events) per = len(tracks[0]) res["passes"] = {} for m in MAGS: res["passes"][f"M{m}"] = {} for T in LEADS: last = NDAYS - T - 1 anyshare = [] for t in range(len(tracks)): seg = fl[t * per : (t + 1) * per] idx = set(i for lst in seg for i in lst) days = [events[i]["day"] for i in idx if events[i]["m"] >= m] anyshare.append(covered_days(days, T, last) / (last + 1)) inside = share(flat, fl, events, m, T) res["passes"][f"M{m}"][str(T)] = { "share_of_pass_days_touching_a_zone_pct": round(100 * sum(anyshare) / len(anyshare), 1), "mean_share_of_pass_inside_a_zone_pct": round(100 * inside, 1), } return res def main(): folder, outdir = sys.argv[1], Path(sys.argv[2]) outdir.mkdir(parents=True, exist_ok=True) rows = load(folder) shallow = lambda es: [e for e in es if e["dep"] < 50 and e["m"] >= 5.5] result = { "note": "Our analysis. No parameter comes from Wen et al. (2026). See the docstring for the rules.", "catalogue_rows_m5": len(rows), "first": str(rows[0]["t"]), "last": str(rows[-1]["t"]), } print("catalogue", len(rows), rows[0]["t"], rows[-1]["t"], flush=True) versions = {"all": rows, "light": decluster(rows, "light"), "gk": decluster(rows, "gk")} for name, ev in versions.items(): sel = shallow(ev) print("version", name, "kept", len(ev), "shallow M5.5+", len(sel), flush=True) result[name] = run_coverage(sel) with open(outdir / "base_rate.json", "w", encoding="utf-8", newline="\n") as f: json.dump(result, f, ensure_ascii=False, indent=1) print("written", outdir / "base_rate.json", flush=True) if __name__ == "__main__": main()