#!/usr/bin/env python3 """Fetch the inputs of factchecked.science's page /ionosphere-storm-recovery/ by URL, with curl under the plain client name "factchecked-research/1.0", into the folders the other scripts expect. Usage: python3 -I fetch_inputs.py S0 News's tables for research note 002, GFZ's Kp and quiet days, IGRF-14 and three OMNI years, about 110 MB, into /downloads/ python3 -I fetch_inputs.py --code the CODE maps for every day in /work/dates_needed.txt (written by select_placebo.py) and the day before each, about 2,300 files and 0.72 GB, at one request a second, through fetch_code_gim_batch.py Each file's SHA-256 is compared with the copy we used on November 6, 2026, and any difference is printed. GFZ's Kp file and its 2026 quiet-day list grow over time, so theirs will differ; their values for 2014-2025 do not change. S0 News's tables carry no licence, so they are fetched here, not hosted. Needs curl (and gzip for the CODE maps). """ import datetime as dt import hashlib import os import subprocess import sys UA = "factchecked-research/1.0" DRIVE = "https://drive.google.com/uc?export=download&id=" # (folder, file name, URL, SHA-256 of the copy we used on 2026-11-06) FILES = [ ("s0-note-002-drive", "SHA256SUMS.txt", DRIVE + "1iMXvBZhKAw1hZafplwrfXoGyOpUjuMiR", "1a45ed275641f51107d96ecb47ad9e843faa99ae22d281fa20ffd017a4e132b2"), ("s0-note-002-drive", "MANIFEST.md", DRIVE + "1izG2Wu1g0hMEK2E5OeQZej3s8XZY51AW", "f92638786bc9e62067aca60b332845be5ee957efe255b8355b599b4e92fd403b"), ("s0-note-002-drive", "storm_inventory.csv", DRIVE + "1cmh1zhfQKollDCYPTUEtLMnO9ufZBOPu", "7d67d7e13d845f8d681a2ca318ad7d2d4ceb23d631d50ec4aab806a0ddb9ceda"), ("s0-note-002-drive", "recovery_times.csv", DRIVE + "1IJwJKvOpqNrpO-MDLRGpqu2Kh12Ns9NK", "e4639eb584fc917d128f0597cb8a3164acbf507619a57e29ff4264cf3a0befcf"), ("s0-note-002-drive", "km_summary.csv", DRIVE + "1rRQUEw3-QAQDWyb8VrFdzy938iDD3jMs", "8850931b29bcfd5d59178e64766f73ab756b0447507666913ef63762d774ddfa"), ("s0-note-002-drive", "km_curves.csv", DRIVE + "11IuoezlSwhOv5R6otsAU1l_MSsWK-uqz", "be47a41525a6853e56ea86916948ef80d758c353f93e683fa4028be5d59abb6a"), ("s0-note-002-drive", "sea_strip.csv", DRIVE + "1N2r5_-UcCiYYbazTIvQAlU4g_iM-KkQ6", "014a5c8bfacfe21ac7d460bf7a26ef57e6fa575c70ee6ca434a1bab06bc89198"), ("s0-note-002-drive", "km_band_x_phase.csv", DRIVE + "12vqFCXAE-lvl1niebWtjcIbdIYdc3x_O", "73edab085936ba2d2d5e3f735a6e21f05084f43a9a82d831d5cc7e4a39e35eb8"), ("s0-note-002-drive", "km_sens_qday_variants.csv", DRIVE + "1CBVc-1rjAK0h33Xa29Ig0IEynVVHcTcF", "692e1367d2bde99e3c0263f26a0a6cb7f9b60e6c80959e1a9a793dd900560bc6"), ("s0-note-002-drive", "quiet_days_selected.csv", DRIVE + "1WaTQQ2eJZU7ZVbp1yo0VrN40WaoxxxMa", "8512ecf12dddeb8cae59056d33ba41dea37cdda8545cdf85c4e752e262511f93"), ("s0-note-002-drive", "quiet_band_envelopes.csv", DRIVE + "1NZvTWo8sZ1gCPjYIuPSr2gV6DOvVH96y", "4731a608ee045b91c53f30b578a46a711c40ce3b5a8cb763b555ee91979fa946"), ("gfz-kp", "Kp_ap_Ap_SN_F107_since_1932.txt", "https://kp.gfz.de/app/files/Kp_ap_Ap_SN_F107_since_1932.txt", "af01278a905944bc55a9ea4dbd00942566b56a8e9e7361e2a55808268e7bced8"), ("igrf14", "igrf14coeffs.txt", "https://www.ngdc.noaa.gov/IAGA/vmod/coeffs/igrf14coeffs.txt", "8f8d88403028fc4ee92c4f38d97b46e0a87e2cfc496045b43c9e26c1d6b0903c"), ("omni-hro", "omni_5min2015.asc", "https://spdf.gsfc.nasa.gov/pub/data/omni/high_res_omni/omni_5min2015.asc", "3834f5a058ad5257a482b53b99f77b09ebc78325f5cc6d0ce40dbf7950c7bc09"), ("omni-hro", "omni_5min2024.asc", "https://spdf.gsfc.nasa.gov/pub/data/omni/high_res_omni/omni_5min2024.asc", "1acc38b9531566bdec4f24d463c52fa68e03939acb4cfd9ab5905eb5460c43ef"), ("omni-hro", "omni_5min2025.asc", "https://spdf.gsfc.nasa.gov/pub/data/omni/high_res_omni/omni_5min2025.asc", "f5793379d582f0b826036fa3a4d63227a2c2a7b18f41114f05e8a15b417ed7ac"), ] QD = {2013: "dac1053212e4b9a35bc43c7ef0f3a114343a2a018bcba787a5183815ac8076d0", 2014: "9be0d2c40a565beaa80b6e7c834c46e0f45cbda7320915ad2b3bb6f2cb2f3f85", 2015: "a13688d1408590be02daf5036870a0f837ae66d5a7c37eba7e492201144be899", 2016: "8d0671405e87f6c8a3f4159ec3e6d42ad9386b81973aac557274ac74cb5a4551", 2017: "55d5d967b2f6e79a4cdfa313eb58f23d0bcb32025ebf119535af09901dd359ca", 2018: "bc9e68409a1fdbc9765bc351db47a51a993f18fa52e3698673cfce1c64b84738", 2019: "60eae9e7af15724aaf6154339330e3aee77d87d073594ef601ea5e9ed843ce5c", 2020: "f585b7bd131c6d8c47dd13df2fcab4329d3b370fa0f91669256ef31e6315e4e8", 2021: "e3147948bad6adf4b92c8b3ae7c00662accbb429f3ab73cf2bc3822977caac53", 2022: "80ece7b53c10a51c58fef98f887722cb170e3fb6e0acac31d711d61e552ea08f", 2023: "80bf33e00820da3ca16b58608ed72c26aaa4f60f091d81593cc0f24e5c533e4e", 2024: "5095c4be79df2b63d85cf0912d6fb81208328cdddbe7cf061b80d0e7bba60c73", 2025: "93651138af2406c3eaa5915561616a913aaab6e57f7ee68daea7af1914ad18dc", 2026: "c97c62bbfb2682e8b444d8f492b0a17cf7503c73d60279c158f40eae33e3eefb"} for y, h in QD.items(): FILES.append(("gfz-kp", "QD_days%d.txt" % y, "https://datapub.gfz.de/download/10.5880.Kp.0001/Quiet_Disturbed_Days/QD_days%d.txt" % y, h)) def sha256(path): h = hashlib.sha256() with open(path, "rb") as f: for chunk in iter(lambda: f.read(1 << 20), b""): h.update(chunk) return h.hexdigest() def fetch(url, dest): p = subprocess.run(["curl", "-sS", "-L", "-A", UA, "--fail", "--max-time", "600", "-o", dest, "-w", "%{http_code}", url], capture_output=True, text=True) return p.returncode, (p.stdout or "").strip(), (p.stderr or "").strip() def main(): base = sys.argv[1] for sub in ("downloads", "results", "work"): os.makedirs(os.path.join(base, sub), exist_ok=True) if "--code" in sys.argv: need = os.path.join(base, "work", "dates_needed.txt") days = set() with open(need, encoding="utf-8") as f: for line in f: if line.strip(): d = dt.date.fromisoformat(line.strip()) days.add(d) days.add(d - dt.timedelta(days=1)) lst = os.path.join(base, "work", "dates_with_previous.txt") with open(lst, "w", encoding="utf-8", newline="\n") as f: f.write("".join(d.isoformat() + "\n" for d in sorted(days))) here = os.path.dirname(os.path.abspath(__file__)) os.makedirs(os.path.join(base, "downloads", "code-gim"), exist_ok=True) sys.exit(subprocess.call([sys.executable, "-I", os.path.join(here, "fetch_code_gim_batch.py"), lst, os.path.join(base, "downloads", "code-gim"), os.path.join(base, "downloads", "code-gim", "fetch_log.jsonl"), "--rate", "1/s"])) differ = 0 for folder, name, url, want in FILES: d = os.path.join(base, "downloads", folder) os.makedirs(d, exist_ok=True) dest = os.path.join(d, name) rc, code, err = fetch(url, dest) if rc != 0: print("FAILED (HTTP %s): %s %s; stopping, as a refusal should not be worked around" % (code, url, err[:200])) sys.exit(2) with open(dest, "rb") as f: if f.read(64).lstrip().lower().startswith(b"<"): print("STOP: %s answered with a web page, not the file (a sign-in or check page?)" % url) sys.exit(3) got = sha256(dest) same = got == want differ += not same print("%-28s %-34s %s" % (folder, name, "same as ours" if same else "DIFFERS from ours: " + got)) print("done; %d file(s) differ from the copies we used" % differ) here = os.path.dirname(os.path.abspath(__file__)) dl = os.path.join(base, "downloads") kp = os.path.join(dl, "gfz-kp", "Kp_ap_Ap_SN_F107_since_1932.txt") drive = os.path.join(dl, "s0-note-002-drive") q = lambda *p: '"%s"' % os.path.join(*p) # noqa: E731 print("\nNext steps (each reads the files fetched above; outputs go to %s):" % os.path.join(base, "results")) print(" python3 -I %s %s %s %s" % (q(here, "check_storms.py"), q(kp), q(drive, "storm_inventory.csv"), q(base, "results", "storms_rebuilt.csv"))) print(" python3 -I %s %s %s %s %s %s %s" % (q(here, "select_placebo.py"), q(kp), q(dl, "gfz-kp"), q(drive, "storm_inventory.csv"), q(drive, "quiet_days_selected.csv"), q(base, "results", "placebos.csv"), q(base, "work", "dates_needed.txt"))) print(" python3 -I %s %s" % (q(here, "draw_spotcheck.py"), q(base))) print(" python3 -I %s %s --code (about 2,300 CODE maps, 0.72 GB, at one request a second)" % (q(here, "fetch_inputs.py"), q(base))) print(" python3 -I %s %s" % (q(here, "cache_bands.py"), q(base))) print(" python3 -I %s %s --run2h 6" % (q(here, "run_all.py"), q(base))) print(" python3 -I %s %s" % (q(here, "exploratory_checks.py"), q(base))) print(" python3 -I %s %s" % (q(here, "check_symh.py"), q(base))) print(" python3 -I %s %s %s (the note's numbers from its own tables)" % (q(here, "reproduce_note.py"), q(drive), q(base, "results", "reproduce_note.json"))) if __name__ == "__main__": main()