60 lines
2.8 KiB
Python
60 lines
2.8 KiB
Python
"""Thermal labels: does a target keep the camera cycle beyond 5 noises from its night level?
|
|||
|
|
Per target (global references CTR02-04 out; PR04, PR17, CTR01 out: their curves carry their own Target issue /
|
||
|
|
Obstruction labels): night level = median of the accepted corr over the 5 h before the label start (end of the night
|
||
|
|
that precedes); noise = own noise (median |difference| between consecutive accepted measurements) over the label;
|
||
|
|
deviation = median of 3 consecutive measurements minus the night level, in noises; instants inside a non-thermal,
|
||
|
|
non-No-data label are skipped. Prints, per label, the targets beyond 5 noises: the extreme, its instant, and how many
|
||
|
|
measurements (smoothed) are beyond.
|
||
|
|
Usage: python3 <this> <labels.jsonl>
|
||
|
|
"""
|
||
|
|
import json, statistics, sys
|
||
|
|
from datetime import timedelta
|
||
|
|
sys.path.insert(0, "tools/scripts")
|
||
|
|
import data, common
|
||
|
|
|
||
|
|
EXCL = {"CTR02", "CTR03", "CTR04", "PR04", "PR17", "CTR01"}
|
||
|
|
by = data.load("data/NORDEND")
|
||
|
|
labels = [json.loads(l) for l in open(sys.argv[1])]
|
||
|
|
other = [(data.parse_time(l["start"]), data.parse_time(l["end"])) for l in labels
|
||
|
|
if l["family"] not in ("Thermal displacement", "No data")]
|
||
|
|
|
||
|
|
|
||
|
|
def covered(t):
|
||
|
|
return any(a < t < b for a, b in other)
|
||
|
|
|
||
|
|
|
||
|
|
for l in labels:
|
||
|
|
if l["family"] != "Thermal displacement":
|
||
|
|
continue
|
||
|
|
s, e = data.parse_time(l["start"]), data.parse_time(l["end"])
|
||
|
|
print(f"{l['id']} {l['start']} {l['end']}")
|
||
|
|
rows = []
|
||
|
|
for name, ms in by.items():
|
||
|
|
if name in EXCL:
|
||
|
|
continue
|
||
|
|
for col in ("corr_x", "corr_y"):
|
||
|
|
night = [m[col] for m in ms if s - timedelta(hours=5) <= m["t"] <= s and m[col] is not None]
|
||
|
|
lab = [(m["t"], m[col]) for m in ms if s <= m["t"] <= e and m[col] is not None]
|
||
|
|
if len(night) < 5 or len(lab) < 5:
|
||
|
|
continue
|
||
|
|
lvl = statistics.median(night)
|
||
|
|
nz = common.own_noise([v for _, v in lab])
|
||
|
|
if not nz:
|
||
|
|
continue
|
||
|
|
dev = []
|
||
|
|
for i in range(1, len(lab) - 1):
|
||
|
|
t = lab[i][0]
|
||
|
|
if covered(t):
|
||
|
|
continue
|
||
|
|
v = statistics.median([lab[i - 1][1], lab[i][1], lab[i + 1][1]])
|
||
|
|
dev.append((t, (v - lvl) / nz, v - lvl))
|
||
|
|
big = [d for d in dev if abs(d[1]) > 5]
|
||
|
|
if big:
|
||
|
|
x = max(big, key=lambda d: abs(d[1]))
|
||
|
|
rows.append((abs(x[1]), f" {name:5} {col} extreme {x[1]:+.1f} noises ({x[2]:+.4f} px, noise {nz:.4f}) at "
|
||
|
|
f"{data.iso(x[0])}; {len(big)} measurements beyond, "
|
||
|
|
f"{data.iso(big[0][0])} .. {data.iso(big[-1][0])}"))
|
||
|
|
rows.sort(reverse=True)
|
||
|
|
for _, r in rows[:6]:
|
||
|
|
print(r)
|
||
|
|
print(f" targets beyond 5 noises: {len(rows)}\n")
|