# Copied unchanged (below this line) on 2026-11-13 from verification/s0-news-2026-10-24/code/ozone_records.py, the 24 October page's script, to re-count record days with data to mid-November. """Count the 2026 days on which the Antarctic ozone hole set or tied a record for the date. Usage: python3 -I ozone_records.py NASA_AREA_2026 NASA_MIN_2026 NASA_OMD_2026 CAMS_AREA_CSV NASA Ozone Watch files: rows "YYYY-MM-DD Data Minimum 10% 30% Mean 70% 90% Maximum", where the last seven columns are NASA's 1979-2025 climatology for that calendar date (Maximum = the highest value of 1979-2025 for the date; for minimum ozone, "Minimum" = the lowest). Values have two decimals, so "tied" means equal to two decimals. CAMS CSV: 6-hourly values 1979 to the latest analysis; the record for each date is computed here from 1979-2025, both for the daily mean (mean of the four 6-hourly values) and for each 6-hourly step. Reads the files as data only; prints the results. """ import csv import datetime as dt import re import sys from collections import defaultdict ROW = re.compile(r"^(\d{4})-(\d{2})-(\d{2})\s+(.*)$") MISSING = -9999.0 def parse_nasa(path): rows = {} with open(path, "rb") as f: for line in f.read().decode("utf-8", "replace").splitlines(): m = ROW.match(line.strip()) if not m: continue nums = [float(x) for x in m.group(4).split()] rows[dt.date(int(m.group(1)), int(m.group(2)), int(m.group(3)))] = nums return rows def nasa_records(path, label, higher_is_worse=True): rows = parse_nasa(path) beat, tied, near = [], [], [] last = None for d in sorted(rows): data, mn, p10, p30, mean, p70, p90, mx = rows[d] if data == MISSING: continue last = d if higher_is_worse: if mx <= 0: continue if data > mx: beat.append((d, data, mx)) elif data == mx: tied.append((d, data, mx)) elif data >= p90: near.append(d) else: # minimum ozone: lower is worse; skip dates with no hole climatology if data < mn: beat.append((d, data, mn)) elif data == mn: tied.append((d, data, mn)) print(f"--- NASA {label}: last date with data {last}") print(f" beat the 1979-2025 record for the date: {len(beat)}") for d, v, r in beat: print(f" {d} 2026 {v:.2f} previous record {r:.2f} (+{v - r:.2f})") print(f" tied it: {len(tied)} {[(str(d), v) for d, v, r in tied]}") return rows, beat, tied def load_cams(path): out = {} with open(path, newline="") as f: r = csv.reader(f) next(r) for row in r: if len(row) < 2 or not row[0]: continue t = dt.datetime.strptime(row[0], "%Y-%m-%dT%H:%M") try: out[t] = float(row[1]) except ValueError: pass return out def cams_records(path): A = load_cams(path) last = max(A) print(f"--- CAMS area: {len(A)} six-hourly values, {min(A)} to {last}") # daily means daily = defaultdict(list) for t, v in A.items(): daily[t.date()].append(v) dmean = {d: sum(v) / len(v) for d, v in daily.items() if len(v) == 4} rec_mean = {} for d, v in dmean.items(): if 1979 <= d.year <= 2025 and not (d.month == 2 and d.day == 29): k = (d.month, d.day) if k not in rec_mean or v > rec_mean[k][0]: rec_mean[k] = (v, d.year) rec6 = {} for t, v in A.items(): if 1979 <= t.year <= 2025: k = (t.month, t.day, t.hour) if k not in rec6 or v > rec6[k][0]: rec6[k] = (v, t.year) beat_mean = [] for d in sorted(x for x in dmean if x.year == 2026): k = (d.month, d.day) if k in rec_mean and rec_mean[k][0] > 0 and dmean[d] >= rec_mean[k][0]: beat_mean.append((d, dmean[d], rec_mean[k])) print(f" days whose daily mean beat or tied the 1979-2025 record daily mean for the date: {len(beat_mean)}") for d, v, (r, y) in beat_mean: print(f" {d} 2026 {v:.3f} previous record {r:.3f} ({y})") beat6 = defaultdict(list) for t in sorted(x for x in A if x.year == 2026): k = (t.month, t.day, t.hour) if k in rec6 and rec6[k][0] > 0 and A[t] >= rec6[k][0]: beat6[t.date()].append((t.hour, A[t], rec6[k])) print(f" days with at least one six-hourly value at or above the 1979-2025 record for that step: {len(beat6)}") for d in sorted(beat6): print(f" {d} steps {[(h, round(v, 3), round(r, 3), y) for h, v, (r, y) in beat6[d]]}") # series since 10 October print(" CAMS daily mean and max since 10 October 2026:") for d in sorted(x for x in dmean if x >= dt.date(2026, 10, 10)): vals = daily[d] k = (d.month, d.day) print(f" {d} mean {dmean[d]:.3f} max {max(vals):.3f} record mean {rec_mean[k][0]:.3f} ({rec_mean[k][1]})") # partial last day for d in sorted(daily): if d.year == 2026 and len(daily[d]) < 4: print(f" partial day {d}: {daily[d]}") return A, dmean def main(): a, m, o, c = sys.argv[1:5] rows, beat, tied = nasa_records(a, "ozone-hole area (million km2, 40-90S, <220 DU)") print(" NASA daily area since 10 October 2026, with the 90th percentile and record for the date:") for d in sorted(rows): if d >= dt.date(2026, 10, 10) and rows[d][0] != MISSING: r = rows[d] print(f" {d} {r[0]:.2f} p90 {r[6]:.2f} max {r[7]:.2f}") nasa_records(m, "minimum ozone (DU; a record is a new low)", higher_is_worse=False) nasa_records(o, "ozone mass deficit (Mt)") cams_records(c) if __name__ == "__main__": main() def extra_counts(nasa_path, cams_path): """Days above NASA's 90th percentile and above CAMS's 1979-2023 95th percentile (daily means).""" import statistics as st rows = parse_nasa(nasa_path) win = [d for d in sorted(rows) if dt.date(2026, 9, 18) <= d and rows[d][0] != MISSING] above = [d for d in win if rows[d][0] > rows[d][6]] print(f"--- NASA: days above its 1979-2025 90th percentile, 18 Sep to {win[-1]}: {len(above)} of {len(win)}") late = [d for d in win if d > dt.date(2026, 10, 17)] print(" after 17 Oct:", [(str(d), rows[d][0], rows[d][6]) for d in late]) A = load_cams(cams_path) daily = defaultdict(list) for t, v in A.items(): daily[t.date()].append(v) dmean = {d: sum(v) / len(v) for d, v in daily.items() if len(v) == 4} def p95(md): s = sorted(dmean[dt.date(y, *md)] for y in range(1979, 2024) if dt.date(y, *md) in dmean) # linear-interpolated 95th percentile k = 0.95 * (len(s) - 1) f = int(k) return s[f] + (s[min(f + 1, len(s) - 1)] - s[f]) * (k - f) days = [d for d in sorted(dmean) if d.year == 2026 and dt.date(2026, 9, 17) <= d] hi = [d for d in days if dmean[d] > p95((d.month, d.day))] print(f"--- CAMS: days with the daily mean above the 1979-2023 95th percentile, 17 Sep to {days[-1]}: {len(hi)} of {len(days)}") print(" 19-24 Oct:", [(str(d), round(dmean[d], 2), round(p95((d.month, d.day)), 2)) for d in days if d >= dt.date(2026, 10, 19)]) if __name__ == "__main__" and len(sys.argv) > 5 and sys.argv[5] == "--extra": extra_counts(sys.argv[1], sys.argv[4])