#!/usr/bin/env python3 """Repeat the numbers of factchecked.science's page on NOAA and NASA's 2026 ozone report (ozone-hole-2026-season). Usage: python3 -I ozone_pipeline.py With the other files of the page beside it (the scripts, the RULES_*.txt files, ozone-inputs.json and our outputs), it 1. downloads the 122 input files listed in ozone-inputs.json (NASA Ozone Watch, NOAA GML and CAMS; about 7 MB) into /downloads//, as a plain client ("factchecked-research/1.0"), and checks each against the SHA-256 of the copy we used on 2026-11-13. NASA's 2026 files and CAMS's files grow every day, so those will differ; 2. runs every step: rankings.py, trend_test.py, release_checks.py, exploratory_checks.py, cams_crosscheck.py, cams_t50_months.py, ozone_records.py (from the site's page of October 24) and charts.py, writing to /out/; 3. compares the numbers with ours (the JSON files beside this script) and lists every difference. Standard library only. Nothing downloaded is executed; the scripts read the files as data. """ import hashlib import json import subprocess import sys import urllib.request from pathlib import Path HERE = Path(__file__).resolve().parent UA = "factchecked-research/1.0" def fetch(work): spec = json.loads((HERE / "ozone-inputs.json").read_text(encoding="utf-8"))["inputs"] differ = [] for i, f in enumerate(spec, 1): dest = work / "downloads" / f["folder"] dest.mkdir(parents=True, exist_ok=True) req = urllib.request.Request(f["url"], headers={"User-Agent": UA}) with urllib.request.urlopen(req, timeout=180) as r: data = r.read() (dest / f["file"]).write_bytes(data) sha = hashlib.sha256(data).hexdigest() if sha != f["sha256"]: differ.append(f["folder"]) print(f"[{i:3d}/{len(spec)}] {f['folder']:<28} {len(data):>9} bytes " f"{'same as ours' if sha == f['sha256'] else 'DIFFERS from our copy of 2026-11-13'}") print(f"\n{len(spec) - len(differ)} of {len(spec)} files match our copies; differ: {', '.join(differ) or 'none'}\n") def run(work): (work / "out").mkdir(exist_ok=True) steps = ["rankings.py", "trend_test.py", "release_checks.py", "exploratory_checks.py", "cams_crosscheck.py", "cams_t50_months.py", "charts.py"] for s in steps: r = subprocess.run([sys.executable, "-I", str(HERE / s), str(work)], capture_output=True, text=True, encoding="utf-8") (work / "out" / f"{s[:-3]}_stdout.txt").write_text(r.stdout + r.stderr, encoding="utf-8", newline="\n") print(f"{s:<24} {'ok' if r.returncode == 0 else 'FAILED, see out/' + s[:-3] + '_stdout.txt'}") d = work / "downloads" args = [next((d / "nasa_area_2026").glob("*.txt")), next((d / "nasa_min_2026").glob("*.txt")), next((d / "nasa_omd_2026").glob("*.txt")), next((d / "cams_csv_sh_area").glob("*.csv"))] r = subprocess.run([sys.executable, "-I", str(HERE / "ozone_records.py")] + [str(a) for a in args], capture_output=True, text=True, encoding="utf-8") (work / "out" / "record-days.txt").write_text(r.stdout + r.stderr, encoding="utf-8", newline="\n") print(f"{'ozone_records.py':<24} {'ok' if r.returncode == 0 else 'FAILED'}") def flat(o, pre=""): if isinstance(o, dict): for k, v in o.items(): if k in ("rules_sha256", "files_read"): continue yield from flat(v, f"{pre}.{k}" if pre else k) elif isinstance(o, list): for i, v in enumerate(o): yield from flat(v, f"{pre}[{i}]") else: yield pre, o def compare(work): total = 0 for name in ("rankings.json", "trend_test.json", "release_checks.json", "exploratory_checks.json", "chart-numbers.json"): ours = dict(flat(json.loads((HERE / name).read_text(encoding="utf-8")))) new = dict(flat(json.loads((work / "out" / name).read_text(encoding="utf-8")))) diff = [k for k in sorted(set(ours) | set(new)) if not (isinstance(ours.get(k), float) and isinstance(new.get(k), float) and abs(ours[k] - new[k]) <= 1e-9 * max(1.0, abs(ours[k]))) and ours.get(k) != new.get(k)] total += len(diff) print(f"{name:<24} {len(ours)} numbers, {len(diff)} differ" + ("" if not diff else ": " + ", ".join(diff[:12]) + (" …" if len(diff) > 12 else ""))) print("\nIdentical to our run." if total == 0 else "\nDifferences are expected where NASA's or CAMS's newer files " "add days (records, the last date); the seasonal ranks and the trend tests should not change.") def main(): if len(sys.argv) != 2: sys.exit(__doc__) work = Path(sys.argv[1]).resolve() work.mkdir(parents=True, exist_ok=True) fetch(work) run(work) compare(work) if __name__ == "__main__": main()