#!/usr/bin/env python3 """Question B of RULES_fig7.txt: Evora (EVO) on 12 May 2024, in Table 4 and in Figure 7 of Tacza et al. (2026), and the digitizing's validation row by row. Pillow only (no numpy). Usage: python3 -I fig7_evo_check.py PAPER_PDF [FOLDER] 1. From FOLDER/fig7_digitized_hourly.csv and fig7_sigma_by_hour.csv (fig7_digitize.py's outputs; default: this script's folder): our count of retained hours and their mean departure for each of Table 4's 37 rows, beside the paper's. 2. EVO's curve on 12 May read again from the PDF with separate code: the zero row is the dotted line (the row with the most short dark runs), and the scale comes from the panel's +20 and -20 V/m grid lines (the first thin bands of light grey met scanning in from the top and from the bottom), not from the tick marks fig7_digitize.py uses. After the fresh review (RULES_fig7_amendment2.txt) the curve is read over the whole plot, as in fig7_digitize.py, not only between the marker lanes, so the low values of 01, 06 and 07 UT are no longer lost. TABLE4 is typed from the paper's Table 4 (p. 14); its p column's order was checked against Figure 8. """ import csv import os import sys sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) from fig7_image import figure7 # noqa: E402 PDF = sys.argv[1] FOLDER = sys.argv[2] if len(sys.argv) > 2 else os.path.dirname(os.path.abspath(__file__)) TABLE4 = [ ("LM", 10, 14, -15.33), ("CLF", 10, 13, -19.40), ("BAT", 10, 15, -14.96), ("CRS", 10, 15, 0.70), ("LA", 10, 18, -7.19), ("CAS1", 10, 15, -12.06), ("CAS2", 10, 15, -16.72), ("EVO", 10, 15, -11.36), ("NCK", 10, 15, 70.53), ("LM", 11, 12, -5.15), ("CLF", 11, 12, -21.00), ("BAT", 11, 14, -14.56), ("CRS", 11, 12, -2.98), ("LA", 11, 10, -15.08), ("CAS1", 11, 13, 9.50), ("CAS2", 11, 13, 1.83), ("HYO", 11, 13, 0.03), ("EVO", 11, 20, -19.43), ("SWI_Jz", 11, 14, 0.096), ("SWI_PG", 11, 14, 156.44), ("LM", 12, 12, 3.87), ("CLF", 12, 12, -0.03), ("BAT", 12, 12, 6.91), ("CRS", 12, 12, 9.04), ("CAS1", 12, 19, 21.52), ("CAS2", 12, 19, 10.12), ("HYO", 12, 21, 9.74), ("EVO", 12, 17, -19.78), ("NCK", 12, 22, 64.41), ("SWI_Jz", 12, 18, 0.029), ("SWI_PG", 12, 18, 47.52), ("CAS1", 13, 12, 36.43), ("CAS2", 13, 12, 25.13), ("HYO", 13, 18, -7.16), ("NCK", 13, 17, -44.93), ("SWI_Jz", 13, 21, 0.116), ("SWI_PG", 13, 21, 113.58)] # 1. validation, row by row rows, sig = {}, {} with open(os.path.join(FOLDER, "fig7_digitized_hourly.csv"), encoding="utf-8") as fh: for r in csv.DictReader(fh): rows.setdefault(r["station"], []).append(r) with open(os.path.join(FOLDER, "fig7_sigma_by_hour.csv"), encoding="utf-8") as fh: for r in csv.DictReader(fh): if r["sigma_halfwidth"]: sig.setdefault(r["station"], []).append(float(r["sigma_halfwidth"])) print("1. Table 4 beside our reading of Figure 7 (retained hours: a curve value and no marker)") print(" station day n paper/ours Delta paper our mean difference in background SDs") for st, day, n, delta in TABLE4: kept = [float(r["departure"]) for r in rows[st] if int(r["time_utc"][8:10]) == day and r["retained"] == "1"] sd = sum(sig[st]) / len(sig[st]) m = sum(kept) / len(kept) if kept else float("nan") print(" %-7s %2d %2d / %2d %10.3f %9.3f %+5.2f" % (st, day, n, len(kept), delta, m, (m - delta) / sd)) evo = [r for r in rows["EVO"] if r["time_utc"].startswith("2024-05-12")] print(" EVO 12 May, hour by hour (departure, retained):", " ".join("%s:%s%s" % (r["time_utc"][11:13], r["departure"] or "gap", "" if r["retained"] == "1" else "*") for r in evo)) with_data = [float(r["departure"]) for r in evo if r["departure"]] print(" hours with data: %d, mean %.1f V/m; retained: %d, mean %.1f V/m (* = a marker, not retained)" % ( len(with_data), sum(with_data) / len(with_data), sum(r["retained"] == "1" for r in evo), sum(float(r["departure"]) for r in evo if r["retained"] == "1") / max(1, sum(r["retained"] == "1" for r in evo)))) # 2. EVO's curve on 12 May with a separate scale px = figure7(PDF).load() x0, x1, y0, y1 = 196, 1275, 3258, 3605 dark = lambda p: max(p) < 100 gridlike = lambda p: 195 <= p[0] <= 242 and p[1] >= 228 and p[2] >= 228 def dots(y): n = cur = 0 for x in range(x0 + 4, x1 - 4): if dark(px[x, y]): cur += 1 else: n += 1 <= cur <= 6 cur = 0 return n def first_band(rng): band = [] for y in rng: if sum(1 for x in range(300, 580) if gridlike(px[x, y])) > 90: band.append(y) elif band: break return sum(band) / len(band) zero_row = max(range(y0 + 30, y1 - 56), key=dots) top, bot = first_band(range(y0 + 30, zero_row)), first_band(range(y1 - 57, zero_row, -1)) scale, zero = 40.0 / (bot - top), (top + bot) / 2 print("2. EVO panel: +20 and -20 V/m grid lines at rows %.1f and %.1f; zero %.1f (dotted line at %d); %.3f V/m per pixel" % ( top, bot, zero, zero_row, scale)) vals = [] for h in range(24): x = int(round(294.5 + 98.0 * (5 + h / 24.0))) ys = [y for y in range(y0 + 3, y1 - 3) if dark(px[x, y]) and not (abs(y - zero) <= 3 and sum(dark(px[x, yy]) for yy in range(y - 4, y + 5)) <= 3)] vals.append("%02d:%s" % (h, " gap" if not ys else "%+5.1f" % ((zero - (min(ys) + max(ys)) / 2) * scale))) print(" EVO 12 May, V/m at h:00 UT:", " ".join(vals))