"""carrington_temperature.py FOLDER -- RULES_carrington_temperature.txt: did the 1859 Carrington event bring "a temperature spike of about 7 degrees C lasting a few months"? Fetches HadCRUT5's global monthly summary series (Met Office Hadley Centre and the Climatic Research Unit, Open Government Licence v3.0) under a plain client name, checks it against the copy we used (SHA-256 below), and compares September 1859 - February 1860 with the 36 months before. Standard library only. Usage: python3 -I carrington_temperature.py (the output should match carrington_temperature.txt) """ import csv import hashlib import io import statistics import sys import urllib.request from pathlib import Path URL = ("https://www.metoffice.gov.uk/hadobs/hadcrut5/data/HadCRUT.5.0.2.0/analysis/diagnostics/" "HadCRUT.5.0.2.0.analysis.summary_series.global.monthly.csv") OUR_SHA256 = "75673adde85c4a3a52c8bd987d4ff643c6fc4fc3174a6168ace10dc1b5a70a99" # fetched 2026-11-13 16:51 UTC def months(start, n): y, m = map(int, start.split("-")) out = [] for _ in range(n): out.append(f"{y:04d}-{m:02d}") m += 1 if m == 13: y, m = y + 1, 1 return out def main(folder: Path) -> None: folder.mkdir(parents=True, exist_ok=True) req = urllib.request.Request(URL, headers={"User-Agent": "factchecked-research/1.0"}) with urllib.request.urlopen(req, timeout=120) as r: data = r.read() (folder / URL.rsplit("/", 1)[1]).write_bytes(data) sha = hashlib.sha256(data).hexdigest() print(f"fetched {len(data):,} bytes; SHA-256 {sha}") print("same file as ours" if sha == OUR_SHA256 else "DIFFERENT from the copy we used (HadCRUT5 is revised now and then)") rows = {} for r in csv.DictReader(io.StringIO(data.decode("utf-8"))): rows[r["Time"]] = (float(r["Anomaly (deg C)"]), float(r["Lower confidence limit (2.5%)"]), float(r["Upper confidence limit (97.5%)"])) base = [rows[k][0] for k in months("1856-09", 36)] mu, sd = statistics.mean(base), statistics.stdev(base) print(f"baseline Sep 1856-Aug 1859: mean {mu:+.3f} C, sd {sd:.3f} C, n={len(base)}") diffs = [] for k in months("1859-09", 6): a, lo, hi = rows[k] diffs.append(a - mu) print(f"{k}: anomaly {a:+.3f} C (95% {lo:+.3f} to {hi:+.3f}); minus baseline {a - mu:+.3f} C") mx = max(diffs) decision = "contradicted" if mx < 1.0 else ("holds" if mx >= 5.0 else "unsupported") print(f"largest window month above baseline: {mx:+.3f} C -> decision: {decision}") if __name__ == "__main__": if len(sys.argv) != 2: sys.exit(__doc__) main(Path(sys.argv[1]))