#!/usr/bin/env python3 """Our analysis: 30-minute means of OMNI's solar wind before the first shock of 10 May 2024, to see what lay ahead of it. Usage: python3 -I omni_preshock.py OMNI_FILE OUT_TXT Columns as in omni_timeline.py. Standard library only. """ import datetime as dt import sys WIDTHS = [4, 4, 3, 3, 3, 3, 4, 4, 4, 7, 7, 6, 7] + [8] * 8 + [8] * 4 + [7, 9, 6, 7, 7, 6] + [8] * 6 + [6] * 7 + [7, 5] NAMES = ["year", "doy", "hour", "minute", "imf_id", "sw_id", "n_imf", "n_plasma", "pct_interp", "timeshift", "rms_timeshift", "rms_phase", "dt_obs", "B", "Bx", "By_gse", "Bz_gse", "By", "Bz", "rms_sd_b", "rms_sd_vec", "V", "Vx", "Vy", "Vz", "Np", "T", "P"] FILL = {"B": 9999.99, "V": 99999.9, "Np": 999.99, "T": 9999999.0, "P": 99.99, "Bz": 9999.99} rows = {} for line in open(sys.argv[1], encoding="ascii", errors="replace"): vals, pos = {}, 0 for w, n in zip(WIDTHS, NAMES): vals[n] = line[pos:pos + w].strip() pos += w t = dt.datetime(int(vals["year"]), 1, 1) + dt.timedelta(days=int(vals["doy"]) - 1, hours=int(vals["hour"]), minutes=int(vals["minute"])) if not dt.datetime(2024, 5, 9, 0) <= t < dt.datetime(2024, 5, 10, 17, 4): continue bin_t = t.replace(minute=0 if t.minute < 30 else 30) r = rows.setdefault(bin_t, {k: [] for k in FILL}) for k, f in FILL.items(): try: x = float(vals[k]) except ValueError: continue if x < f * 0.999: r[k].append(x) out = ["time (bin start) V km/s Np /cc T K P nPa |B| nT Bz nT n_plasma"] for t in sorted(rows): r = rows[t] m = lambda k, d=1: " --- " if not r[k] else f"{sum(r[k]) / len(r[k]):7.{d}f}" out.append(f"{t:%m-%d %H:%M} {m('V', 0)} {m('Np')} {m('T', 0)} {m('P')} {m('B')} {m('Bz')} {len(r['V'])}") with open(sys.argv[2], "w", encoding="utf-8", newline="\n") as f: f.write("\n".join(out) + "\n") print("\n".join(out[-34:]))