"""Prints, for given sensors around an instant, error_value (in MAD above the sensor median, and / threshold), flux, corr_x, corr_y. Args: """ import sys from datetime import timedelta 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, parse_time # noqa from episodes import level # noqa c, w = parse_time(sys.argv[3]), timedelta(minutes=int(sys.argv[4])) ms = load(sys.argv[2]) for s in sys.argv[5].split(","): v = ms[s] med, mad = level([m["error_value"] for m in v if m["error_value"] is not None]) print(s, f"median {med:.3g} mad {mad:.3g}") for m in v: if c - w <= m["t"] <= c + w: e = m["error_value"] z = f"{(e - med) / mad:7.1f}" if e is not None else " -" r = f"{e / m['error_threshold']:.2f}" if e is not None and m["error_threshold"] else "-" f = lambda k: f"{m.get(k):.3f}" if isinstance(m.get(k), float) else str(m.get(k)) print(" ", m["t"].strftime("%m-%d %H:%M"), "z", z, "ratio", r, "flux", f("flux"), "cx", f("corr_x"), "cy", f("corr_y"))