#!/usr/bin/env python3 """Akasofu's epsilon, 1963-2026, and Earth's geomagnetic response to it: a reproduction and a test. Fact-Checked Science, November 2026, for the paper check "akasofu-epsilon-weak-field" ("Our analysis"), on Popescu, A. S. (2026), Advances in Space Research, doi:10.1016/j.asr.2026.10.093. Standard library only. It reproduces, without numpy, the two pre-registered analyses we first ran with numpy (reproduce.py and response_test.py, hosted beside it with their rules, RULES_reproduction.txt and RULES_response_test.txt), and writes every number of ours on the page. Run it python3 -I -B akasofu_epsilon.py [folder] [--dst] The folder (default: the script's own) holds, or will receive, the inputs below. A missing file is downloaded under the plain client name "factchecked-research/1.0". Each OMNI2 file and IGRF-14 is checked against the SHA-256 of the copy we used on November 11, 2026; GFZ extends its two files every day, so for those the script checks a fingerprint of the lines it uses (to October 31, 2026). A different hash or fingerprint means the maker changed the data, so numbers may differ. It prints a summary and writes akasofu-epsilon-numbers.json, epsilon-annual.csv and response-window-scores.csv into the folder. Once the files are there it takes about ten seconds. Inputs (about 223 MB) omni2_1963.dat ... omni2_2026.dat NASA's OMNI2 hourly solar-wind data (King & Papitashvili 2005), one file a year, from https://spdf.gsfc.nasa.gov/pub/data/omni/low_res_omni/ . Solar-wind hours are used up to October 15, 2026, 00 UT, the last valid hour in our copy of the 2026 file. igrf14coeffs.txt IGRF-14 Gauss coefficients (IAGA V-MOD), from NOAA Kp_ap_since_1932.txt GFZ's three-hourly Kp and ap (Matzka et al. 2021), CC BY 4.0 Hp60_ap60_complete_series.txt GFZ's hourly Hp60 and ap60, CC BY 4.0 --dst (optional) also read the World Data Center for Geomagnetism, Kyoto's monthly pages of hourly Dst, January 1995 to September 2026, into the subfolder kyoto-dst/ (381 small pages, fetched one a second, about seven minutes). Final values to December 2020 and provisional ones after; the script never requests a real-time (quicklook) page. Kyoto's data are for scientific, non-commercial use, with acknowledgement of the WDC and of the observatories (https://wdc.kugi.kyoto-u.ac.jp/wdc/Sec3.html). No hourly Dst value is written to any output: only window scores and yearly means in quiet hours. the paper's supplementary tables (optional) if you have the article's own supplementary files 1-s2.0-S0273117726015188-mmc3.csv (annual) and ...-mmc4.csv (monthly), put them in the folder and the script compares our series with them cell by cell and reports the size of the largest difference. They are the publisher's, all rights reserved; we do not host them, and nothing from them is written to the outputs but the sizes of the differences. What it computes A. The dipole proxy sqrt(g10^2 + g11^2 + h11^2) from IGRF-14 for each calendar year, relative to 1963, and its 2/3 power, the paper's scaling factor. B. Akasofu's epsilon for every valid hour by the paper's recipe (section 6.1): eps = (4 pi / mu0) V B_T^2 sin^4(theta/2) l0^2, B_T^2 = By^2 + Bz^2 (GSM), theta = atan2(By, Bz), l0 = 7 R_E, R_E = 6371 km; then monthly and annual means, the scaled series, the window means of the paper's section 7.2, the ratio B_dip / <|B|> with its regression and robust errors (HC3, Newey-West), and the correlations with Kp of its section 7.3. C. Whether 2023-2026 is unusual as an input: ranks of years and three-year windows, the windows centred on the smoothed sunspot maxima of Cycles 21-25, and what averaging the inputs first does to epsilon. D. The response test (RULES_response_test.txt): monthly ap (and Kp, and with --dst Dst) against epsilon and against Newell et al.'s (2007) function V^(4/3) B_T^(2/3) sin^(8/3)(theta/2), fitted on 1995-2022; the score of 2023-2025 beside 26 earlier three-year windows, each scored leaving its own months out; the pass mark; step and trend regressions with Newey-West errors; the hourly test on ap60 matched by input level; the partial year 2026. E. Post hoc, not registered: the size of the bias GFZ estimates for Kp from its stations' drift, set against the scores; and (with --dst) Dst in quiet hours, final years against provisional ones. F. Added after a fresh review of the built page, and not registered either. Other readings of the registered scores: the pass mark applied to each of the 26 earlier windows in turn; how many earlier windows 2023-2025 is above; the allowance for the Kp stations' drift carried through Test M, the step regression and Test H (every ap and ap60 value raised at the same yearly rate, then fits, bins and scores made again); the change in the hourly score from three years before each sunspot maximum; the quiet-level hourly scores in percent; epsilon per unit of sunspot number at five maxima; the largest ap and ap60 values in GFZ's files; and (with --dst) the yearly means of Dst in quiet hours behind section E's comparison. Conventions: UT calendar months and years; an hour is valid when flow speed, By (GSM) and Bz (GSM) are all present; nothing is imputed. A positive score means more response than the fitted relation predicts. """ import csv import datetime import hashlib import json import math import os import re import sys import time import urllib.request UA = "factchecked-research/1.0" OMNI_URL = "https://spdf.gsfc.nasa.gov/pub/data/omni/low_res_omni/omni2_%d.dat" IGRF_URL = "https://www.ngdc.noaa.gov/IAGA/vmod/coeffs/igrf14coeffs.txt" KP_URL = "https://kp.gfz.de/app/files/Kp_ap_since_1932.txt" HP_URL = "https://kp.gfz.de/app/files/Hp60_ap60_complete_series.txt" KYOTO_URL = "https://wdc.kugi.kyoto-u.ac.jp/dst_%s/%s/index.html" YEARS = list(range(1963, 2027)) OMNI_END = (2026, 10, 15, 0) # the last valid solar-wind hour in our copy of omni2_2026.dat GFZ_END = (2026, 10, 31) # GFZ's Kp was definitive to this day when we fetched it DST_END = (2026, 9) # Kyoto's last provisional month on November 11, 2026 SHA = { "igrf14coeffs.txt": "8f8d88403028fc4ee92c4f38d97b46e0a87e2cfc496045b43c9e26c1d6b0903c", # OMNI_SHA_BEGIN "omni2_1963.dat": "60e6f2dcea08dc73cfffc1fa8f5923bcfe0cf28da4c5bb51bfa4ffded0666605", "omni2_1964.dat": "59da6db7a2cc4f9d5bad42d3c0eba15ed53b7ffae31a2989aa52b7b2513249d1", "omni2_1965.dat": "ec70d3c9bddcc3dce7d0eccf74d058bda57983aa591c38d6da76052de5a0cef8", "omni2_1966.dat": "2fa856d0baadef2535049d470919f9dbc33854d289d0224ad42fc1570af13b99", "omni2_1967.dat": "3ae65713ef28738f17e8126c126c0b108ad66b9c75db45d3e06d2425c7ab68bf", "omni2_1968.dat": "b1d4c71f2d93b0589a29613b80ea1155b6f7586116869a4a9834c96bdefa0106", "omni2_1969.dat": "8bb9090254a1fbedd0d1b4dd0ec6004823c17e63ef3a1d40c03edfa2e8b2bcc7", "omni2_1970.dat": "7d64ba7e95cb30dbc6ae536c6049b8b38a7d411e4d28c7ae6db56e04e89f88d8", "omni2_1971.dat": "8235e7ebb443161860bf7ef4b61c69267a23bdbb19ead75ee3e03af5905a294c", "omni2_1972.dat": "be11befb620501125c494e92c1ddc2689d0b5c102e4a3f5ebc46a228f0fff2f1", "omni2_1973.dat": "7817d10780060ae510a170bb8223ac2a79e539b32cb6760a10efc243a714e881", "omni2_1974.dat": "3de3ec8520282ee644243e35ef68db494accf0c709fed6ede7d7dec1b2900518", "omni2_1975.dat": "1c8339eca446126ea2764d640a465799f102d212b563e1c9edc0b595f296b28e", "omni2_1976.dat": "21cc10c272abce14a58735699dfeed43ad1374ff0373f99e36658022e6b70cda", "omni2_1977.dat": "92a8f21d0933ac88b400ea054491dec1e7be73483c69f000da11eb25a4d38c3e", "omni2_1978.dat": "db9f4957c642705657c618d177f258cf1ecf0e23c8965c3594fd130cc3d29fbb", "omni2_1979.dat": "0faff764418e27d4e16eb764cf66597cea775970780210d5d60554ef01b0a461", "omni2_1980.dat": "d1452dbb163d25157bdbdb0dc611af290c399dd7eef4b976e09d5cf7e0842514", "omni2_1981.dat": "3a8f3e7628ce049b0f2b91546f9f7a567d86a9bafede3d6575ca22b503d010cc", "omni2_1982.dat": "6668238bab07acb7e5a6158518c8d0d791569070690c8592b07a35c82cf95e40", "omni2_1983.dat": "f6ae243524fe0901515f5a6829def6af5d42f7a3fdcf3b5f80c543f04ac7e879", "omni2_1984.dat": "76f00265c81101ac5059dd09bb9276bbadb21038d4a4e9733e622e362850c306", "omni2_1985.dat": "473a5c328030242efa979cbe285ab206f91fa3a9735d3bc12455c4cad1dccb98", "omni2_1986.dat": "0cd186e5ff5f28f507092eca139784ab5475a06edba908aaad3b69bb5ad6adcd", "omni2_1987.dat": "70a693a4fccbf1ca009225bf890d0b64ec1ace40c6beb9b7512ad1488572b66a", "omni2_1988.dat": "3ef3a5f064bad2681cb2b33b10478ae3c9edc9dc2c1d1a8ce3c467d4fc52f85b", "omni2_1989.dat": "a39ed8143bd29cb38cfeef9a2f659a022bae3372ef5cdb7c06766a305f3f8563", "omni2_1990.dat": "1290a18638b72fe445da3773900c2657783127f0649aaca0534b73a99b9ecca6", "omni2_1991.dat": "ba2fed18bb045578160fec83eba7065b87fc359fa9fe641c402a30934d3072cb", "omni2_1992.dat": "1fb36fcd138b53d733efad25ec90b6cb3ebf759add2307d7aa84f0ccc087d658", "omni2_1993.dat": "326eb371a75fa87603fbe94108c43ccdba22fcae2d37ea1b14e4c132878b890b", "omni2_1994.dat": "6fa13d5c396eba5fb00e494b4a8b94b98d6e3c7327fac3f8989dd7992a103350", "omni2_1995.dat": "71d17d51ca92beaea8235b3059736e7e7a471fbf0814c5c8e7d34903ccf1295a", "omni2_1996.dat": "943bf2cc51e483bd2cd7ea608e2938a4e7b2b0a76198d401d83ab7248545c059", "omni2_1997.dat": "98a68a0c41704384ddc587abf63153fe22aea9bf358787a5e649a938b53a34bd", "omni2_1998.dat": "7816dfa8f587c3bafdc5c0bc72230e42f784dbd1d95c17828731cbe24eff93c1", "omni2_1999.dat": "68d42e06f43e39093dd12513b34c07fe6be178aa783cedda834da519dbb1486c", "omni2_2000.dat": "f707f2c9fd3279839943e049b5eb6bf68a095d8caf9c47eb1a3ec39ef8768c66", "omni2_2001.dat": "778393a58ba8e5c5ac677edae058670adeed029d0a38f0c44ffbd28fc8f74555", "omni2_2002.dat": "ad0316866abee6f17741e8940d02f8199570ce8a107e2cb45c2eff01972a560a", "omni2_2003.dat": "cb1fcee0f95af4c318b239617bbb46f6e41c811bdca8464cf397eb7fd2fb7fc9", "omni2_2004.dat": "5538ae44d3476bb84eb963d6892537a085a9707a296cd57d6a1960ea43f89b90", "omni2_2005.dat": "9b99d08300d8e2a2cbeaeab073b2e0d83e31b5c925c0f465860430602ad07102", "omni2_2006.dat": "27db7ba84a0889b0438fd4428e26128a2235bcf9e30b2a77bf678fab531bf4ea", "omni2_2007.dat": "2bdae448301e6de3863e78643178628e3bcd39dee2aea111fe523d1e393217e7", "omni2_2008.dat": "3115c8f3c1d28eaca6a4ada84ca2f36865d36d2b2db1c4f8a4c4ba667ac1e274", "omni2_2009.dat": "1b8e29b6fd31b6b187dbad5499367526c8b34744f87dcc5aaaedb47c9e50f651", "omni2_2010.dat": "5a70010684b553f740b95b31fb56d6ab99b0d545c6f02b11dd84141bbd8b60cb", "omni2_2011.dat": "9a93c0e8b563a8ca6ae9c76448d2140ad00574ef65abc7a6504fdad1c3a196ce", "omni2_2012.dat": "342612e8ed98fcc5952e4f33e3de92c657d6682728722716d68930b981f87faf", "omni2_2013.dat": "46db595b661833960638cb1c44a9c90df55769907bdf1473ad5d9feb68e3d0d9", "omni2_2014.dat": "8078580877128e53904084bf22cd712b347deb33c8db5133876baa19be2f57c0", "omni2_2015.dat": "aaa291634e011715066ddcf59028e4db16d92495ebca88e4ac034edd1f0f4b19", "omni2_2016.dat": "9a2be4f3e975ff307fcfcca5fc1a5d4cb9f04942a0aae47d9c3529303b51c51e", "omni2_2017.dat": "b53494bc4fa719da1a5e6914c93307d2c9cfa1fa77abb3883e5925bfc9e0b3bc", "omni2_2018.dat": "2f4b43cc5106d856a4765581eaf277f10506c002d72d927b21eca85776ae0b04", "omni2_2019.dat": "8f4e57f313687b4fb86865dbb2df06adf414c7e496b99893b86013d91744b48e", "omni2_2020.dat": "11c2de98f1fd1ebe0156ca36c439fd4063d28c95e3706ec8752e7f59eea41700", "omni2_2021.dat": "c7a68a97abddd6842f26225b6ac5761cdb2f375aca2b5f53b752f7158ed2f211", "omni2_2022.dat": "413ac4895d24cab0af4861710c437f12efab44f3cd6c814a614815fa0f2c8d88", "omni2_2023.dat": "df74e09c22b126841835c0add8c46933b93118c33a1978f7e977f9488cf7d743", "omni2_2024.dat": "41f3b5891ce3f1220719d5c1ea808f3014f28a1704557d3363eefb5ee7c249b1", "omni2_2025.dat": "0c1cbad73ad812883a4c1ab49fbe30dda842d65efb89f5c0ea9f3447f9f52a5b", "omni2_2026.dat": "dac7c9ef50e26536b6da5cfcbacdb4c077839e7a4b2707720c6ddf9950b6dd99", # OMNI_SHA_END } FINGERPRINT = { # SHA-256 of the data lines used, to GFZ_END (GFZ) or of the parsed values (Kyoto) # FINGERPRINT_BEGIN "Hp60_ap60_complete_series.txt": "04a9d1efcf45ecf2b8caa91ec3ca87f12855e76704929f090f364afe9507cc8b", "Kp_ap_since_1932.txt": "d2bbbd70c6e9f96871d9276618ea7be100d26aaa56d204e8fe18524efd1f9f1c", "kyoto-dst": "ea956b898777d8bd80d6c4d805731ee5617a4d151627c1065f3f0bacb82bff86", # FINGERPRINT_END } MU0 = 4.0e-7 * math.pi L0 = 7.0 * 6371.0e3 K_EPS = 4.0 * math.pi / MU0 * L0 * L0 # eps [W] = K_EPS * V[m/s] * B_T[T]^2 * sin^4(theta/2) NAN = float("nan") MIN_H = 360 # valid hours a month needs to enter the response test REF = [(y, y + 2) for y in range(1995, 2021)] CYCLE_WINDOWS = ((21, 1978, 1980, "December 1979", 232.9), (22, 1988, 1990, "November 1989", 212.5), (23, 2000, 2002, "November 2001", 180.3), (24, 2013, 2015, "April 2014", 116.4), (25, 2023, 2025, "October 2024", 160.9)) # SILSO's 13-month smoothed maxima, version 2.0 # ------------------------------------------------------------------ small numerics def isnan(x): return x != x def mean(v): return math.fsum(v) / len(v) def median(v): s = sorted(v) n = len(s) return s[n // 2] if n % 2 else 0.5 * (s[n // 2 - 1] + s[n // 2]) def sd(v): m = mean(v) return math.sqrt(math.fsum((x - m) ** 2 for x in v) / (len(v) - 1)) def percentile(sorted_v, p): """Linear interpolation between order statistics (numpy's default).""" pos = (len(sorted_v) - 1) * p / 100.0 lo = int(math.floor(pos)) hi = min(lo + 1, len(sorted_v) - 1) return sorted_v[lo] + (pos - lo) * (sorted_v[hi] - sorted_v[lo]) def norm_p2(z): return math.erfc(abs(z) / math.sqrt(2.0)) def gammaincc(a, x): """Regularized upper incomplete gamma function Q(a, x).""" if x <= 0: return 1.0 if x < a + 1.0: ap_, s, d = a, 1.0 / a, 1.0 / a for _ in range(2000): ap_ += 1.0 d *= x / ap_ s += d if abs(d) < abs(s) * 1e-16: break return 1.0 - s * math.exp(-x + a * math.log(x) - math.lgamma(a)) b, c, d = x + 1.0 - a, 1e300, 1.0 / (x + 1.0 - a) h = d for i in range(1, 2000): an = -i * (i - a) b += 2.0 d = an * d + b d = 1e-300 if abs(d) < 1e-300 else d c = b + an / c c = 1e-300 if abs(c) < 1e-300 else c d = 1.0 / d delta = d * c h *= delta if abs(delta - 1.0) < 1e-16: break return math.exp(-x + a * math.log(x) - math.lgamma(a)) * h def chi2_sf(q, k): return gammaincc(k / 2.0, q / 2.0) def betainc(a, b, x): """Regularized incomplete beta function I_x(a, b), by a continued fraction.""" if x <= 0.0: return 0.0 if x >= 1.0: return 1.0 front = math.exp(math.lgamma(a + b) - math.lgamma(a) - math.lgamma(b) + a * math.log(x) + b * math.log(1.0 - x)) if x > (a + 1.0) / (a + b + 2.0): return 1.0 - betainc(b, a, 1.0 - x) c, d = 1.0, 1.0 - (a + b) * x / (a + 1.0) d = 1e-300 if abs(d) < 1e-300 else d d = 1.0 / d h = d for m in range(1, 500): for num in (m * (b - m) * x / ((a + 2 * m - 1) * (a + 2 * m)), -(a + m) * (a + b + m) * x / ((a + 2 * m) * (a + 2 * m + 1))): d = 1.0 + num * d d = 1e-300 if abs(d) < 1e-300 else d c = 1.0 + num / c c = 1e-300 if abs(c) < 1e-300 else c d = 1.0 / d h *= d * c if abs(d * c - 1.0) < 1e-16: break return front * h / a def t_p2(t, df): return betainc(df / 2.0, 0.5, df / (df + t * t)) def solve_inverse(M): """Inverse of a small square matrix by Gauss-Jordan elimination.""" n = len(M) A = [list(map(float, row)) + [1.0 if i == j else 0.0 for j in range(n)] for i, row in enumerate(M)] for c in range(n): p = max(range(c, n), key=lambda r: abs(A[r][c])) A[c], A[p] = A[p], A[c] piv = A[c][c] A[c] = [v / piv for v in A[c]] for r in range(n): if r != c and A[r][c] != 0.0: f = A[r][c] A[r] = [a - f * b for a, b in zip(A[r], A[c])] return [row[n:] for row in A] def matmul(A, B): return [[math.fsum(A[i][k] * B[k][j] for k in range(len(B))) for j in range(len(B[0]))] for i in range(len(A))] def ols(X, y): """Least squares. X is a list of rows. Returns beta, residuals, (X'X)^-1.""" k = len(X[0]) XtX = [[math.fsum(r[i] * r[j] for r in X) for j in range(k)] for i in range(k)] Xty = [math.fsum(r[i] * v for r, v in zip(X, y)) for i in range(k)] inv = solve_inverse(XtX) beta = [math.fsum(inv[i][j] * Xty[j] for j in range(k)) for i in range(k)] e = [v - math.fsum(b * x for b, x in zip(beta, r)) for r, v in zip(X, y)] return beta, e, inv def sandwich(X, inv, weights_meat): k = len(X[0]) V = matmul(matmul(inv, weights_meat), inv) return [math.sqrt(V[i][i]) for i in range(k)] def newey_west_se(X, e, inv, L, correct=False): n, k = len(X), len(X[0]) S = [[math.fsum(e[t] * e[t] * X[t][i] * X[t][j] for t in range(n)) for j in range(k)] for i in range(k)] for l in range(1, L + 1): w = 1.0 - l / (L + 1.0) G = [[math.fsum(e[t] * e[t - l] * X[t][i] * X[t - l][j] for t in range(l, n)) for j in range(k)] for i in range(k)] for i in range(k): for j in range(k): S[i][j] += w * (G[i][j] + G[j][i]) se = sandwich(X, inv, S) return [s * math.sqrt(n / (n - k)) for s in se] if correct else se def hc3_se(X, e, inv): k = len(X[0]) u2 = [] for r, ei in zip(X, e): h = math.fsum(r[i] * inv[i][j] * r[j] for i in range(k) for j in range(k)) u2.append((ei / (1.0 - h)) ** 2) S = [[math.fsum(u * r[i] * r[j] for u, r in zip(u2, X)) for j in range(k)] for i in range(k)] return sandwich(X, inv, S) def pearson(a, b): p = [(x, y) for x, y in zip(a, b) if not (isnan(x) or isnan(y))] mx, my = mean([x for x, _ in p]), mean([y for _, y in p]) sxy = math.fsum((x - mx) * (y - my) for x, y in p) return sxy / math.sqrt(math.fsum((x - mx) ** 2 for x, _ in p) * math.fsum((y - my) ** 2 for _, y in p)), len(p) def rolling_rows(x, n, minp): out = [] for i in range(len(x)): w = [v for v in x[max(0, i - n + 1):i + 1] if not isnan(v)] out.append(mean(w) if len(w) >= minp else NAN) return out # ------------------------------------------------------------------ inputs def sha256_file(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(folder, name, url, notes): path = os.path.join(folder, name) if not os.path.exists(path): print("downloading", url) req = urllib.request.Request(url, headers={"User-Agent": UA}) with urllib.request.urlopen(req, timeout=300) as r: data = r.read() os.makedirs(os.path.dirname(path), exist_ok=True) with open(path, "wb") as f: f.write(data) want = SHA.get(name) if want: got = sha256_file(path) if got != want: notes.append("%s differs from the copy we used (SHA-256 %s..., ours %s...)" % (name, got[:16], want[:16])) print("Note:", notes[-1]) return path def read_igrf(path): epochs, rows = 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[:1] in "gh": p = line.split() rows[(p[0], int(p[1]), int(p[2]))] = [float(x) for x in p[3:]] return epochs, rows def dipole_proxy(igrf, t): epochs, rows = igrf out = 0.0 for key in (("g", 1, 0), ("g", 1, 1), ("h", 1, 1)): v = rows[key] if t >= epochs[-1]: c = v[len(epochs) - 1] + (t - epochs[-1]) * v[-1] else: i0 = max(i for i, e in enumerate(epochs) if e <= t) c = v[i0] + (t - epochs[i0]) / (epochs[i0 + 1] - epochs[i0]) * (v[i0 + 1] - v[i0]) out += c * c return math.sqrt(out) # OMNI2 fixed columns (0-based start, end) from omni2.text: word 9 |B|, 16 By GSM, 17 Bz GSM, 25 flow speed, # 39 Kp x 10, 41 Dst, 50 ap. A record is 327 characters. C_BMAG, C_BY, C_BZ, C_V, C_KP, C_DST = (30, 36), (72, 78), (78, 84), (129, 135), (218, 221), (225, 231) def read_omni(folder, notes): """All hours 1963-2026 as parallel lists. Missing values are NaN; hours after OMNI_END carry no solar wind.""" H = dict(year=[], month=[], dom=[], hour=[], V=[], BY=[], BZ=[], BM=[], kp=[], dst=[]) for y in YEARS: path = fetch(folder, "omni2_%d.dat" % y, OMNI_URL % y, notes) d0 = datetime.date(y, 1, 1) cal = {} with open(path, encoding="ascii") as f: for line in f: if len(line.rstrip("\r\n")) != 327: raise ValueError("%s: a record is not 327 characters" % path) doy, hr = int(line[4:8]), int(line[8:11]) if doy not in cal: dd = d0 + datetime.timedelta(days=doy - 1) cal[doy] = (dd.month, dd.day) mo, dom = cal[doy] v, by, bz, bm = float(line[129:135]), float(line[72:78]), float(line[78:84]), float(line[30:36]) kp, dst = int(line[218:221]), int(line[225:231]) late = (y, mo, dom, hr) > OMNI_END H["year"].append(y); H["month"].append(mo); H["dom"].append(dom); H["hour"].append(hr) H["V"].append(NAN if v == 9999.0 or late else v) H["BY"].append(NAN if by == 999.9 or late else by) H["BZ"].append(NAN if bz == 999.9 or late else bz) H["BM"].append(NAN if bm == 999.9 or late else bm) H["kp"].append(NAN if kp == 99 else kp / 10.0) H["dst"].append(NAN if dst == 99999 else float(dst)) return H def read_gfz(path, end, notes, name): """GFZ's files: {(y, m, d, start hour): (index, a-index)} and a fingerprint of the data lines to `end`.""" out, h = {}, hashlib.sha256() with open(path, encoding="ascii") as f: for line in f: if line.startswith("#") or not line.strip(): continue p = line.split() key = (int(p[0]), int(p[1]), int(p[2])) if key > end: break h.update(" ".join(p[:4] + p[7:9]).encode("ascii") + b"\n") if float(p[7]) >= 0: out[key + (int(round(float(p[3]))),)] = (float(p[7]), float(p[8])) check_fingerprint(name, h.hexdigest(), notes) return out def check_fingerprint(name, got, notes): want = FINGERPRINT.get(name) if want and got != want: notes.append("%s: the lines used differ from our copy (fingerprint %s..., ours %s...)" % (name, got[:16], want[:16])) print("Note:", notes[-1]) FOUND[name] = got FOUND = {} def read_kyoto_page(path): with open(path, encoding="euc-jp", errors="replace") as f: text = f.read() m = re.search(r"Hourly Equatorial Dst Values \(([A-Za-z -]+)\)", text) kind = m.group(1).strip().upper() if m else "?" if "REAL" in kind or "QUICK" in kind: raise ValueError("%s is a real-time page; this script must not read one" % path) days = {} for line in text.split("DAY", 1)[1].split("