#!/usr/bin/env python3 """Generate demonstrative magnetic-field traces. NOT actual OPM or vehicle data.""" from pathlib import Path import math, random, csv SEED = 20261113 DT = 0.01 DURATION = 3.0 OUTPUT = Path(__file__).with_name('synthetic_magnetic_events.csv') def gauss(t, mu, sigma, amplitude): return amplitude * math.exp(-0.5 * ((t - mu) / sigma) ** 2) def generate(): rng = random.Random(SEED) for scenario in range(1, 6): for i in range(int(DURATION / DT) + 1): t = round(i * DT, 3) base = (0 if scenario == 5 else gauss(t, 1.4, 0.11, 0.22) - gauss(t, 1.57, 0.14, 0.08)) second = gauss(t, 1.72, 0.05, 0.13) if scenario == 2 else 0 gate = gauss(t, 0.88, 0.22, 0.29) if scenario == 3 else 0 other = gauss(t, 1.49, 0.14, -0.19) if scenario == 4 else 0 noise = rng.gauss(0, 0.006) bx = base + second + gate + other + noise by = .55 * base + .25 * second + .8 * gate - .4 * other + rng.gauss(0, .006) bz = -.35 * base + .6 * second + .5 * gate + .5 * other + rng.gauss(0, .006) ref = .8 * gate + rng.gauss(0,.005) yield dict(scenario_id=f'SIM-{scenario:02d}',time_s=t, bx_nT=round(bx,6),by_nT=round(by,6),bz_nT=round(bz,6), reference_nT=round(ref,6),synthetic='TRUE') if __name__=='__main__': rows=list(generate()) with OUTPUT.open('w',newline='',encoding='utf-8') as f: w=csv.DictWriter(f,fieldnames=rows[0].keys());w.writeheader();w.writerows(rows) print(f'Wrote {len(rows)} fully synthetic samples to {OUTPUT}')