30 lines
1.7 KiB
Python
30 lines
1.7 KiB
Python
"""Prints, per target and axis, the daily levels, amplitude and whole-window slow-drift statistics of displacement.py. Args: <detectors> <station folder> <from> <to> [targets,...]"""
|
|
import sys
|
|
from datetime import datetime, timedelta, timezone
|
|
from pathlib import Path
|
|
det = Path(sys.argv[1]).resolve()
|
|
sys.path[:0] = [str(det / "scripts"), str(det.parents[0] / "aimsight-tools" / "scripts")]
|
|
from data import load, is_reference # noqa
|
|
import displacement as D # noqa
|
|
day = lambda d: datetime.strptime(d, "%Y-%m-%d").replace(tzinfo=timezone.utc)
|
|
a, b = day(sys.argv[3]) - timedelta(days=3), day(sys.argv[4])
|
|
ms = {s: [m for m in v if a <= m["t"] < b] for s, v in load(sys.argv[2]).items()}
|
|
want = sys.argv[5].split(",") if len(sys.argv) > 5 else None
|
|
for s, v in sorted(ms.items()):
|
|
if is_reference(v) or (want and s not in want):
|
|
continue
|
|
for col in ("corr_x", "corr_y"):
|
|
ds, lv, ampl, _ = D._days(v, col)
|
|
if len(ds) < D.DAYS:
|
|
continue
|
|
w = D._whole(ds, lv, ampl, None)
|
|
pairs = [(i, j) for i in range(len(ds)) for j in range(i + 1, len(ds))]
|
|
slope = sorted((lv[j] - lv[i]) / (ds[j] - ds[i]).days for i, j in pairs)[len(pairs) // 2]
|
|
tau = sum((lv[j] > lv[i]) - (lv[j] < lv[i]) for i, j in pairs) / len(pairs)
|
|
d = slope * (ds[-1] - ds[0]).days
|
|
step = max(abs(y - x) for x, y in zip(lv, lv[1:]))
|
|
print(f"{s} {col} n={len(ds)} ampl={ampl:.3f} drift={d:+.3f} ({d/ampl if ampl else 0:+.1f} ampl) tau={tau:+.2f} "
|
|
f"step={step:.3f} whole={'YES' if w else 'no'} pieces={D._pieces(ds, lv, ampl, None) if not w else ''}")
|
|
if want:
|
|
print(" ", " ".join(f"{x.day}:{y:+.3f}" for x, y in zip(ds, lv)))
|