"""fetch_inputs.py — fetch the public inputs of our check of S0 News's research note 008 and compare them with the copies we used on 15 November 2026. Fact-Checked Science. Python 3.10 or later, standard library only. Usage: python3 -I fetch_inputs.py Fetches the seven inputs by URL under a plain client name into the folder, then checks each one's SHA-256 against ours. Then run the analysis scripts with the same folder, e.g. python3 -I 01_reproduce.py . python3 -I fetch_inputs.py --period-hashes Prints the per-year hashes of the values in the folder's inputs (how input_period_hashes.json was made). Most of these files are updated in place every month (BAS's ASL index, SILSO's sunspot number, NOAA's AAO, the station SAM index), so a later copy will usually differ in its SHA-256. When it does, this script compares the values for the months we used, year by year, against input_period_hashes.json (kept next to this script): - if every year we used matches, the inputs we used are unchanged and our outputs should reproduce; - if some years differ, the provider has revised those values. Re-run the scripts and compare with our hosted outputs; differences in the numbers then come from the revision, not from the scripts. The scripts use only the months listed under "period" below, so months added after our freeze don't matter. We host none of these files: they belong to their providers (see the page for their terms and credits).""" import hashlib import json import os import sys import urllib.request UA = "factchecked-research/1.0" INPUTS = { "asli_calculation_latest.csv": { "url": "https://files.bas.ac.uk/twins/asli/asli_calculation_latest.csv", "sha256": "876642028a80437de8547ab3a207b7d8b927ec445ee6fe384c9f8e8a08838535", "period": ("1959-01", "2026-07"), "what": "BAS ASL index v3 (ERA5)"}, "ASL-index-Version2-Monthly-ERA-Interim_Hosking2016.txt": { "url": "https://legacy.bas.ac.uk/data/absl/ASL-index-Version2-Monthly-ERA-Interim_Hosking2016.txt", "sha256": "b6f210aee5dbded60f87a8cc37cc1bce98b41af1e099b90971a5dc9a6b67696e", "period": ("1979-01", "2018-03"), "what": "BAS ASL index v2 (ERA-Interim)"}, "SN_m_tot_V2.0.csv": { "url": "https://www.sidc.be/SILSO/DATA/SN_m_tot_V2.0.csv", "sha256": "1cf8a1f6f28ff9ee479783d72fa323eb70a824056450ccf60d0152fa28abd72f", "period": ("1749-01", "2026-10"), "what": "WDC-SILSO monthly total sunspot number V2.0"}, "monthly.aao.index.b79.current.ascii": { "url": "https://www.cpc.ncep.noaa.gov/products/precip/CWlink/daily_ao_index/aao/monthly.aao.index.b79.current.ascii", "sha256": "a708f8a88906be31ab2b75963d5b8d676511ad3fa156cbc4eccf7e4050240856", "period": ("1979-01", "2026-10"), "what": "NOAA CPC monthly AAO index"}, "newsam.1957.2007.txt": { "url": "https://legacy.bas.ac.uk/met/gjma/newsam.1957.2007.txt", "sha256": "7158a4b1b70acbd26740ce394f1fbd2a560633cfa1e93929c6c90d5a19275a92", "period": ("1957-01", "2026-09"), "what": "Marshall's station-based SAM index (BAS)"}, "workbook.csv": { "url": "https://docs.google.com/spreadsheets/d/1TEEzIqyDiJOKbzoXSxg4_Yy5dFZt5gMh8V9U6CdZKKc/export?format=csv", "sha256": "7445d980d9683e68107ba27dd8e132330649d0bbcd9e6322c714bb000f5968c9", "period": ("1979-01", "2016-11"), "what": "the 2017 manuscript's workbook (S0 News; Google Sheets CSV export)"}, "magnetic-field-guide-numbers.json": { "url": "https://factchecked.science/magnetic-field-guide/magnetic-field-guide-numbers.json", "sha256": "cb6cfee622898a281e64b8e725dae1240d36f8d3b3bbafbeeb5fc92f101974fd", "period": None, "what": "our guide to Earth's magnetic field: IGRF-14 dipole moments"}, } def ym(s): y, m = s.split("-")[:2] return int(y) * 12 + int(m) - 1 def values(name, path): """Month -> canonical text of the values our scripts use (rounded, so a change of format alone doesn't count).""" out = {} with open(path, encoding="utf-8-sig") as f: lines = f.read().splitlines() if name == "asli_calculation_latest.csv": head = None for line in lines: if line.startswith("#") or not line.strip(): continue p = line.split(",") if head is None: head = p i_sp = head.index("sector_pressure (hPa) [a]") i_rc = head.index("relative_central_pressure (hPa) [b]") i_ac = head.index("actual_central_pressure (hPa)") continue out[ym(p[0])] = f"{float(p[i_sp]):.3f},{float(p[i_rc]):.3f},{float(p[i_ac]):.3f}" elif name == "ASL-index-Version2-Monthly-ERA-Interim_Hosking2016.txt": for line in lines: p = line.split() if len(p) >= 3 and p[0].isdigit() and p[1].isdigit(): out[int(p[0]) * 12 + int(p[1]) - 1] = f"{float(p[2]):.4f}" elif name == "SN_m_tot_V2.0.csv": for line in lines: p = [x.strip() for x in line.split(";")] if len(p) >= 4 and p[0].isdigit(): out[int(p[0]) * 12 + int(p[1]) - 1] = f"{float(p[3]):.1f}" elif name == "monthly.aao.index.b79.current.ascii": for line in lines: p = line.split() if len(p) == 3 and p[0].isdigit(): out[int(p[0]) * 12 + int(p[1]) - 1] = f"{float(p[2]):.3f}" elif name == "newsam.1957.2007.txt": for line in lines: p = line.split() if p and len(p[0]) == 4 and p[0].isdigit(): for k, v in enumerate(p[1:13]): out[int(p[0]) * 12 + k] = f"{float(v):.2f}" elif name == "workbook.csv": for line in lines: p = line.split(",") if len(p) >= 3 and len(p[0]) == 7 and p[0][4] == "-" and p[0][:4].isdigit(): out[ym(p[0])] = f"{float(p[1]):.4f},{float(p[2]):.1f}" return out def period_hashes(name, path): if name == "magnetic-field-guide-numbers.json": d = json.load(open(path, encoding="utf-8")) ser = {r["epoch"]: r["M_1e22_Am2"] for r in d["field_decline"]["dipole_series"] if not r["forecast"]} txt = ";".join(f"{e:.0f}:{ser[e]:.4f}" for e in (1960.0, 1980.0, 1990.0, 2025.0)) return {"dipole": hashlib.sha256(txt.encode()).hexdigest()[:16]} v = values(name, path) a, b = (ym(x) for x in INPUTS[name]["period"]) years = {} for m in range(a, b + 1): years.setdefault(m // 12, []).append(f"{m // 12:04d}-{m % 12 + 1:02d}={v.get(m, 'missing')}") return {str(y): hashlib.sha256(";".join(rows).encode()).hexdigest()[:16] for y, rows in sorted(years.items())} def fetch(url, dest): req = urllib.request.Request(url, headers={"User-Agent": UA}) with urllib.request.urlopen(req, timeout=120) as r, open(dest, "wb") as f: f.write(r.read()) def main(): here = os.path.dirname(os.path.abspath(__file__)) if len(sys.argv) == 3 and sys.argv[1] == "--period-hashes": folder = sys.argv[2] print(json.dumps({n: period_hashes(n, os.path.join(folder, n)) for n in INPUTS}, indent=1)) return if len(sys.argv) != 2: raise SystemExit(__doc__) folder = sys.argv[1] os.makedirs(folder, exist_ok=True) ours = json.load(open(os.path.join(here, "input_period_hashes.json"), encoding="utf-8")) for name, info in INPUTS.items(): dest = os.path.join(folder, name) try: fetch(info["url"], dest) except Exception as e: # report and go on; never retry another way print(f"FAILED {name}: {e}") continue h = hashlib.sha256(open(dest, "rb").read()).hexdigest() if h == info["sha256"]: print(f"same {name}: identical to the copy we used ({info['what']})") continue try: now = period_hashes(name, dest) except Exception as e: print(f"CHANGED {name}: SHA-256 differs and the file no longer parses ({e}); check its format") continue diff = [k for k, v in ours[name].items() if now.get(k) != v] if not diff: print(f"updated {name}: SHA-256 differs, but every value we used is unchanged ({info['what']})") else: print(f"REVISED {name}: values we used differ in {', '.join(diff)}; re-run and compare with our hosted outputs") if __name__ == "__main__": main()