#!/usr/bin/env python3 """S0's special report of November 11, 2026 ("Pole Shift - Part 2"): every number tagged "Our analysis" on https://factchecked.science/s0-news-2026-11-11/ (Fact-Checked Science, November 2026). Standard library only. Run it python3 -I -B special_report_part2_numbers.py [folder] [--part count|cycles|field|all] The folder (default: the script's own) must hold, or will receive, the inputs below. A missing file is downloaded from its maker under the plain client name "factchecked-research/1.0", one request at a time with a pause between requests. Every file is then compared with the SHA-256 of the copy we used on November 11, 2026; for files that grow (GFZ's, SILSO's, the current quarter of NOAA's daily data) a different hash is expected, and the script uses only the days and months we had. It prints a summary and writes s0-news-2026-11-11-numbers.json into the folder. --part field needs two small files and takes seconds. --part count needs Kyoto's 837 monthly pages (about 5 MB, about ten minutes at the script's pace). --part cycles needs those and about 120 files from NOAA (about 11 MB). Inputs (all public) dst_YYYYMM.html Hourly Dst from the World Data Center for Geomagnetism, Kyoto, one page a month, January 1957 to September 2026: https://wdc.kugi.kyoto-u.ac.jp/dst_final/YYYYMM/index.html (to December 2020) and https://wdc.kugi.kyoto-u.ac.jp/dst_provisional/YYYYMM/index.html (from January 2021). Nose, Iyemori, Sugiura and Kamei (2015), doi:10.17593/14515-74000. Kyoto's rules (https://wdc.kugi.kyoto-u.ac.jp/wdc/Sec3.html): scientific use, no commercial use, with acknowledgement of the WDC and of the observatories that supply the data. THE SCRIPT NEVER READS A REAL-TIME (QUICKLOOK) MONTH: Kyoto asks to be contacted before those values are published. Kp_ap_Ap_SN_F107_since_1932.txt Kp, ap, Ap (GFZ Helmholtz Centre for Geosciences, CC BY 4.0; Matzka et al. 2021, doi:10.1029/2020SW002641; data doi:10.5880/Kp.0001) with F10.7 from DRAO/NRCan: https://kp.gfz.de/app/files/Kp_ap_Ap_SN_F107_since_1932.txt (its sunspot column is not used) SN_m_tot_V2.0.csv, SN_ms_tot_V2.0.csv Monthly mean and 13-month smoothed total sunspot number, version 2.0, WDC-SILSO, Royal Observatory of Belgium, Brussels (CC BY-NC 4.0): https://www.sidc.be/SILSO/DATA/ goes-xrs-report_YYYY.txt NOAA NCEI's yearly lists of GOES X-ray flares, 1975-2016 (for 2015 the file goes-xrs-report_2015_modifiedreplacedmissingrows.txt): https://www.ngdc.noaa.gov/stp/space-weather/solar-data/solar-features/solar-flares/x-rays/goes/xrs/ YYYY_events.tar.gz, 2026MMDDevents.txt NOAA SWPC's edited events, 2017-2025 by year, and the ten days of 2026 with an X-class flare: ftp://ftp.swpc.noaa.gov/pub/warehouse/YYYY/ YYYY_DSD.txt, YYYYQn_DSD.txt NOAA SWPC's Daily Solar Data, 1997-2026, used only to check our flare counts: ftp://ftp.swpc.noaa.gov/pub/indices/old_indices/ CHAOS-8.7_spline-coefficients.dat CHAOS-8.7 core field (Kloss et al., DTU Space, September 30, 2026, CC BY 4.0, doi:10.5281/zenodo.22959079), from https://www.spacecenter.dk/files/magnetic-models/CHAOS-8/ igrf14coeffs.txt IGRF-14 (IAGA Working Group V-MOD): https://www.ngdc.noaa.gov/IAGA/vmod/coeffs/igrf14coeffs.txt What it computes (the rules were written before the first runs: RULES_storm_count.txt, RULES_sun.txt and RULES_field.txt, hosted beside this script; HASHES.txt lists what changed afterwards) C "Over 400 solar storms of that magnitude": storms at least as strong as that of 23-24 March 2023, by Kyoto's Dst (-163 nT or deeper, from 1957) and GFZ's Kp (8o or more, from 1932), counted by the rule the storm lists of S0 News's research note 004 follow (each hour or three-hour interval at the level joins the storm before it if it starts 24 h or less after that storm's latest one), with a ladder of other thresholds and other ways of counting; and, among them, the storms for which our review of November 1, 2026 found Florida named. If the note's own list, Storms_all_strata_24h.csv, is put in the folder (we neither host nor fetch it), the script checks its storms against it, start and end times alike. Our first reading of the note's sentence, runs of hours joined when their starts are 24 h or less apart, is the one RULES_storm_count.txt registered; its counts are kept beside the others. S Solar Cycle 25 against Cycles 15-24: smoothed maximum and mean sunspot number, F10.7, Ap, great storms and X-class flares, like for like over each cycle's first 83 months (December 2019 to October 2026 for Cycle 25). Flare lists before GOES-16 are on the old operational scale; "today's scale" divides their classes by 0.7. F The axial dipole in CHAOS-8.7 from March 23, 2023 to August 31, 2026, beside IGRF-14's forecast. Conventions A Kyoto table's column k is the hour from k-1 to k UT. Kp is counted in thirds (8o = 24, 9- = 26, 9o = 27). "In the past" means storms that began before March 23, 2023. Cycle starts are WDC-SILSO's smoothed minima. Years of dipole loss run from one January 1 to the next unless a row says otherwise. Credit: the B-spline and IGRF code is adapted from the site's special_report_numbers.py (/s0-news-2026-11-09/). """ import datetime as dt import hashlib import json import math import os import re import sys import tarfile import time import urllib.error import urllib.request UA = "factchecked-research/1.0" PAUSE = 0.4 # seconds between downloads OUT_NAME = "s0-news-2026-11-11-numbers.json" EPOCH = dt.datetime(1932, 1, 1) PAST_BEFORE = dt.datetime(2023, 3, 23) # "in the past": storms that began before the March 2023 storm KP_UNTIL = dt.date(2026, 10, 31) # GFZ's Kp was definitive to this day when we read it SN_UNTIL = (2026, 10) # SILSO's last month when we read it DST_FIRST, DST_LAST, DST_LAST_FINAL = (1957, 1), (2026, 9), (2020, 12) FLARES_UNTIL = dt.date(2026, 10, 31) X_DAYS_2026 = ["20260118", "20260201", "20260202", "20260203", "20260204", "20260330", "20260424", "20260603", "20260630", "20260704"] # the days of 2026, to October 31, on which SWPC's daily data count an X-class flare DST_LADDER = [-100, -125, -150, -163, -200, -250] KP_LADDER = [("7-", 20), ("7o", 21), ("7+", 22), ("8-", 23), ("8o", 24), ("8+", 25), ("9-", 26), ("9o", 27)] CYCLES = [(15, 1913, 7), (16, 1923, 8), (17, 1933, 9), (18, 1944, 2), (19, 1954, 4), (20, 1964, 10), (21, 1976, 3), (22, 1986, 9), (23, 1996, 8), (24, 2008, 12), (25, 2019, 12)] SILSO_TABLE_MAX = {15: 175.7, 16: 130.2, 17: 198.6, 18: 218.7, 19: 285.0, 20: 156.6, 21: 232.9, 22: 212.5, 23: 180.3, 24: 116.4, 25: 160.9} # WDC-SILSO's own table of cycle maxima, read November 11, 2026 N_LIKE, N_LIKE_DST = 83, 82 # months of Cycle 25 so far; Kyoto's provisional Dst ends a month earlier T0 = 2023.0 + (31 + 28 + 22) / 365.0 # March 23, 2023, 00 UT T1 = 2026.0 + (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31) / 365.0 # the end of August 31, 2026 (CHAOS-8.7's last satellite data) # Storms for which our review of November 1, 2026 found Florida named (its table "Every storm we found with Florida # named"), as UT-day spans, with that page's description of the record; and its two weaker entries, kept apart. FLORIDA_NOV1 = [ ("1989-03-13", "1989-03-14", "reports; no photograph found"), ("2000-04-06", "2000-04-07", "one photograph"), ("2001-11-06", "2001-11-06", "a sentence; no Florida photograph in the gallery"), ("2003-10-29", "2003-10-30", "two reports; no Florida photograph in the gallery"), ("2003-11-20", "2003-11-20", "a sentence; no Florida photograph in the gallery"), ("2023-03-23", "2023-03-24", "one long exposure"), ("2024-05-10", "2024-05-11", "several"), ("2024-10-10", "2024-10-11", "several"), ("2025-11-11", "2025-11-12", "several"), ("2026-01-19", "2026-01-21", "one photographer"), ] FLORIDA_WEAK = [ ("2004-11-07", "2004-11-10", "inferred (every US state except Hawaii)"), ("1981-04-12", "1981-04-13", "a lead: a 2025 article, no date or primary source"), ] NGDC = "https://www.ngdc.noaa.gov/stp/space-weather/solar-data/solar-features/solar-flares/x-rays/goes/xrs/" SWPC_W = "ftp://ftp.swpc.noaa.gov/pub/warehouse/" SWPC_I = "ftp://ftp.swpc.noaa.gov/pub/indices/old_indices/" URLS = { "Kp_ap_Ap_SN_F107_since_1932.txt": "https://kp.gfz.de/app/files/Kp_ap_Ap_SN_F107_since_1932.txt", "SN_m_tot_V2.0.csv": "https://www.sidc.be/SILSO/DATA/SN_m_tot_V2.0.csv", "SN_ms_tot_V2.0.csv": "https://www.sidc.be/SILSO/DATA/SN_ms_tot_V2.0.csv", "CHAOS-8.7_spline-coefficients.dat": "https://www.spacecenter.dk/files/magnetic-models/CHAOS-8/_downloads/" "d51e04c49142b02b19f7544b6d32bec8/CHAOS-8.7_spline-coefficients.dat", "igrf14coeffs.txt": "https://www.ngdc.noaa.gov/IAGA/vmod/coeffs/igrf14coeffs.txt", } GROWS = {"Kp_ap_Ap_SN_F107_since_1932.txt", "SN_m_tot_V2.0.csv", "SN_ms_tot_V2.0.csv", "2026Q4_DSD.txt"} # SHA-256 of the copies we used on November 11, 2026 (filled from HASHES.txt's list; a missing name is not checked) HASHES = { "CHAOS-8.7_spline-coefficients.dat": "f759e725b763dd300cb97be07f44cda655226babde0cfe23f9e37ed7a425d203", "igrf14coeffs.txt": "8f8d88403028fc4ee92c4f38d97b46e0a87e2cfc496045b43c9e26c1d6b0903c", } HASHES.update(json.loads("""{ "1997_DSD.txt": "06d8a0402b681e61e86515595ba19b5094217a8bd4fd51891c222396a3d131b1", "1998_DSD.txt": "ee271ac83835fde588327d15ed3153365d79c5910c35444a5204d3cc5761b29c", "1999_DSD.txt": "a17cfdf130001be1d85c5cc67773663d932d16240791f574a09760abf292528d", "2000_DSD.txt": "352b0c5a08d338e4d2aba0e3c4427e9b390010876bf17a80d710df0b44a25e81", "2001_DSD.txt": "0b94657f30be9652c1be731b39fd6357718f052293d363090fb6bd11571041db", "2002_DSD.txt": "3a836d3afe692b706f04504210c1399736f4edf3dc4880d1c447ecc4464cb0aa", "2003_DSD.txt": "8fba77689226b9ef96ee5c773a3a383f08e4b602f02cbebe7fd711f5d89c1379", "2004_DSD.txt": "f8f2158813d8ed33b232aaa45d7fb747a8bface312cc59f8f03fa0b8d399a659", "2005_DSD.txt": "49de6c4b5ec01dee503ca2c731cb61e2f6c7310e6f40fca71843d7fe57adfedd", "2006_DSD.txt": "6dd85fae489a32fecfdc1a66d7fd4be33ad6cf499c7cdfac8e2310723503b6ea", "2007_DSD.txt": "b7b92346a836a1e7bd9c41d73ee2c1a0dfd05c578e3517bda94a04e37ad3a3a1", "2008_DSD.txt": "c1d48bd399264264b778fcaa25c0ecf81981d6fab5634d377de6f7ab403baa9e", "2009_DSD.txt": "96dc2e2bb2542bb2cacbe474161cf8ba842ca49c5cb27c0e9724a92d19c5a002", "2010_DSD.txt": "5ff5188e3477eb242901af49dc7d1efb07f4866a1516330657e372166109ad30", "2011_DSD.txt": "393fa75025d04a8e8ac17d89757909cbac26a1a2062cfe3ed6f3068b9cddab86", "2012_DSD.txt": "d691f370e27596a0073fd78b06870c6ad8ea0f2577f94f0489ab6007340e6014", "2013_DSD.txt": "59f4971ad83e3d8ff806eb3cc1c49ea8cb324cc5486f43b5ec7da0e916b760f6", "2014_DSD.txt": "34370f77a1e182b707baad428d578f590db4fe135caeed51975d4d437d810b20", "2015_DSD.txt": "b9b1d1a04a470d2600e3a926d8fe601243da357c1416066c63a63bdbed38f4e0", "2016_DSD.txt": "2ee24604ef2518769f9ed3a55cb8f049a3352a496f6f7170c02c72c063c026da", "2017_DSD.txt": "c30629c0079333bf7bf5e4495960756f065b8fd7167f89a5a1411a2f1f7987fc", "2017_events.tar.gz": "269e727db334c54f17a6c62cedaf129dc2895aa4b69ec8961778a475ed02d24d", "2018_DSD.txt": "81cf399844b582f4bc4ac84f4035859370ce91a1cde0793ca6362488c7ab8d4b", "2018_events.tar.gz": "b3bf2bf43807edf4093c139a15667aa905cdd33db7182779666e45af10836773", "2019Q1_DSD.txt": "b5ae15376a46df3972644e4f555cc2706efc380a1a32a03aaac73d37ef9df90b", "2019Q2_DSD.txt": "70947151995e42929ac8bf5ad00150dd867c6b8d16255a55b7bcc809f6511b09", "2019Q3_DSD.txt": "a7bdb280d05aa70e82473934aa77d6945e39e0f10d21725ff47fb76d99eb211d", "2019Q4_DSD.txt": "17e9bcda6cb66960d863ba97a4c2c0a1c298cfbbcd1515a5a102db5b43765d8f", "2019_events.tar.gz": "f24f326bc7ff6e46e01a641a07378530da43f7b5252071ec36391fafe368977a", "2020Q1_DSD.txt": "6140ffaecc76ee22f4d2096b1bc8c89fbcb4ad88de34f7a12ff72b97ae4310fd", "2020Q2_DSD.txt": "485f7a028004f08acd5ad9165705c1086923d116bf5cdd18e194879d4ef70be4", "2020Q3_DSD.txt": "a8512b4d6b665d75c7b5ad316f1e95cb0357aa065005d68a16b02759d1ff0f05", "2020Q4_DSD.txt": "152a9c964969902f3c81a79de2fea1b6461731ff92ca2d5b4e45edad36e16225", "2020_events.tar.gz": "ce0005f97923834464fa9e664dd7d9978f8784429bbe27d1c711c0d9fafdc9c1", "2021Q1_DSD.txt": "85f21c63b31ce610857168f60565686e2f238868fff7fa7e3eef40481a9c25bb", "2021Q2_DSD.txt": "bdfbb4ae63798184a9710c3b1e8fd5a468d74f2bd7cc55fee5eca78433b0f37c", "2021Q3_DSD.txt": "81651d5c5582bf948155507b92ab0c64d5808527a3ce2067073c7b23d28a62e9", "2021Q4_DSD.txt": "ffaceeb46db7daab9b9cec0df1c6794e82bbafc9932379ad64c8967bf9e56b40", "2021_events.tar.gz": "ff2067dd4d7caccf0456e700c8a83fa174b19c5baac35fbd92feed2a5e662363", "2022Q1_DSD.txt": "9fa85fa2ea4db6fdb2b1662dc53c4daadfb465cdbbc677e684fa79c563d9bff2", "2022Q2_DSD.txt": "31fa6e6b7e274e420482e561228400b76aa3c612c2f5c5ef993d9d496bd268cd", "2022Q3_DSD.txt": "5574eb4034b7c5cabf82c5b91d8bc2aeb6eef4ef3f7ff3d9bfd8fe9702d9cb01", "2022Q4_DSD.txt": "f86b5171f6907c199a43a095f0f7395f88cb64a1b51336498117b5cb6d00d359", "2022_events.tar.gz": "81a4de2edfe1ec42adf777306daf1bb552748bd062dd5ff622c46393b05c02ae", "2023Q1_DSD.txt": "43085bf68632a39fec1906a86f6dbe1daf56496ea9bad50a16edb5bca9d39269", "2023Q2_DSD.txt": "37c86143fad59f3b4903d8a9d0843feb203a7dee366396154668b10f90b2b609", "2023Q3_DSD.txt": "7ea45ba50ed00bc5751003ecc01fe9f7b62fe2afd0312467ce94e04688f670b1", "2023Q4_DSD.txt": "051227ed2af3b329636946fa72c3e65c20568cd2e67656d186830d0ca774ff38", "2023_events.tar.gz": "946a59657f2a7266feefc4a807325cdda39e747372f67728a6ab70d193516d1e", "2024Q1_DSD.txt": "b14b6fbba25eeeced91753abd29e3c7fde714a633e47deeedd55753d54de35ff", "2024Q2_DSD.txt": "eb9c4f5a9e1ee974108f60ec80a42da12e9fa9806948f71b8d000c693be0fdbc", "2024Q3_DSD.txt": "3f5a73bbd6d9f1fe65b56fac0a9fe3a896ac4ece914500ab85058d96b289b608", "2024Q4_DSD.txt": "a67f2a827a85bb33568b6767f62ad0ea175174b365fc2135b19b0de2b59d2f5c", "2024_events.tar.gz": "b3aa83efa41750c493b597a3dadf3784c91fb19e28640544cef85d519fc24131", "2025Q1_DSD.txt": "0454e6ec9fb6aad6c5918fece64827a3d1fc10c48b50612ad9372aec678acf97", "2025Q2_DSD.txt": "6c4c62b37328359b35bcf32091b4e6a546f871bd2eff876339cf785212c91419", "2025Q3_DSD.txt": "edb6e0009e0cd956a61ac72eab68fe35fbbf79612a8c733b5153037764a8d9f0", "2025Q4_DSD.txt": "6c7fe53d0819f3f2a6e8412219c63e3f34fc66265314ca99fece08c04c87ecc4", "2025_events.tar.gz": "c3f483e65e9f661c807e86eff87a0cab15b347fcdae4b8184f5c94bdf0689c44", "20260118events.txt": "68178adde8fe1fd0a1b3759a344796574fc926c728f1c2f1f27d960cfc77e4b5", "20260201events.txt": "a53b3dcca7316708f92cb2660d31dadf4071294d19ddd689384b640a754364da", "20260202events.txt": "fc2e21ea192530e1dbdf780f1744384b49ac24612c109e6bb1ec9d3750638093", "20260203events.txt": "d67adae6de53fd49c3a76a6476e60fc215bf42704502a997eaa5cbce3df10b43", "20260204events.txt": "b3f7cd6effba50105de6efed01b42291522a92a7d66365a224e85aa161230c72", "20260330events.txt": "574e76d1c0cc5275e8571f7aee3d32ac59f3a5344cb761aee417b8c3c643a603", "20260424events.txt": "0ba9eb49be47cbe9b1a31a622efed2a5f62c8228c15de7a151a9b5d8e34cafa2", "20260603events.txt": "549674dbdf4c9de94d337ec611deef2c9d40251c0551fdd2e2823cf9344c9e7e", "20260630events.txt": "ceaf4515873435a584485714e5596c10c17a5f19f8ddd0ed199c9a95cddd83e2", "20260704events.txt": "b4ebb48a5fadb04716810234e6b310e426e9aa787ba9e6e789e5af1aca2fdf3d", "2026Q1_DSD.txt": "90ccec9a394f4c3bd3f25f763b1e1e514836488579bcda886177818b8e4ca097", "2026Q2_DSD.txt": "4e2ff15c167b0e7e004cf2258cbd6f44505cda1d94867d3523a8eab9fde4a061", "2026Q3_DSD.txt": "7365132e4283d2d4152e68183e92ea6ff38297e8d95cad49205aab8f92f31e2f", "2026Q4_DSD.txt": "71b35727ca396514fabc7e6b71821466302f45e26eed665b0c7324a5a63eed8a", "Kp_ap_Ap_SN_F107_since_1932.txt": "dd30b260d0c36c3efaf8149e5d4313794b362bfe8b568ad5360644260409cfac", "SN_m_tot_V2.0.csv": "1cf8a1f6f28ff9ee479783d72fa323eb70a824056450ccf60d0152fa28abd72f", "SN_ms_tot_V2.0.csv": "6556ec0b65f608a27d7c559feb0177c91c6340ca4b7b31d016dacbbeaca176e3", "goes-xrs-report_1975.txt": "b3c300f361e36ba030c2e48182f9423bd6d33696f5ec598cdee354f457ad63c4", "goes-xrs-report_1976.txt": "4e746ac1c933b950e529675a7df5fc2a115f3baddbc94881e0ec12870a11a2a1", "goes-xrs-report_1977.txt": "a68829f702ad75f1a4aa2592a4d04f031bfffbdfd034d925beb9d666c0b785e7", "goes-xrs-report_1978.txt": "13f5ee9bcaf03cca1d2c546bb7952d3f04f5fc01b9ca23ba69a3142945163423", "goes-xrs-report_1979.txt": "66473941cf5bb91a53303cd9eb5288b230f376cc8347c46a6a67d3af3cd90220", "goes-xrs-report_1980.txt": "5f96a4a5be34b2370128fe4f39aacf688c842e687c2a6633bf9e29f4272cdb32", "goes-xrs-report_1981.txt": "9cab98a4867df9cf480ab339ad47dd37a766c541494cf09ce9933ed9a5d1629c", "goes-xrs-report_1982.txt": "7c0f256c6d1afd38e81471866c131448723a860b018e540d0c41a6c30d594ff2", "goes-xrs-report_1983.txt": "ced124bb0b50b54631569dbfb419a595103b3f0bbf9f23c20e0116ecfb52bd00", "goes-xrs-report_1984.txt": "c083df81b8267d0112ace119f8a8590c2001d539a4698b7edb8839d5653dd817", "goes-xrs-report_1985.txt": "fdc3e70c911f4fe980e5e8a8c5f6e64b4ae8fd52e58945b6b018f04864e22613", "goes-xrs-report_1986.txt": "8999be46d6fd3c4b01b5355d88aad41bc4d20fbb461263dd6dd21bf83081e306", "goes-xrs-report_1987.txt": "ab132635d6d6de8381b6a7d46c4bf03b5fdd38bc5493fcb6eaa8fed4d13e4140", "goes-xrs-report_1988.txt": "738d1e9c8c50119c1cd3ec503d5714cca9a548d0b163fc183d56cc6ce8bec797", "goes-xrs-report_1989.txt": "44e231dc6aaebfc0a0bd3f13686b090bd78c39e1b29bc2d9a4434ce7ac2cfaa1", "goes-xrs-report_1990.txt": "b575d4908a40f754045ec4c44b16eb69fa5a34198985f6d4af5ca16e3a3b5378", "goes-xrs-report_1991.txt": "7447a49649fc953b5279844e3c7b499e8549fa79a138a9d7b85819e9e8f08162", "goes-xrs-report_1992.txt": "01cc35ee0267761f3d598a55aafc64b08a56ee4d71e2a0a5246db1a9936bb7e3", "goes-xrs-report_1993.txt": "14b2517429c951b3d0b71ec0731b6bb248a7b3d0109218ca44d9659cdd48d357", "goes-xrs-report_1994.txt": "bd6a8b824e2bf9f5f39c300a49de9bd5ef733374e0f1dcbdb9bee6d78223f6b6", "goes-xrs-report_1995.txt": "1f0772da5581bb3fbb4c34b014355c0671620561b5db7758d55a3687a8521179", "goes-xrs-report_1996.txt": "9ba83e3b035c379386c5dbe50492d20d8ad4a537f3f9009a1b6a080ee36c95ff", "goes-xrs-report_1997.txt": "7c84dd60fc12e8746503faf33222f0dd4204227eb5b009731ffa93f5c9588b4d", "goes-xrs-report_1998.txt": "62e8137244b0a4e985fb76bd9348e466857869f32eb7ff9249cbd67ad332e0fe", "goes-xrs-report_1999.txt": "978a2d4f912a9a5566c61cd1ad4400430b6f46c530b354ec8788a4dcd3d801bc", "goes-xrs-report_2000.txt": "48c59979bea08fbd12f94d7c0fbb9fb04a610766a84b60faa4675b12ba83ef9e", "goes-xrs-report_2001.txt": "45f63f4cdbe2ecf8ee7627f5f841f479c61672af1e388b37c93c41d7869d4e79", "goes-xrs-report_2002.txt": "9aca4516c149631e2532dd7642dcfa5494d15670028bd457933ff28af83b352b", "goes-xrs-report_2003.txt": "f964a9d4358951549a77c3fcfe62ac7f69f0b9e746fc51b16ffbc67dce328379", "goes-xrs-report_2004.txt": "7c1d98f11bbae625b9694986503a27b5363f61538dcdda8031a15f161eb1fcc7", "goes-xrs-report_2005.txt": "cc5bcf3f9427ebc8c0521aa31e382b9a8e4754f8950a9a25d94cda7d834c88ac", "goes-xrs-report_2006.txt": "277ba16f09c54b8be33af5ce5e4b9f2eb5fe6bdd1947bc219af6b844227a0217", "goes-xrs-report_2007.txt": "04bde3aee1396cc0e04218608aedf5859a998c18d5d5f6679e289e848b4b40b7", "goes-xrs-report_2008.txt": "9594fbd151afeb2455f80131b52a6cec80e56942dac68cad5e4282092e4c6d2c", "goes-xrs-report_2009.txt": "8086d28b78beb96cc9b745f274ae9fe903f0dfcd3887cc2904909b6ca21f3738", "goes-xrs-report_2010.txt": "b9da77fc23af104988d3d92b0062602a1d75553db0fea21f666b70795dc3663d", "goes-xrs-report_2011.txt": "5163a2f6c763a8501f66c63f298b5e43bc133f9b4621bf645cc69063855590cf", "goes-xrs-report_2012.txt": "d09a36f440cf6f70ee6049c91d77bf9a916b3ce8a0715339029c5befa076914d", "goes-xrs-report_2013.txt": "a733afb0aa5fecf9e5a3c3f523451916c6b349b96e3db7a9aacea703cc38bdbe", "goes-xrs-report_2014.txt": "887faf295839bbe5e24a1c432a127cd3bba9409c14709b87ef0c8359e39f0d11", "goes-xrs-report_2015_modifiedreplacedmissingrows.txt": "8f763de8c167eb2ba9758de3f9b84df775f37a4f82e0e1c21cbbade76b1bf5aa", "goes-xrs-report_2016.txt": "1e4eca84d5403b31b8b6f7feefc4214db8f37aa35da1cf25d9fcd0dceff3e7d1" }""")) DST_VALUES_SHA256 = "82d6f71d174b856a7ed5228c278af67eda6a545c65ca94561ed5c2d4c0a598b7" # SHA-256 of the 611,400 hourly values as parsed, month by month def say(*a): print(*a) sys.stdout.flush() def hidx(d): return int((d - EPOCH).total_seconds() // 3600) def hdate(h): return EPOCH + dt.timedelta(hours=h) def add_months(y, m, n): k = (y * 12 + (m - 1)) + n return k // 12, k % 12 + 1 def month_range(a, b): out, (y, m) = [], a while (y, m) < b: out.append((y, m)) y, m = add_months(y, m, 1) return out def sha_file(path): with open(path, "rb") as f: return hashlib.sha256(f.read()).hexdigest() # ------------------------------------------------------------------ inputs class Inputs: def __init__(self, folder): self.folder = folder self.seen = {} def get(self, url): req = urllib.request.Request(url, headers={"User-Agent": UA}) with urllib.request.urlopen(req, timeout=300) as r: data = r.read() time.sleep(PAUSE) return data def file(self, name, url=None): path = os.path.join(self.folder, name) if not os.path.exists(path): url = url or URLS[name] say("downloading", url) data = self.get(url) with open(path, "wb") as f: f.write(data) if name not in self.seen: digest = sha_file(path) self.seen[name] = digest want = HASHES.get(name) if want and digest != want: if name in GROWS: say("Note: %s has grown since our copy; only the days and months we had are used." % name) else: say("Note: %s differs from the copy we used (SHA-256 %s...); results may differ." % (name, want[:16])) return path def dst_page(self, y, m): ym = "%04d%02d" % (y, m) name = "dst_%s.html" % ym path = os.path.join(self.folder, name) if not os.path.exists(path): kinds = ("final",) if (y, m) <= DST_LAST_FINAL else ("provisional", "final") # never the real-time pages data = None for kind in kinds: url = "https://wdc.kugi.kyoto-u.ac.jp/dst_%s/%s/index.html" % (kind, ym) try: say("downloading", url) data = self.get(url) break except urllib.error.HTTPError: continue if data is None: raise SystemExit("Kyoto has no final or provisional page for " + ym) with open(path, "wb") as f: f.write(data) return path def read_kyoto(inp): """hour index (hour start) -> Dst nT, January 1957 to September 2026, final and provisional pages only.""" out, kinds = {}, {"final": 0, "provisional": 0} digest = hashlib.sha256() for y, m in month_range(DST_FIRST, add_months(DST_LAST[0], DST_LAST[1], 1)): path = inp.dst_page(y, m) txt = open(path, encoding="utf-8", errors="replace").read() i, j = txt.find("
")
body = re.sub(r"", "", txt[i:j], flags=re.S)
if "(FINAL)" in body:
kinds["final"] += 1
elif "(PROVISIONAL)" in body:
kinds["provisional"] += 1
else:
raise SystemExit("%s is neither a final nor a provisional page: not read" % path)
head = re.search(r"\n\s+([A-Z]+)\s+(\d{4})\s*\n", body)
if not head or int(head.group(2)) != y or dt.datetime.strptime(head.group(1).title(), "%B").month != m:
raise SystemExit("the heading of %s does not match its name" % path)
vals_month = []
for line in body.split("\n"):
if len(line) < 98 or not line[:2].strip().isdigit() or re.search(r"[A-Za-z]", line):
continue
h0 = hidx(dt.datetime(y, m, int(line[:2])))
k = 0
for g in range(3):
seg = line[3 + g * 33:3 + g * 33 + 32] # the day in columns 1-2, a space, then three groups of eight 4-wide values
for q in range(8):
v = int(seg[4 * q:4 * q + 4])
if v >= 9999:
raise SystemExit("a missing hour in " + path)
out[h0 + k] = v
vals_month.append(v)
k += 1
ny, nm = add_months(y, m, 1)
if len(vals_month) != 24 * (dt.date(ny, nm, 1) - dt.date(y, m, 1)).days:
raise SystemExit("%s: %d hourly values" % (path, len(vals_month)))
digest.update(("%04d%02d:" % (y, m) + ",".join(str(v) for v in vals_month) + "\n").encode())
d = digest.hexdigest()
if d != DST_VALUES_SHA256:
say("Note: Kyoto's hourly values differ from the copy we used (provisional values are revised); results may differ.")
return out, kinds, d
def read_gfz(inp):
"""per day: Kp in thirds, Ap, F10.7 observed and adjusted, the definitive flag. Days after KP_UNTIL are ignored."""
days = {}
for line in open(inp.file("Kp_ap_Ap_SN_F107_since_1932.txt"), encoding="utf-8", errors="replace"):
if line.startswith("#") or not line.strip():
continue
p = line.split()
d = dt.date(int(p[0]), int(p[1]), int(p[2]))
if d > KP_UNTIL:
continue
days[d] = {"kp": [int(round(float(x) * 3)) for x in p[7:15]], "ap": [int(x) for x in p[15:23]], "Ap": int(p[23]),
"f107obs": float(p[25]), "f107adj": float(p[26]), "D": int(p[27])}
return days
def kp_series(gfz):
kp = {}
for d, row in gfz.items():
if row["D"] < 1 or min(row["kp"]) < 0:
continue
h0 = hidx(dt.datetime(d.year, d.month, d.day))
for i, k in enumerate(row["kp"]):
kp[h0 + 3 * i] = k
return kp
# ------------------------------------------------------------------ storms
def intervals(series, step, test):
"""maximal runs of consecutive samples (step hours apart) passing the test: [start hour, end hour (exclusive), (hour, value) pairs]"""
runs, cur = [], None
for h in sorted(series):
v = series[h]
if test(v):
if cur is not None and h == cur[1]:
cur[1] = h + step
cur[2].append((h, v))
else:
if cur is not None:
runs.append(cur)
cur = [h, h + step, [(h, v)]]
elif cur is not None:
runs.append(cur)
cur = None
if cur is not None:
runs.append(cur)
return runs
def merge(runs, gap_h, chained=True):
"""note 004's rule: intervals whose starts are gap_h or less apart are one storm (chained: each start against the one before)."""
storms = []
for r in runs:
if storms:
ref = storms[-1]["last_start"] if chained else storms[-1]["start"]
if r[0] - ref <= gap_h:
s = storms[-1]
s["end"], s["last_start"] = r[1], r[0]
s["values"].extend(r[2])
s["n_intervals"] += 1
continue
storms.append({"start": r[0], "last_start": r[0], "end": r[1], "values": list(r[2]), "n_intervals": 1})
return storms
def chain(series, step, test, gap_h, anchored=False):
"""The rule the note's own storm lists follow (Storms_all_strata_24h.csv): every hour, or three-hour interval, at the
level joins the storm before it when it starts gap_h or less after that storm's latest hour at the level
(anchored: after the storm's first hour). Checked against the note's list by check_note_lists()."""
storms = []
for h in sorted(series):
v = series[h]
if not test(v):
continue
if storms:
s = storms[-1]
if h - (s["start"] if anchored else s["last_start"]) <= gap_h:
if h != s["end"]:
s["n_intervals"] += 1
s["end"], s["last_start"] = h + step, h
s["values"].append((h, v))
continue
storms.append({"start": h, "last_start": h, "end": h + step, "values": [(h, v)], "n_intervals": 1})
return storms
def count_set(series, step, test):
runs = intervals(series, step, test)
past_h = hidx(PAST_BEFORE)
out = {}
tally = lambda st: {"all": len(st), "past": sum(1 for s in st if s["start"] < past_h)}
primary = chain(series, step, test, 24)
out["N_chained_24h"] = tally(primary) # the note's lists' rule: the count the page uses
out["N_anchored_24h"] = tally(chain(series, step, test, 24, True))
out["N_chained_48h"] = tally(chain(series, step, test, 48))
# our first reading of the note's sentence, as registered in RULES_storm_count.txt: runs joined by their starts
for name, gap, chained in (("M_chained_24h", 24, True), ("M_anchored_24h", 24, False),
("M_chained_48h", 48, True), ("M_anchored_48h", 48, False)):
out[name] = tally(merge(runs, gap, chained))
days, n_samples = set(), 0
for r in runs:
h = r[0]
while h < r[1]:
days.add(hdate(h).date())
n_samples += 1
h += step
out["U_intervals"] = {"all": len(runs), "past": sum(1 for r in runs if r[0] < past_h)}
out["U_days"] = {"all": len(days), "past": sum(1 for d in days if dt.datetime(d.year, d.month, d.day) < PAST_BEFORE)}
out["U_samples"] = {"all": n_samples, "past": sum((min(r[1], past_h) - r[0]) // step for r in runs if r[0] < past_h)}
return out, primary
def florida_match(storms, records):
"""a record matches a storm when its UT days lie within 36 h of the storm's span (the note's hit rule)"""
hits = {}
for d0, d1, kind in records:
a = hidx(dt.datetime.strptime(d0, "%Y-%m-%d")) - 36
b = hidx(dt.datetime.strptime(d1, "%Y-%m-%d")) + 24 + 36
for i, s in enumerate(storms):
if s["start"] < b and s["end"] > a:
hits.setdefault(i, []).append("%s..%s: %s" % (d0, d1, kind))
return hits
def part_C(dst, dst_kinds, gfz):
kp = kp_series(gfz)
res = {"rules": "RULES_storm_count.txt",
"terms": "Dst: WDC for Geomagnetism, Kyoto, final and provisional values only; scientific, non-commercial use, with "
"acknowledgement of the WDC and the observatories. Kp: GFZ, CC BY 4.0.",
"dst": {"first_month": "%04d-%02d" % DST_FIRST, "last_month": "%04d-%02d" % DST_LAST,
"final_months": dst_kinds["final"], "provisional_months": dst_kinds["provisional"], "hours": len(dst)},
"kp": {"first_day": min(gfz).isoformat(), "last_definitive_day": max(d for d in gfz if gfz[d]["D"] >= 1).isoformat(),
"intervals": len(kp)},
"past_means_storms_starting_before": PAST_BEFORE.date().isoformat()}
a, b = hidx(dt.datetime(2023, 3, 23)), hidx(dt.datetime(2023, 3, 26))
lo = min((dst[h], h) for h in range(a, b) if h in dst)
hi = max((kp[h], h) for h in range(a, b) if h in kp)
res["march_2023"] = {"dst_min": lo[0], "dst_min_hour_start_UT": hdate(lo[1]).isoformat(), "kp_max_thirds": hi[0],
"kp_max_interval_start_UT": hdate(hi[1]).isoformat(),
"hours_at_or_below_-163": sum(1 for h in range(a, b) if dst.get(h, 0) <= -163),
"intervals_at_or_above_8o": sum(1 for h in range(a, b) if kp.get(h, 0) >= 24)}
res["dst_ladder"], res["kp_ladder"] = {}, {}
storms_163 = storms_8o = None
for thr in DST_LADDER:
c, st = count_set(dst, 1, lambda v, t=thr: v <= t)
res["dst_ladder"][str(thr)] = c
if thr == -163:
storms_163 = st
for name, thr in KP_LADDER:
c, st = count_set(kp, 3, lambda v, t=thr: v >= t)
res["kp_ladder"][name] = c
if name == "8o":
storms_8o = st
d163, k8o = res["dst_ladder"]["-163"], res["kp_ladder"]["8o"]
years_dst = (PAST_BEFORE - dt.datetime(DST_FIRST[0], DST_FIRST[1], 1)).days / 365.25
years_kp = (PAST_BEFORE - dt.datetime(1932, 1, 1)).days / 365.25
res["pass_mark"] = {
"over_400_at_march_2023_level": d163["N_chained_24h"]["past"] > 400 or k8o["N_chained_24h"]["past"] > 400,
"dst_163_past_storms": d163["N_chained_24h"]["past"], "kp_8o_past_storms": k8o["N_chained_24h"]["past"],
"kp_8m_past_storms_noaa_g4": res["kp_ladder"]["8-"]["N_chained_24h"]["past"],
"dst_100_past_storms": res["dst_ladder"]["-100"]["N_chained_24h"]["past"],
"share_of_dst_100_past_storms_weaker_than_march_2023_pct":
100.0 * (1 - d163["N_chained_24h"]["past"] / res["dst_ladder"]["-100"]["N_chained_24h"]["past"]),
"by_the_reading_first_registered": {"dst_163": d163["M_chained_24h"]["past"], "kp_8o": k8o["M_chained_24h"]["past"],
"kp_8m": res["kp_ladder"]["8-"]["M_chained_24h"]["past"],
"dst_100": res["dst_ladder"]["-100"]["M_chained_24h"]["past"]},
"years_of_record_before_2023-03-23": {"dst_from_1957": years_dst, "kp_from_1932": years_kp},
# a rough guide only: the measured yearly rates carried back to September 1859, where the report's chart begins
"if_the_measured_rates_held_from_1859-09": {
"years": (PAST_BEFORE - dt.datetime(1859, 9, 1)).days / 365.25,
"dst_163": d163["N_chained_24h"]["past"] / years_dst * (PAST_BEFORE - dt.datetime(1859, 9, 1)).days / 365.25,
"kp_8o": k8o["N_chained_24h"]["past"] / years_kp * (PAST_BEFORE - dt.datetime(1859, 9, 1)).days / 365.25,
"kp_8m": res["kp_ladder"]["8-"]["N_chained_24h"]["past"] / years_kp * (PAST_BEFORE - dt.datetime(1859, 9, 1)).days / 365.25},
"unmerged_counts_past": {"dst_intervals": d163["U_intervals"]["past"], "dst_days": d163["U_days"]["past"],
"dst_hours": d163["U_samples"]["past"], "kp_intervals": k8o["U_intervals"]["past"],
"kp_days": k8o["U_days"]["past"], "kp_3h": k8o["U_samples"]["past"]},
"ladder_levels_with_more_than_400_past_storms": {
"dst": [t for t in DST_LADDER if res["dst_ladder"][str(t)]["N_chained_24h"]["past"] > 400],
"kp": [n for n, _ in KP_LADDER if res["kp_ladder"][n]["N_chained_24h"]["past"] > 400]}}
past_h = hidx(PAST_BEFORE)
for label, storms, ext in (("florida_dst_163", storms_163, min), ("florida_kp_8o", storms_8o, max)):
hits, weak = florida_match(storms, FLORIDA_NOV1), florida_match(storms, FLORIDA_WEAK)
rows = []
for i, s in enumerate(storms):
extreme = ext(v for _, v in s["values"])
when = min(h for h, v in s["values"] if v == extreme) # the first hour (or interval) at the extreme
rows.append({"start_UT": hdate(s["start"]).isoformat(), "end_UT": hdate(s["end"]).isoformat(), "extreme": extreme,
"extreme_from_UT": hdate(when).isoformat(), "n_intervals": s["n_intervals"], "past": s["start"] < past_h,
"florida_named": hits.get(i, []), "florida_weak": weak.get(i, [])})
def era(a_year, b_year, past):
sel = [r for r in rows if a_year <= int(r["start_UT"][:4]) < b_year and r["past"] == past]
named = sum(1 for r in sel if r["florida_named"])
weak_only = sum(1 for r in sel if r["florida_weak"] and not r["florida_named"])
return {"storms": len(sel), "florida_named": named, "inferred_or_lead": weak_only, "no_record_found": len(sel) - named - weak_only}
by_decade = {}
for r in rows:
if r["past"]:
dec = int(r["start_UT"][:4]) // 10 * 10
by_decade[str(dec)] = by_decade.get(str(dec), 0) + 1
res[label] = {"before_2000": era(1900, 2000, True), "from_2000_to_2023-03-22": era(2000, 2100, True),
"all_past": era(1900, 2100, True), "since_2023-03-23": era(1900, 2100, False),
"past_by_decade": by_decade, "storms": rows}
say("C March 2023: lowest Dst %d nT in the hour from %s; highest Kp %d/3 from %s"
% (lo[0], hdate(lo[1]).isoformat(), hi[0], hdate(hi[1]).isoformat()))
say("C storms before it at least as strong: %d by Dst (since 1957), %d by Kp (since 1932); over 400? %s"
% (d163["N_chained_24h"]["past"], k8o["N_chained_24h"]["past"], "yes" if res["pass_mark"]["over_400_at_march_2023_level"] else "no"))
say("C ladder, past storms: " + ", ".join("Dst<=%d: %d" % (t, res["dst_ladder"][str(t)]["N_chained_24h"]["past"]) for t in DST_LADDER))
say("C " + ", ".join("Kp>=%s: %d" % (n, res["kp_ladder"][n]["N_chained_24h"]["past"]) for n, _ in KP_LADDER))
say("C by the reading first registered (runs joined by their starts): %d and %d"
% (d163["M_chained_24h"]["past"], k8o["M_chained_24h"]["past"]))
f = res["florida_dst_163"]
say("C Florida named, by Dst: %d of %d before 2000; %d of %d in 2000-2023; %d of %d since"
% (f["before_2000"]["florida_named"], f["before_2000"]["storms"], f["from_2000_to_2023-03-22"]["florida_named"],
f["from_2000_to_2023-03-22"]["storms"], f["since_2023-03-23"]["florida_named"], f["since_2023-03-23"]["storms"]))
return res
# ------------------------------------------------------------------ cycles
def span(c, kind, nlike=N_LIKE):
i = [x[0] for x in CYCLES].index(c)
y, m = CYCLES[i][1], CYCLES[i][2]
if kind == "like":
return (y, m), add_months(y, m, nlike)
if i + 1 < len(CYCLES):
return (y, m), (CYCLES[i + 1][1], CYCLES[i + 1][2])
return (y, m), add_months(y, m, N_LIKE)
def in_span(d, a, b):
return a <= (d.year, d.month) < b
def read_silso(path):
out = {}
for line in open(path, encoding="utf-8", errors="replace"):
p = [x.strip() for x in line.split(";")]
if len(p) >= 4 and float(p[3]) >= 0 and (int(p[0]), int(p[1])) <= SN_UNTIL:
out[(int(p[0]), int(p[1]))] = float(p[3])
return out
def storm_starts(series, step, test):
return [hdate(s["start"]) for s in chain(series, step, test, 24)]
def check_note_lists(folder, dst, gfz):
"""If the note's own storm list, Storms_all_strata_24h.csv, is in the folder, compare our storms with it, stratum by
stratum, start and end times alike. The file is S0 News's and carries no licence, so we do not host or fetch it: it is in
the Drive folder the note links. Without it the check is skipped and the result says so."""
path = os.path.join(folder, "Storms_all_strata_24h.csv")
if not os.path.exists(path):
return {"run": False, "why": "Storms_all_strata_24h.csv (the note's own list, not hosted) was not in the folder"}
kp = kp_series(gfz)
strata = {"Kp>=9-": (kp, 3, lambda v: v >= 26), "Kp>=8-": (kp, 3, lambda v: v >= 23), "Kp>=8o": (kp, 3, lambda v: v >= 24),
"Dst<=-200": (dst, 1, lambda v: v <= -200), "Dst<=-300": (dst, 1, lambda v: v <= -300)}
theirs = {k: [] for k in strata}
lines = open(path, encoding="utf-8-sig").read().splitlines()
head = lines[0].split(",")
i_s, i_a, i_b = head.index("stratum"), head.index("start_UT"), head.index("end_UT")
for line in lines[1:]:
f = line.split(",")
if len(f) > i_b and f[i_s] in theirs:
theirs[f[i_s]].append((f[i_a], f[i_b]))
first = min(a for rows in theirs.values() for a, _ in rows)[:4] + "-01-01T00:00:00"
out = {"run": True, "file_sha256": sha_file(path), "strata": {}, "all_equal": True}
for name, (series, step, test) in strata.items():
last = "2026-10-30T14:00:00" # the note's data freeze (its Methods)
ours = [(hdate(s["start"]).isoformat(), hdate(s["last_start"]).isoformat()) for s in chain(series, step, test, 24)]
ours = [(a, b) for a, b in ours if first <= a <= last]
ours_reg = [hdate(s["start"]).isoformat() for s in merge(intervals(series, step, test), 24, True)]
ours_reg = [a for a in ours_reg if first <= a <= last]
same = sorted(ours) == sorted(theirs[name])
out["strata"][name] = {"the_note": len(theirs[name]), "ours": len(ours), "every_start_and_end_equal": same,
"by_the_reading_first_registered": len(ours_reg)}
out["all_equal"] = out["all_equal"] and same
say("C the note's own storm list: " + ", ".join("%s %d/%d%s" % (k, v["ours"], v["the_note"], "" if v["every_start_and_end_equal"] else " DIFFERS")
for k, v in out["strata"].items()))
return out
NO_TENTHS = [] # dates of M and X flares that NOAA NCEI's reports list without a tenths digit
def read_ngdc_flares(inp):
"""NOAA NCEI's reports, 1975-2016, on the operational scale of the time: (date, time of maximum, class letter, mantissa)"""
out = []
for y in range(1975, 2017):
name = "goes-xrs-report_%d.txt" % y
if y == 2015:
name = "goes-xrs-report_2015_modifiedreplacedmissingrows.txt"
seen = set()
for line in open(inp.file(name, NGDC + name), encoding="ascii", errors="replace"):
if len(line) < 63 or line[:5] != "31777" or line[59] not in "ABCMX":
continue
yy, mm, dd = int(line[5:7]), int(line[7:9]), int(line[9:11])
year = 1900 + yy if yy >= 70 else 2000 + yy
a, b = line[60:62].strip(), line[62:63].strip()
if not a.isdigit():
continue
mant = int(a) + (int(b) / 10.0 if b.isdigit() else 0.0)
if not b.isdigit() and line[59] in "MX":
NO_TENTHS.append("%04d-%02d-%02d" % (year, mm, dd))
key = (year, mm, dd, line[13:17], line[23:27], line[59], mant)
if key in seen:
continue
seen.add(key)
try:
out.append((dt.date(year, mm, dd), line[23:27].strip(), line[59], mant))
except ValueError:
continue
return out
def read_swpc_flares(inp):
"""NOAA SWPC's edited events, 2017-2026: the XRA lines. A flare entered twice (same day, start, peak and class) counts once."""
out, seen = [], set()
def take(text, fallback):
m = re.search(r":Date:\s+(\d{4})\s+(\d{2})\s+(\d{2})", text)
d = dt.date(int(m.group(1)), int(m.group(2)), int(m.group(3))) if m else fallback
for line in text.splitlines():
if " XRA " not in line:
continue
mc = re.search(r"\b([ABCMX])(\d+\.\d)\b", line[48:])
if not mc:
continue
p = line.replace("+", " ").split()
key = (d, p[1], p[2], mc.group(1), mc.group(2))
if key in seen:
continue
seen.add(key)
out.append((d, p[2], mc.group(1), float(mc.group(2))))
for y in range(2017, 2026):
name = "%d_events.tar.gz" % y
tf = tarfile.open(inp.file(name, SWPC_W + "%d/%s" % (y, name)), "r:gz")
for mem in tf.getmembers(): # members are read in memory; nothing is extracted to disk
if mem.isfile() and mem.name.endswith("events.txt"):
base = os.path.basename(mem.name)
take(tf.extractfile(mem).read().decode("ascii", "replace"), dt.date(int(base[:4]), int(base[4:6]), int(base[6:8])))
for day in X_DAYS_2026:
name = day + "events.txt"
path = inp.file(name, SWPC_W + "2026/2026_events/" + name)
take(open(path, encoding="ascii", errors="replace").read(), dt.date(int(day[:4]), int(day[4:6]), int(day[6:8])))
return [f for f in out if f[0].year >= 2017 and f[0] <= FLARES_UNTIL]
def read_dsd_x(inp):
"""X-class flares per year in SWPC's Daily Solar Data, 1997 to October 31, 2026 (a check on the lists)"""
names = ["%d_DSD.txt" % y for y in range(1997, 2019)] + ["%dQ%d_DSD.txt" % (y, q) for y in range(2019, 2027) for q in (1, 2, 3, 4)]
tot = {}
for name in names:
for line in open(inp.file(name, SWPC_I + name), encoding="ascii", errors="replace"):
p = line.split()
if line.startswith((":", "#")) or len(p) < 12 or not (len(p[0]) == 4 and p[0].isdigit() and p[1].isdigit() and p[2].isdigit()):
continue
d = dt.date(int(p[0]), int(p[1]), int(p[2]))
if d > FLARES_UNTIL:
continue
try:
x = int(p[11])
except ValueError:
continue
if x > 0:
tot[d.year] = tot.get(d.year, 0) + x
else:
tot.setdefault(d.year, 0)
return tot
def part_S(inp, dst, gfz):
cyc = [c for c, _, _ in CYCLES]
sn = read_silso(inp.file("SN_m_tot_V2.0.csv"))
sms = read_silso(inp.file("SN_ms_tot_V2.0.csv"))
res = {"rules": "RULES_sun.txt",
"terms": "Sunspot number: WDC-SILSO, Royal Observatory of Belgium, Brussels, CC BY-NC 4.0. Kp, Ap: GFZ, CC BY 4.0. "
"F10.7: DRAO/NRCan through GFZ's file. Dst: WDC Kyoto, final and provisional only, scientific non-commercial "
"use. Flares: NOAA NCEI and NOAA SWPC.",
"cycle_starts": {str(c): "%04d-%02d" % (y, m) for c, y, m in CYCLES}, "like_for_like_months": N_LIKE,
"like_for_like_months_dst": N_LIKE_DST}
def smooth(y, m): # the 13-month smoothing, half weights at the ends
tot = w = 0.0
for k in range(-6, 7):
key = add_months(y, m, k)
if key not in sn:
return None
wt = 0.5 if abs(k) == 6 else 1.0
tot += wt * sn[key]
w += wt
return tot / w
s1 = {}
for c in cyc:
a, b = span(c, "whole")
best = bests = None
for key in month_range(a, b):
v = smooth(*key)
if v is not None and (best is None or v > best[0]):
best = (v, key)
if key in sms and (bests is None or sms[key] > bests[0]):
bests = (sms[key], key)
s1[c] = {"ours": round(best[0], 1), "ours_month": "%04d-%02d" % best[1], "silso_smoothed_file": bests[0],
"silso_month": "%04d-%02d" % bests[1], "silso_table": SILSO_TABLE_MAX[c]}
res["S1_smoothed_max"] = {str(c): s1[c] for c in cyc}
res["S1_ratio_c25_to"] = {str(c): round(s1[25]["silso_table"] / s1[c]["silso_table"], 4) for c in cyc if c != 25}
def mean_sn(a, b):
vals = [sn[k] for k in month_range(a, b) if k in sn]
return sum(vals) / len(vals), len(vals)
s2 = {c: (mean_sn(*span(c, "like")), mean_sn(*span(c, "whole"))) for c in cyc}
res["S2_mean_sn"] = {str(c): {"first_83_months": round(s2[c][0][0], 1), "months": s2[c][0][1],
"whole_cycle": round(s2[c][1][0], 1), "whole_months": s2[c][1][1]} for c in cyc}
res["S2_ratio_c25_to"] = {str(c): {"first_83_months": round(s2[25][0][0] / s2[c][0][0], 4),
"c25_so_far_over_whole_cycle": round(s2[25][0][0] / s2[c][1][0], 4)} for c in cyc if c != 25}
vals = [(d, gfz[d]["f107adj"]) for d in sorted(gfz) if gfz[d]["f107adj"] > 0]
acc, floor = 0.0, None
for i, (d, v) in enumerate(vals):
acc += v
if i >= 365:
acc -= vals[i - 365][1]
if i >= 364 and (vals[i][0] - vals[i - 364][0]).days <= 380:
mm = acc / 365.0
if floor is None or mm < floor[0]:
floor = (mm, vals[i][0].isoformat())
def mean_daily(key, a, b, ok):
v = [gfz[d][key] for d in gfz if in_span(d, a, b) and ok(gfz[d][key])]
return (sum(v) / len(v), len(v)) if v else (None, 0)
s3, s4 = {}, {}
for c in cyc:
if c >= 19:
s3[c] = (mean_daily("f107adj", *span(c, "like"), ok=lambda v: v > 0), mean_daily("f107adj", *span(c, "whole"), ok=lambda v: v > 0),
mean_daily("f107obs", *span(c, "like"), ok=lambda v: v > 0))
if c >= 17:
s4[c] = (mean_daily("Ap", *span(c, "like"), ok=lambda v: v >= 0), mean_daily("Ap", *span(c, "whole"), ok=lambda v: v >= 0))
res["S3_f107"] = {
"floor_lowest_365_day_mean_adj": round(floor[0], 1), "floor_window_ends": floor[1],
"by_cycle": {str(c): {"first_83_months_adj": round(s3[c][0][0], 1), "days": s3[c][0][1], "whole_cycle_adj": round(s3[c][1][0], 1),
"first_83_months_obs": round(s3[c][2][0], 1),
"first_83_months_adj_above_floor": round(s3[c][0][0] - floor[0], 1)} for c in s3},
"ratio_c25_to": {str(c): {"first_83_months_adj": round(s3[25][0][0] / s3[c][0][0], 4),
"first_83_months_above_floor": round((s3[25][0][0] - floor[0]) / (s3[c][0][0] - floor[0]), 4)}
for c in s3 if c != 25}}
res["S4_Ap"] = {
"by_cycle": {str(c): {"first_83_months": round(s4[c][0][0], 2), "days": s4[c][0][1], "whole_cycle": round(s4[c][1][0], 2)} for c in s4},
"ratio_c25_to": {str(c): {"first_83_months": round(s4[25][0][0] / s4[c][0][0], 4),
"c25_so_far_over_whole_cycle": round(s4[25][0][0] / s4[c][1][0], 4)} for c in s4 if c != 25}}
kp = kp_series(gfz)
s5 = {"kp": {}, "dst": {}}
for name, thr in (("8-", 23), ("8o", 24), ("9-", 26), ("9o", 27)):
st = storm_starts(kp, 3, lambda v, t=thr: v >= t)
s5["kp"][name] = {str(c): {"first_83_months": sum(1 for d in st if in_span(d, *span(c, "like"))),
"whole_cycle": sum(1 for d in st if in_span(d, *span(c, "whole")))} for c in cyc if c >= 17}
for thr in (-100, -163, -200, -250):
st = storm_starts(dst, 1, lambda v, t=thr: v <= t)
s5["dst"][str(thr)] = {str(c): {"first_82_months": sum(1 for d in st if in_span(d, *span(c, "like", N_LIKE_DST))),
"whole_cycle": sum(1 for d in st if in_span(d, *span(c, "whole")))} for c in cyc if c >= 20}
s5["dst"][str(thr)]["19 (from 1957-01 only)"] = {"whole_cycle": sum(1 for d in st if in_span(d, (1957, 1), (1964, 10)))}
res["S5_great_storms"] = s5
unit = {"A": 1e-8, "B": 1e-7, "C": 1e-6, "M": 1e-5, "X": 1e-4}
flares = [(d, mant * unit[cls], "old", tmax) for d, tmax, cls, mant in read_ngdc_flares(inp)]
flares += [(d, mant * unit[cls], "old" if d.year <= 2019 else "new", tmax) for d, tmax, cls, mant in read_swpc_flares(inp)]
seen, uniq = set(), []
for f in flares:
key = (f[0], f[3], round(f[1] * 1e7))
if key not in seen:
seen.add(key)
uniq.append(f)
flares = uniq
today = lambda f: f[1] / 0.7 if f[2] == "old" else f[1] # the flux on the scale used since GOES-16
by_year = {}
for f in flares:
if f[1] >= 1e-4 - 1e-12:
by_year[f[0].year] = by_year.get(f[0].year, 0) + 1
dsd = read_dsd_x(inp)
s7 = {"x_class_as_listed_by_year": {str(y): by_year[y] for y in sorted(by_year)},
"x_class_in_swpc_daily_data_by_year": {str(y): dsd[y] for y in sorted(dsd)},
"years_1997_2026_where_the_two_differ": {str(y): [by_year.get(y, 0), dsd[y]] for y in sorted(dsd) if by_year.get(y, 0) != dsd[y]},
"by_cycle": {}}
for c in (21, 22, 23, 24, 25):
row = {}
for kind, label in (("like", "first_83_months"), ("whole", "whole_cycle")):
a, b = span(c, kind)
sel = [f for f in flares if in_span(f[0], a, b)]
big = max(sel, key=lambda f: f[1])
row[label] = {"X1_or_more_as_listed": sum(1 for f in sel if f[1] >= 1e-4 - 1e-12),
"X10_or_more_as_listed": sum(1 for f in sel if f[1] >= 1e-3 - 1e-12),
"X1_or_more_on_todays_scale": sum(1 for f in sel if today(f) >= 1e-4 - 1e-12),
"X10_or_more_on_todays_scale": sum(1 for f in sel if today(f) >= 1e-3 - 1e-12),
"largest_as_listed": ("X%.0f on %s" if big[0].isoformat() in NO_TENTHS else "X%.1f on %s") % (big[1] / 1e-4, big[0].isoformat()),
"largest_on_todays_scale": ("X%.0f" if big[0].isoformat() in NO_TENTHS else "X%.1f") % (today(big) / 1e-4)}
s7["by_cycle"][str(c)] = row
top25 = sorted([f for f in flares if in_span(f[0], *span(25, "like"))], key=lambda f: -f[1])[:10]
s7["cycle_25_ten_largest"] = ["X%.1f %s" % (f[1] / 1e-4, f[0].isoformat()) for f in top25]
s7["largest_25_on_todays_scale"] = ["X%.1f %s (listed X%.1f)" % (today(f) / 1e-4, f[0].isoformat(), f[1] / 1e-4)
for f in sorted(flares, key=lambda f: -today(f))[:25]]
def cls_name(flux):
return ("X%.1f" % (flux / 1e-4)) if flux >= 1e-4 - 1e-12 else ("M%.1f" % (flux / 1e-5))
def largest_before(d0):
"""the largest listed flare in the seven days before a storm's first day (that day itself left out)"""
day = dt.date.fromisoformat(d0)
sel = [f for f in flares if day - dt.timedelta(days=7) <= f[0] < day]
big = max(sel, key=lambda f: f[1])
return {"as_listed": cls_name(big[1]), "on": big[0].isoformat(), "on_todays_scale": cls_name(today(big)),
"x_class_as_listed_in_those_days": sum(1 for f in sel if f[1] >= 1e-4 - 1e-12)}
s7["largest_flare_in_the_7_days_before"] = {d0: largest_before(d0) for d0 in
("1989-03-13", "2000-04-06", "2001-11-06", "2003-10-29", "2003-11-20")}
s7["classes_listed_without_tenths"] = {"first": min(NO_TENTHS), "last": max(NO_TENTHS), "m_and_x_flares": len(NO_TENTHS),
"of_them_after_1980-04-28": sum(1 for x in NO_TENTHS if x > "1980-04-28"),
"m_and_x_flares_with_tenths_before_1980-04-29": sum(1 for f in flares if f[2] == "old" and f[0].isoformat() < "1980-04-29" and f[1] >= 1e-5 - 1e-12) - sum(1 for x in NO_TENTHS if x <= "1980-04-28")} if NO_TENTHS else {}
s7["note"] = ("Lists before GOES-16 are on the old operational scale; 'on today's scale' divides their classes by 0.7. NOAA "
"states that factor for GOES-8 to -15, whose data were scaled to match GOES-7; for the lists of GOES-1 to -7 "
"(Cycles 21 and 22) applying it is our inference. The lists to April 1980 give classes without tenths, and the "
"largest flares saturated the sensors, so their listed classes are floors. A flare of May 8, 2024 that SWPC's "
"list enters twice is counted once. The ten days of 2026 read from SWPC's event lists were chosen from its daily "
"summaries, so for 2026 the comparison of the two is not independent.")
res["S7_x_flares"] = s7
half_s1 = [c for c in range(15, 24) if s1[25]["silso_table"] / s1[c]["silso_table"] <= 0.60]
half_s2 = [c for c in range(15, 24) if s2[25][0][0] / s2[c][0][0] <= 0.60]
n = min(len(half_s1), len(half_s2))
res["reading_half"] = {"cycles_15_23_where_c25_is_0.60_or_less_by_S1": half_s1, "by_S2_like_for_like": half_s2,
"outcome": "holds" if n >= 5 else ("holds in part" if max(len(half_s1), len(half_s2)) >= 1 else "fails")}
res["reading_rank"] = {"S1_rank_of_c25_among_cycles_15_25": 1 + sum(1 for c in cyc if s1[c]["silso_table"] > s1[25]["silso_table"]),
"S2_like_for_like_rank": 1 + sum(1 for c in cyc if s2[c][0][0] > s2[25][0][0]), "of": len(cyc)}
say("S smoothed maximum, Cycle 25 / cycle: " + ", ".join("C%d %.2f" % (c, s1[25]["silso_table"] / s1[c]["silso_table"]) for c in cyc if c != 25))
say("S mean sunspot number, first 83 months: " + ", ".join("C%d %.2f" % (c, s2[25][0][0] / s2[c][0][0]) for c in cyc if c != 25))
say("S 'half': %s; rank of Cycle 25: %d of 11 by maximum, %d like for like"
% (res["reading_half"]["outcome"], res["reading_rank"]["S1_rank_of_c25_among_cycles_15_25"], res["reading_rank"]["S2_like_for_like_rank"]))
say("S X-class flares on today's scale, first 83 months: " + ", ".join(
"C%s %d" % (c, s7["by_cycle"][c]["first_83_months"]["X1_or_more_on_todays_scale"]) for c in s7["by_cycle"]))
say("S years where our list count differs from SWPC's daily data:", s7["years_1997_2026_where_the_two_differ"] or "none")
return res
# ------------------------------------------------------------------ field (B-splines and IGRF, after special_report_numbers.py)
def span_index(nb, p, u, U):
if u >= U[nb]:
return nb - 1
if u <= U[p]:
return p
lo, hi = p, nb
mid = (lo + hi) // 2
while u < U[mid] or u >= U[mid + 1]:
lo, hi = (lo, mid) if u < U[mid] else (mid, hi)
mid = (lo + hi) // 2
return mid
def basis_derivs(i, u, p, n, U):
"""Non-zero B-splines and their derivatives (Piegl and Tiller, The NURBS Book, algorithm A2.3)."""
ndu = [[0.0] * (p + 1) for _ in range(p + 1)]
left, right = [0.0] * (p + 1), [0.0] * (p + 1)
ndu[0][0] = 1.0
for j in range(1, p + 1):
left[j], right[j] = u - U[i + 1 - j], U[i + j] - u
saved = 0.0
for r in range(j):
ndu[j][r] = right[r + 1] + left[j - r]
temp = ndu[r][j - 1] / ndu[j][r]
ndu[r][j] = saved + right[r + 1] * temp
saved = left[j - r] * temp
ndu[j][j] = saved
ders = [[0.0] * (p + 1) for _ in range(n + 1)]
for j in range(p + 1):
ders[0][j] = ndu[j][p]
a = [[0.0] * (p + 1) for _ in range(2)]
for r in range(p + 1):
s1, s2 = 0, 1
a[0][0] = 1.0
for k in range(1, n + 1):
d, rk, pk = 0.0, r - k, p - k
if r >= k:
a[s2][0] = a[s1][0] / ndu[pk + 1][rk]
d = a[s2][0] * ndu[rk][pk]
j1 = 1 if rk >= -1 else -rk
j2 = k - 1 if (r - 1) <= pk else p - r
for j in range(j1, j2 + 1):
a[s2][j] = (a[s1][j] - a[s1][j - 1]) / ndu[pk + 1][rk + j]
d += a[s2][j] * ndu[rk + j][pk]
if r <= pk:
a[s2][k] = -a[s1][k - 1] / ndu[pk + 1][r]
d += a[s2][k] * ndu[r][pk]
ders[k][r] = d
s1, s2 = s2, s1
r = p
for k in range(1, n + 1):
for j in range(p + 1):
ders[k][j] *= r
r *= (p - k)
return ders
class Chaos:
"""CHAOS-8.7's core field as B-splines: the three dipole coefficients g10, g11, h11 and their time derivatives."""
def __init__(self, path):
nums, header = [], None
with open(path, encoding="ascii") as f:
for line in f:
s = line.strip()
if not s or s.startswith("#"):
continue
parts = s.split()
if header is None:
try:
vals = [int(x) for x in parts]
except ValueError:
continue
if len(vals) == 3:
header = vals
continue
nums.extend(float(x) for x in parts)
nmax, self.nspl, order = header
n = nmax * (nmax + 2)
self.p = order - 1
self.knots, vals = nums[:self.nspl + order], nums[self.nspl + order:]
assert len(vals) == self.nspl * n, "unexpected layout in the CHAOS file"
self.coefs = [vals[j * n:j * n + 3] for j in range(self.nspl)]
self.t_first, self.t_last = self.knots[order - 1], self.knots[self.nspl]
def dip(self, t, deriv=0):
i = span_index(self.nspl, self.p, t, self.knots)
w = basis_derivs(i, t, self.p, deriv, self.knots)[deriv]
return [sum(w[j] * self.coefs[i - self.p + j][q] for j in range(self.p + 1)) for q in range(3)]
def igrf_g10(path, t):
epochs, row = None, None
with open(path, encoding="ascii") as f:
for line in f:
if line.startswith("g/h"):
epochs = [float(x) for x in line.split()[3:-1]]
elif line.split()[:3] == ["g", "1", "0"]:
row = [float(x) for x in line.split()[3:]]
main, sv = row[:-1], row[-1]
if t >= epochs[-1]:
return main[-1] + (t - epochs[-1]) * sv
i0 = max(i for i, e in enumerate(epochs) if e <= t)
return main[i0] + (t - epochs[i0]) / (epochs[i0 + 1] - epochs[i0]) * (main[i0 + 1] - main[i0])
def part_F(inp):
chaos = Chaos(inp.file("CHAOS-8.7_spline-coefficients.dat"))
igrf = inp.file("igrf14coeffs.txt")
A_REF, MU = 6371.2, 1.0e-7
def state(t):
g = chaos.dip(t)
gd, gdd = chaos.dip(t, 1), chaos.dip(t, 2)
b0 = math.sqrt(g[0] ** 2 + g[1] ** 2 + g[2] ** 2)
neg = g[0] < 0 # g10 is negative today, so |g10| falls when g10 rises
return {"t": round(t, 3), "abs_g10_nT": abs(g[0]), "M_1e22_Am2": (A_REF * 1e3) ** 3 * (b0 * 1e-9) / MU / 1e22,
"loss_rate_nT_per_yr": gd[0] if neg else -gd[0], "loss_accel_nT_per_yr2": gdd[0] if neg else -gdd[0],
"tilt_deg": math.degrees(math.acos(-g[0] / b0)), "b0_nT": b0}
g10 = lambda t: abs(chaos.dip(t)[0])
res = {"rules": "RULES_field.txt", "chaos_valid_span": [round(chaos.t_first, 3), round(chaos.t_last, 3)],
"T0": round(T0, 3), "T1": round(T1, 3), "T0_date": "2023-03-23", "T1_date": "2026-08-31"}
s0, s1 = state(T0), state(T1)
d, dm, yrs = s0["abs_g10_nT"] - s1["abs_g10_nT"], s0["M_1e22_Am2"] - s1["M_1e22_Am2"], T1 - T0
fc = (abs(igrf_g10(igrf, 2025.0)) - abs(igrf_g10(igrf, 2030.0))) / 5.0
res["F1"] = {"at_T0": s0, "at_T1": s1, "years": yrs, "g10_loss_nT": d, "g10_loss_pct": 100.0 * d / s0["abs_g10_nT"],
"g10_loss_nT_per_yr": d / yrs, "M_loss_pct": 100.0 * dm / s0["M_1e22_Am2"],
"M_loss_pct_per_century": 100.0 * dm / s0["M_1e22_Am2"] / yrs * 100.0, "igrf14_forecast_2025_2030_nT_per_yr": fc}
res["F2"] = {
"yearly_loss_nT_from_january_1": [{"span": "%d-%d" % (y, y + 1), "from": "%d-01-01" % y, "to": "%d-01-01" % (y + 1),
"loss_nT": g10(float(y)) - g10(float(y + 1))} for y in range(2015, 2026)],
"part_years": [{"span": "2023-03-23 to 2024-01-01", "loss_nT_per_yr": (g10(T0) - g10(2024.0)) / (2024.0 - T0)},
{"span": "2026-01-01 to 2026-08-31", "loss_nT_per_yr": (g10(2026.0) - g10(T1)) / (T1 - 2026.0)},
{"span": "2020-03-23 to 2023-03-23", "loss_nT_per_yr": (g10(T0 - 3.0) - g10(T0)) / 3.0}],
"instantaneous": [{k: s[k] for k in ("t", "loss_rate_nT_per_yr", "loss_accel_nT_per_yr2")}
for s in (state(t) for t in (2019.0, 2020.0, T0 - 3.0, 2021.0, 2022.0, 2023.0, T0, 2024.0, 2025.0, 2026.0, T1))]}
# added for the page, after the rules: years counted from March 23, the windows /march-2023-storm/ states
res["F2"]["yearly_loss_nT_from_march_23"] = [
{"span": "%d-%d" % (2023 + k - 1, 2023 + k), "from": "%d-03-23" % (2023 + k - 1), "to": "%d-03-23" % (2023 + k),
"loss_nT": g10(T0 + k - 1) - g10(T0 + k)} for k in (0, 1, 2, 3)]
res["F2"]["rate_curve_every_0.1_yr"] = [[round(2015.0 + 0.1 * k, 1), round(state(2015.0 + 0.1 * k)["loss_rate_nT_per_yr"], 4)]
for k in range(0, 117)]
res["F3"] = {"tilt_deg_T0": s0["tilt_deg"], "tilt_deg_T1": s1["tilt_deg"]}
# added after the fresh review, to agree with /march-2023-storm/: the mean yearly loss over the two years after a date
# less that over the two years before it, at the storm and at every quarter-year from 2001
pace = lambda t: ((g10(t - 2.0) - g10(t)) / 2.0, (g10(t) - g10(t + 2.0)) / 2.0)
quarters = [2001.0 + 0.25 * k for k in range(0, 97) if 2001.0 + 0.25 * k + 2.0 <= chaos.t_last]
steps = [(pace(t)[1] - pace(t)[0], t) for t in quarters]
early = [x for x in steps if x[1] < 2020.0]
b4, aft = pace(T0)
res["F2"]["two_year_change_of_pace"] = {
"at_2023-03-23": {"mean_loss_two_years_before_nT_per_yr": b4, "mean_loss_two_years_after_nT_per_yr": aft, "step": aft - b4},
"quarter_years_2001_on": len(steps),
"largest_speeding_up_2001_2019": {"t": max(early)[1], "step": max(early)[0]},
"quarters_of_2022": [[t, x] for x, t in steps if 2022.0 <= t < 2023.0],
"largest_speeding_up_2001_on": {"t": max(steps)[1], "step": max(steps)[0]},
"largest_slowing_2001_on": {"t": min(steps)[1], "step": min(steps)[0]}}
since = [(v, t) for t, v in res["F2"]["rate_curve_every_0.1_yr"] if t > T0]
res["F2"]["rate_since_2023-03-23"] = {"lowest": {"t": min(since)[1], "nT_per_yr": min(since)[0]},
"highest": {"t": max(since)[1], "nT_per_yr": max(since)[0]}}
r_before, r_t0, r_t1 = state(T0 - 3.0)["loss_rate_nT_per_yr"], s0["loss_rate_nT_per_yr"], s1["loss_rate_nT_per_yr"]
rise_before, rise_after = r_t0 - r_before, r_t1 - r_t0
if rise_after > rise_before and r_t1 > fc + 1.0:
reading = "supported"
elif r_t1 <= r_t0 + 1.0:
reading = "contradicted"
else:
reading = "a small rise"
by2045 = d / yrs * (2045.0 - T1)
half = abs(igrf_g10(igrf, 2025.0)) / 2.0
res["readings"] = {"rate_2020-03-23": r_before, "rate_2023-03-23": r_t0, "rate_2026-08-31": r_t1,
"rise_in_the_three_years_before": rise_before, "rise_since": rise_after, "forecast": fc,
"acceleration_event_beginning_march_2023": reading,
"if_the_pace_since_march_2023_continued_to_2045": {"loss_nT": by2045, "pct_of_abs_g10_at_T1": 100.0 * by2045 / s1["abs_g10_nT"]},
"halving_abs_g10_of_2025": {"by_2045_nT_per_yr": half / 20.0, "times_forecast": half / 20.0 / fc,
"by_2036_nT_per_yr": half / 11.0, "times_forecast_2036": half / 11.0 / fc}}
say("F |g10| %.1f nT on 2023-03-23, %.1f nT on 2026-08-31: -%.1f nT (%.3f%%), %.2f nT a year; IGRF-14 forecast %.2f"
% (s0["abs_g10_nT"], s1["abs_g10_nT"], d, res["F1"]["g10_loss_pct"], d / yrs, fc))
say("F years from January 1: " + ", ".join("%s %.2f" % (r["span"], r["loss_nT"]) for r in res["F2"]["yearly_loss_nT_from_january_1"]))
say("F years from March 23: " + ", ".join("%s %.2f" % (r["span"], r["loss_nT"]) for r in res["F2"]["yearly_loss_nT_from_march_23"]))
say("F rate %.2f (March 2020), %.2f (March 2023), %.2f (August 2026): %s" % (r_before, r_t0, r_t1, reading))
return res
def main():
args = [a for a in sys.argv[1:] if not a.startswith("--")]
part = "all"
if "--part" in sys.argv:
part = sys.argv[sys.argv.index("--part") + 1]
args = [a for a in args if a != part]
folder = args[0] if args else os.path.dirname(os.path.abspath(__file__))
inp = Inputs(folder)
res = {"what": "Numbers behind https://factchecked.science/s0-news-2026-11-11/ (our analysis of public data)",
"made_by": "special_report_part2_numbers.py", "part_run": part}
outpath = os.path.join(folder, OUT_NAME)
if part != "all" and os.path.exists(outpath):
res = json.load(open(outpath, encoding="utf-8")) # keep the parts already there
res["part_run"] = "all, in parts"
dst = gfz = None
if part in ("all", "count", "cycles"):
gfz = read_gfz(inp)
dst, kinds, digest = read_kyoto(inp)
res["dst_values_sha256"] = digest
say("Dst: %d hourly values, %d final and %d provisional months; Kp definitive to %s"
% (len(dst), kinds["final"], kinds["provisional"], max(d for d in gfz if gfz[d]["D"] >= 1).isoformat()))
if part in ("all", "count"):
res["C_storm_count"] = part_C(dst, kinds, gfz)
res["C_storm_count"]["note_list_check"] = check_note_lists(folder, dst, gfz)
if part in ("all", "cycles"):
res["S_cycles"] = part_S(inp, dst, gfz)
if part in ("all", "field"):
res["F_field"] = part_F(inp)
res.setdefault("inputs_sha256", {}).update({k: v for k, v in sorted(inp.seen.items())})
with open(outpath, "w", encoding="utf-8", newline="\n") as f:
json.dump(res, f, indent=1)
f.write("\n")
say("wrote", outpath)
if __name__ == "__main__":
main()