#!/usr/bin/env python3 """Fetch the public inputs of our checks on factchecked.science/may-2024-potential-gradient/ and compare them with ours. Usage: python3 -I fetch_inputs.py FOLDER Standard library only (Python 3.9 or later). Fetches about 38 MB under a plain client name into FOLDER, in the layout the other scripts read (omni/, gfz-kp/, kyoto-dst/, nmdb/, goes/), skips files already there, reads everything as data and runs nothing. For each input it prints whether it matches the copy we used on 2026-11-15. Some inputs are revised or grow (GFZ's Kp file gains a line every three hours; Kyoto's 2024 Dst is provisional; NMDB may revise counts), so for those we compare the rows we used, not the whole file. A difference is reported, not fatal. Not fetched, because only a person in a browser can get it: the paper itself, Tacza et al. (2026), J. Space Weather Space Clim. 16, 36, doi:10.1051/swsc/2026029 (open access, CC BY 4.0), file swsc250080.pdf, 12,166,745 bytes, SHA-256 c9faeb3bf483f0a00cc3d09d75b8becd12f52835efd0b91170b7ba9621551929. The journal's site answered our client with a bot check, so the site's owner downloaded it. The Figure 7 scripts read it from wherever you save it. Terms: OMNI (NASA/GSFC SPDF), public; GFZ Kp, CC BY 4.0; WDC Kyoto Dst, scientific and non-commercial use only, with acknowledgement of the WDC and its observatories (doi:10.17593/14515-74000); NMDB, free for non-commercial use, with acknowledgement of NMDB and the station PIs (see storm_facts.py); GOES-16 SGPS (NOAA NCEI), public domain. """ import hashlib import html import os import re import sys import time import urllib.error import urllib.request UA = "factchecked-research/1.0" NMDB = ("https://www.nmdb.eu/nest/draw_graph.php?formchk=1&{st}&tabchoice=revori&dtype=corr_for_pressure&tresolution={res}" "&force=1&yunits=0&date_choice=bydate&start_day={d0}&start_month=5&start_year=2024&start_hour=0&start_min=0" "&end_day={d1}&end_month=5&end_year=2024&end_hour={h1}&end_min={m1}&output=ascii") GOES = "https://data.ngdc.noaa.gov/platforms/solar-space-observing-satellites/goes/goes16/l2/data/sgps-l2-avg5m/2024/05/" ST8 = "&".join("stations[]=" + s for s in ("MXCO", "NANM", "AATB", "JUNG1", "LMKS", "KIEL2", "OULU", "SOPO")) ST5 = "&".join("stations[]=" + s for s in ("SOPO", "DOMC", "OULU", "KIEL2", "JUNG1")) # (relative path, URL, what to hash, SHA-256 of our copy) INPUTS = [ ("omni/omni2_2024.dat", "https://spdf.gsfc.nasa.gov/pub/data/omni/low_res_omni/omni2_2024.dat", "file", "41f3b5891ce3f1220719d5c1ea808f3014f28a1704557d3363eefb5ee7c249b1"), ("omni/omni_min202405.asc", "https://spdf.gsfc.nasa.gov/pub/data/omni/high_res_omni/monthly_1min/omni_min202405.asc", "file", "b5aaa14f4daf0b03d697fa4380f659ba2a4bf8e1df223b320df087b2772acca5"), ("gfz-kp/Kp_ap_since_1932.txt", "https://kp.gfz.de/app/files/Kp_ap_since_1932.txt", "gfz-may-2024-rows", "aa87170b556988e6b844ee50ce4d72f7505830dac56d62f05e1d36ee52cfaf80"), ("kyoto-dst/dst_provisional_202405.html", "https://wdc.kugi.kyoto-u.ac.jp/dst_provisional/202405/index.html", "kyoto-rows", "cfb231995fc2dd68ffb3ebaebd2f7c23b80ab641d46553cc72cb44bc3f8f78b0"), ("nmdb/nmdb_8st_hourly_corrp_202405.txt", NMDB.format(st=ST8, res=60, d0=1, d1=31, h1=23, m1=59), "nmdb-rows", "54c7c180fa4176e2d686531088126e026fe7ca1d97c3af3e9d85bd3321a2a997"), ("nmdb/nmdb_gle_5min_corrp_20240510-12.txt", NMDB.format(st=ST5, res=5, d0=10, d1=12, h1=0, m1=0), "nmdb-rows", "13aaa06b61408425d3a38538eadf5c142058e41d44f6485046335db2b942681c"), ("goes/sci_sgps-l2-avg5m_g16_d20240510_v3-0-2.nc", GOES + "sci_sgps-l2-avg5m_g16_d20240510_v3-0-2.nc", "file", "e58ea0c0f384934d5814a5f1f00d9fa7374ac6f0f8d096e5038aca7a423fd912"), ("goes/sci_sgps-l2-avg5m_g16_d20240511_v3-0-2.nc", GOES + "sci_sgps-l2-avg5m_g16_d20240511_v3-0-2.nc", "file", "c515d1218cd56eae62acd559f7d5a0e3a6cd57e7e5695d395c7f53cd8b2e4ea3"), ("goes/sci_sgps-l2-avg5m_g16_d20240512_v3-0-2.nc", GOES + "sci_sgps-l2-avg5m_g16_d20240512_v3-0-2.nc", "file", "4cc099256096389e009c87f9f1c24ae8538b5253f2c896cadea902e4cd8b84c8"), ] def digest(path, how): raw = open(path, "rb").read() if how == "file": return hashlib.sha256(raw).hexdigest() if how == "gfz-may-2024-rows": rows = [l for l in raw.split(b"\n") if l.startswith(b"2024 05 ")] return hashlib.sha256(b"\n".join(rows) + b"\n").hexdigest() text = raw.decode("utf-8", "replace") if how == "nmdb-rows": m = re.search(r"(.*?)", text, flags=re.S) body = html.unescape(m.group(1)) if m else "" rows = [l for l in body.splitlines() if re.match(r"^\d{4}-\d\d-\d\d \d\d:\d\d:\d\d;", l)] else: # kyoto-rows txt = html.unescape(re.sub(r"<[^>]+>", "", text)) rows = [l.rstrip() for l in txt.splitlines() if re.match(r"^\s?\d{1,2}\s+-?\d", l)] return hashlib.sha256(("\n".join(rows) + "\n").encode()).hexdigest() def fetch(url, path): os.makedirs(os.path.dirname(path), exist_ok=True) req = urllib.request.Request(url, headers={"User-Agent": UA}) for attempt in range(3): try: with urllib.request.urlopen(req, timeout=300) as r: data = r.read() with open(path, "wb") as fh: fh.write(data) print(" fetched", len(data), "bytes") return True except (urllib.error.URLError, TimeoutError) as e: print(" attempt", attempt + 1, "failed:", e) time.sleep(5 * (attempt + 1)) return False def main(): folder = sys.argv[1] if len(sys.argv) > 1 else "inputs" for rel, url, how, ours in INPUTS: path = os.path.join(folder, *rel.split("/")) print(rel) if not (os.path.exists(path) and os.path.getsize(path) > 0): if not fetch(url, path): print(" NOT FETCHED; the scripts that read it will stop") continue time.sleep(1) d = digest(path, how) print(" " + ("matches our copy" if d == ours else "DIFFERS from our copy (" + how + "): " + d)) if __name__ == "__main__": main()