#!/usr/bin/env python3 """Check the numbers of the NOAA-NASA release of 4 November 2026 by the rules of RULES_release_checks.txt (and Amendment 1 in RULES_rankings.txt for the vortex and heat-flux data). Standard library only; reads downloads as data. Usage: python3 -I release_checks.py Writes out/release_checks.json and prints it. """ import hashlib import json import sys from datetime import date, timedelta from pathlib import Path if hasattr(sys.stdout, "reconfigure"): sys.stdout.reconfigure(encoding="utf-8", newline="\n") HERE = Path(__file__).resolve().parent # the rules files sit beside the scripts V = Path(sys.argv[1]).resolve() D = V / "downloads" MISSING = -9999.0 MI2 = 1.609344 ** 2 # km2 per square mile, exact (international mile) read = [] def one(sub, pattern="*.txt"): f = sorted((D / sub).glob(pattern)) assert len(f) == 1, (sub, f) read.append((f[0].relative_to(V).as_posix(), hashlib.sha256(f[0].read_bytes()).hexdigest())) return f[0] def monthly(sub): rows = {} for line in one(sub).read_text(encoding="utf-8").splitlines(): p = line.split() if len(p) >= 2 and p[0].isdigit() and len(p[0]) == 4 and float(p[1]) != MISSING: rows[int(p[0])] = float(p[1]) return rows def daily(sub): rows = {} for line in one(sub).read_text(encoding="utf-8").splitlines(): p = line.split() if p and len(p[0]) == 10 and p[0][4] == "-": rows[date.fromisoformat(p[0])] = [float(x) for x in p[1:]] return rows def rounds_to(value, stated, decimals): return round(value, decimals) == stated R = {"rules_sha256": hashlib.sha256((HERE / "RULES_release_checks.txt").read_bytes()).hexdigest()} rk = json.loads((V / "out" / "rankings.json").read_text(encoding="utf-8")) A1 = rk["measures"]["A1_season_mean_area_0907_1013"]["value_2026"] A2 = rk["measures"]["A2_one_day_max_area"]["value_2026"] A2d = rk["measures"]["A2_one_day_max_area"]["date_2026"] rec = rk["measures"]["A2_one_day_max_area"]["top10"][0] # ---- conversions and the area numbers R["season_mean"] = {"nasa_km2_million": A1, "release_km2": 25, "holds_25": rounds_to(A1, 25, 0), "in_sq_mi_million": A1 / MI2, "release_sq_mi": 9.6, "holds_9_6": rounds_to(A1 / MI2, 9.6, 1), "25_km2_in_sq_mi": 25 / MI2} R["one_day_max"] = {"nasa_km2_million": A2, "date": A2d, "release_km2": 27.1, "holds_27_1": rounds_to(A2, 27.1, 1), "date_holds": A2d == "2026-09-18", "in_sq_mi_million": A2 / MI2, "holds_10_5": rounds_to(A2 / MI2, 10.5, 1), "27_1_km2_in_sq_mi": 27.1 / MI2} R["ratio_to_record"] = {"record": rec, "ratio": A2 / rec[1], "holds_about_90pct": abs(A2 / rec[1] - 0.90) <= 0.05, "ratio_rounded_figures": 27.1 / 29.9} R["counterfactual_conversion"] = {"3.5_million_km2_in_sq_mi_million": 3.5 / MI2, "1_to_2_million_sq_mi_in_km2_million": [1 * MI2, 2 * MI2], "km2_point_inside_mi_range": 1 <= 3.5 / MI2 <= 2} # US area (Census 2010 table: total 3,796,742 sq mi = 9,833,517 km2; land 3,531,905 sq mi = 9,147,593 km2) us_total, us_land = 9.833517, 9.147593 R["us_area"] = {"total_km2_million": us_total, "land_km2_million": us_land, "ratio_total": A1 / us_total, "ratio_land": A1 / us_land, "more_than_twice_total": A1 > 2 * us_total, "more_than_twice_land": A1 > 2 * us_land} # Dobson unit: 1 DU = 0.01 mm at STP -> 100 DU = 1 mm; 2026's 105 DU = 1.05 mm R["dobson_unit"] = {"100_DU_mm": 100 * 0.01, "105_DU_mm": 105 * 0.01} # ---- heat flux: 45-75S, 100 hPa, Aug and Sep monthly means; magnitude = -value (SH flux is negative) aug = monthly("nasa_vt100_08") sep = monthly("nasa_vt100_09") yrs = sorted(set(aug) & set(sep)) hf = {y: (31 * aug[y] + 30 * sep[y]) / 61 for y in yrs} mag = {y: -v for y, v in hf.items()} order = sorted(mag, key=lambda y: mag[y]) # weakest first clim = sorted(mag[y] for y in mag if 1979 <= y <= 2025) med = (clim[len(clim) // 2] if len(clim) % 2 else (clim[len(clim) // 2 - 1] + clim[len(clim) // 2]) / 2) R["heat_flux_100hPa_45_75S_aug_sep"] = { "value_2026_K_m_s": hf[2026], "rank_weakest": order.index(2026) + 1, "n_years": len(order), "median_1979_2025_magnitude": med, "weak": mag[2026] < med, "especially_weak_top5": order.index(2026) < 5, "five_weakest": [(y, round(hf[y], 2)) for y in order[:5]], "aug_2026": aug[2026], "sep_2026": sep[2026], "aug_rank_weakest": sorted(aug, key=lambda y: -aug[y]).index(2026) + 1, "sep_rank_weakest": sorted(sep, key=lambda y: -sep[y]).index(2026) + 1, "n_aug": len(aug), "n_sep": len(sep), } # ---- vortex strength: 60S zonal-mean zonal wind, 50 hPa, monthly (Aug, Sep, Oct) for mm, sub in (("aug", "nasa_u60s50_08"), ("sep", "nasa_u60s50_09"), ("oct", "nasa_u60s50_10")): u = monthly(sub) if 2026 in u: o = sorted(u, key=lambda y: -u[y]) # strongest first R[f"u60S_50hPa_{mm}"] = {"value_2026_m_s": u[2026], "rank_strongest": o.index(2026) + 1, "n_years": len(o), "top10pct": o.index(2026) + 1 <= 5, "top5": [(y, u[y]) for y in o[:5]], "mean_1979_2025": sum(u[y] for y in u if y <= 2025) / len([y for y in u if y <= 2025])} # ---- vortex area at 460 K (daily 2026 with 1979-2025 climatology) va = daily("nasa_vortex_area_460_2026") cols = ["data", "min", "p10", "p30", "mean", "p70", "p90", "max", "fcst"] def vortex_window(a, b): days = [a + timedelta(days=i) for i in range((b - a).days + 1)] rows = [dict(zip(cols, va[d_])) for d_ in days if d_ in va and va[d_][0] != MISSING] return {"n_days": len(rows), "days_above_p90": sum(1 for r in rows if r["data"] > r["p90"]), "days_above_max": sum(1 for r in rows if r["data"] > r["max"]), "days_above_mean": sum(1 for r in rows if r["data"] > r["mean"]), "mean_2026": sum(r["data"] for r in rows) / len(rows), "mean_clim_mean": sum(r["mean"] for r in rows) / len(rows), "mean_clim_p90": sum(r["p90"] for r in rows) / len(rows)} R["vortex_area_460K_1sep_13oct"] = vortex_window(date(2026, 9, 1), date(2026, 10, 13)) R["vortex_area_460K_1sep_13oct"]["unusually_large_rule"] = ( R["vortex_area_460K_1sep_13oct"]["days_above_p90"] > R["vortex_area_460K_1sep_13oct"]["n_days"] / 2) R["vortex_area_460K_aug"] = vortex_window(date(2026, 8, 1), date(2026, 8, 31)) R["vortex_area_460K_header"] = one("nasa_vortex_area_460_2026").read_text(encoding="utf-8").splitlines()[:6] # 60S wind daily (50 hPa) in Aug-Sep vs climatology w = daily("nasa_u60s50_2026") days = [date(2026, 8, 1) + timedelta(days=i) for i in range(61)] rows = [dict(zip(cols, w[d_])) for d_ in days if d_ in w and w[d_][0] != MISSING] R["u60S_50hPa_daily_aug_sep"] = {"n_days": len(rows), "days_above_p90": sum(1 for r in rows if r["data"] > r["p90"]), "days_above_max": sum(1 for r in rows if r["data"] > r["max"]), "mean_2026": sum(r["data"] for r in rows) / len(rows), "mean_clim": sum(r["mean"] for r in rows) / len(rows)} hfd = daily("nasa_vt100_2026") rows = [dict(zip(cols, hfd[d_])) for d_ in days if d_ in hfd and hfd[d_][0] != MISSING] R["heat_flux_daily_aug_sep"] = {"n_days": len(rows), "days_weaker_than_p90_side": sum(1 for r in rows if r["data"] > r["p90"]), "days_weaker_than_clim_mean": sum(1 for r in rows if r["data"] > r["mean"]), "mean_2026": sum(r["data"] for r in rows) / len(rows), "mean_clim": sum(r["mean"] for r in rows) / len(rows)} R["files_read"] = read (V / "out" / "release_checks.json").write_text(json.dumps(R, indent=1, default=str) + "\n", encoding="utf-8", newline="\n") print(json.dumps({k: v for k, v in R.items() if k != "files_read"}, indent=1, default=str))