Files
aimsight-labeling/auto/analyses/WYOMING_2026-11-06T0805_2026-11-16T0627/scripts/agitation.py
T

44 lines
2.3 KiB
Python

"""Per hour: agitation of the far group (median over target_07..target_11 of |corr_y step| between consecutive
measurements) and of the far references (|raw y step| of target_12, target_13), against MeteoSwiss wind, humidity,
air temperature; then correlations. Also the lag between dx_RD and the housing temperature.
usage: python3 agitation.py
"""
import csv, statistics, sys
sys.path.insert(0, "tools/scripts")
import data
D = "labeling/auto/analyses/WYOMING_2026-11-06T0805_2026-11-16T0627/work/"
start, end = data.parse_time("2026-11-06T08:15Z"), data.parse_time("2026-11-16T06:15Z")
meas = data.load("data/WYOMING")
w = {data.parse_time(r["time_utc"]): r for r in csv.DictReader(open(D + "weather_geneve.csv"))}
FAR = ["target_%02d" % i for i in range(7, 12)]
hours = {}
for s in FAR + ["target_12", "target_13"]:
v = [m for m in meas[s] if start <= m["t"] <= end]
for a, b in zip(v, v[1:]):
h = b["t"].replace(minute=0, second=0, microsecond=0)
if s in FAR:
if a["corr_y"] is not None and b["corr_y"] is not None:
hours.setdefault(h, {}).setdefault("tgt", []).append(abs(b["corr_y"] - a["corr_y"]))
elif not data.rejected(a) and not data.rejected(b):
hours.setdefault(h, {}).setdefault("ref", []).append(abs(b["y"] - a["y"]))
rows = []
for h in sorted(hours):
if h in w and "tgt" in hours[h] and "ref" in hours[h]:
f = lambda k: float(w[h][k]) if w[h][k] else None
rows.append((h, statistics.median(hours[h]["tgt"]), statistics.median(hours[h]["ref"]), f("wind_speed_kmh"),
f("wind_gust_kmh"), f("humidity_pct"), f("temperature_c"), f("global_radiation_wm2")))
by_day = {}
for r in rows:
by_day.setdefault(r[0].strftime("%m-%d"), []).append(r)
print("day agit_tgt agit_ref wind gust (daily medians)")
for d, rs in by_day.items():
print(d, "%.3f %.3f %.1f %.1f" % tuple(statistics.median([x[i] for x in rs]) for i in (1, 2, 3, 4)))
def corr(i, j):
p = [(r[i], r[j]) for r in rows if r[i] is not None and r[j] is not None]
return statistics.correlation(*zip(*p))
for name, j in (("wind", 3), ("gust", 4), ("humidity", 5), ("air", 6), ("radiation", 7)):
print(f"r(agit_tgt, {name}) = {corr(1, j):+.2f}; r(agit_ref, {name}) = {corr(2, j):+.2f}")
print(f"r(agit_tgt, agit_ref) = {corr(1, 2):+.2f}; n = {len(rows)}")