#!/usr/bin/env python3 """Fetch the public inputs of /preseismic-geomagnetic-network/ into a folder. Standard library only. Run: python3 -I fetch_public_inputs.py [--accept-esa-terms] It writes /indices (GFZ's Kp, OMNI2 for 2023, NASA SSCWeb's Swarm positions), /usgs (USGS's catalogue) and, only with --accept-esa-terms, /ibi (ESA's Swarm A Ionospheric Bubble Index, one file a day). About 84 MB in all. A file already there is not fetched again. It then says whether each file is byte for byte the one we used on 2 November 2026. GFZ's file grows every day and USGS revises its catalogue, so those can differ without changing the numbers much; only August 2023 matters for GFZ and OMNI. ESA asks anyone who accesses Swarm products to accept its Data Policy and its Terms and Conditions, so that step is yours to choose: https://earth.esa.int/eogateway/documents/20142/1564626/ESA-Data-Policy-ESA-PB-EO-2010-54.pdf https://earth.esa.int/eogateway/documents/20142/1564626/Terms-and-Conditions-for-the-use-of-ESA-Data.pdf Without those files swarma_date_proof.py and swarma_baselines.py can't run, and run_all.py skips them; the other scripts run. The zip itself is not fetched here: download SwarmA-MagSet.zip from Zenodo, https://doi.org/10.5281/zenodo.17862825 (CC BY 4.0). Its SHA-256 should be 2513b67e93486f2c60aaa21ed84dd8c9b4843e05eeca64bccfceeef546c10c80. """ import hashlib import sys import urllib.request from pathlib import Path sys.stdout.reconfigure(encoding="utf-8", errors="replace") SSC = "https://sscweb.gsfc.nasa.gov/WS/sscr/2/locations/swarm%s/20230731T000000Z,20230901T000000Z/geo/" USGS = "https://earthquake.usgs.gov/fdsnws/event/1/query?format=csv&starttime=%s&endtime=%s&minmagnitude=5.0&eventtype=earthquake&orderby=time-asc" ESA = "https://swarm-diss.eo.esa.int/?do=download&file=swarm/Level2daily/Entire_mission_data/IBI/TMS/Sat_A/SW_OPER_IBIATMS_2F_2023{day}T000000_2023{day}T235959_0502.ZIP" OPEN = [ ("indices/Kp_ap_since_1932.txt", "https://kp.gfz-potsdam.de/app/files/Kp_ap_since_1932.txt", "6a470791396fec13ec278d83c10490cd7dd7ad6a7849f473ccad77f5a91fc691"), ("indices/omni2_2023.dat", "https://spdf.gsfc.nasa.gov/pub/data/omni/low_res_omni/omni2_2023.dat", "df74e09c22b126841835c0add8c46933b93118c33a1978f7e977f9488cf7d743"), ("indices/ssc-swarma.xml", SSC % "a", "e993647c6df88b615091152ecb95d943bcf76f5a0b9214919e1012bee9aec36d"), ("indices/ssc-swarmb.xml", SSC % "b", "7bf960515a16b7fed495d67a54d21b80f1e2e493ff0da46800287306fe033b18"), ("indices/ssc-swarmc.xml", SSC % "c", "2652bf31d2be95589c8d033459896ff0234c27352f5c078bd3d18349479775e2"), ("usgs/usgs-m5-2014-2019.csv", USGS % ("2014-01-01", "2020-01-01"), "ce36d65ad840a5233e790ea42bd7d0b2813c3f892b206923b15e52d6f5a18bab"), ("usgs/usgs-m5-2020-2025.csv", USGS % ("2020-01-01", "2026-01-01"), "1a3e75e278edf78c82bddbafe65a6023e998c01b913e2dd8f3c3fb50ff645b8a"), ] IBI_DAYS = { "0801": "dd9bbd4726a9763619e77d1787ec8e88937dcd6b884632e3b68ffe5b897d2061", "0802": "f2a54b9524cdf4aeb51d656c000db7920258e76db2bfe61aca44e66d38de4ff4", "0803": "258677ed9e81bde579733fa664b5a522ef78add1375860fcd84c358100ede7ff", "0804": "41c83b4b2055d569d7a1594a3616e45ac13ee58e57e3fa15cf7202370facb7fe", "0805": "0a4e249cfaa7da801d38f7781d168e92e95ca837c8e9708bd8ac756480fae31d", "0806": "37f9cc07af73af240c199b736be00e05d0772dcf363cc2766cef9bfbfa783b1f", "0807": "2077f6e489b732f59afdd97613c40b6d4e039664748805d5dec66866ef7315ae", "0808": "51750ce6e910a5a701be1d648214dec35e6713e73cdf6baaabef9955da302b6d", "0809": "4bbbe3f8c28f75fadb5a8d8e1927584f2490bfbc83174b924761530642db4f7a", "0810": "bb5e335d434e3684af82abcd8f97f7e21ec9921ce7fedeaf8caae4d3a64b42fa", "0811": "5b2ca73f1bcc820dcc1cd6e645b4f812a30f0807184d6a0093ea406c234c2f5e", "0812": "9235ffc36af33ecdc579b952505218ef31843f5528029e212f79c93163dd5a90", "0820": "b9671449a9634749e1b25c9f8187be16f4b3b001e87dbc08aa364b18432d6736", "0821": "56a90289b8a0b599db2512378d3e60e5fd87cd66950bf9835c375b8e41e5548d", } def esa_url(day): return ESA.format(day=day) def fetch(url, path): path.parent.mkdir(parents=True, exist_ok=True) req = urllib.request.Request(url, headers={"User-Agent": "factchecked.science repeat script", "Accept": "application/xml, text/plain, text/csv, */*"}) tmp = path.with_suffix(path.suffix + ".part") with urllib.request.urlopen(req, timeout=300) as r, open(tmp, "wb") as f: while True: block = r.read(1 << 20) if not block: break f.write(block) tmp.replace(path) def main(): args = [a for a in sys.argv[1:] if not a.startswith("--")] if len(args) != 1: sys.exit(__doc__) root = Path(args[0]) todo = list(OPEN) if "--accept-esa-terms" in sys.argv: for day, sha in IBI_DAYS.items(): todo.append((f"ibi/SW_OPER_IBIATMS_2F_2023{day}T000000_2023{day}T235959_0502.ZIP", esa_url(day), sha)) else: print("ESA's files were left out: run again with --accept-esa-terms if you accept ESA's terms (see the top of this script).") for rel, url, sha in todo: path = root / rel if path.is_file(): state = "already here" else: fetch(url, path) state = "fetched" got = hashlib.sha256(path.read_bytes()).hexdigest() print(f"{rel}: {state}, {path.stat().st_size:,} bytes, {'the same file we used' if got == sha else 'differs from the file we used'}", flush=True) if __name__ == "__main__": main()