"""Checks of dataset.py on a synthetic station: python test_dataset.py .""" import sys from datetime import datetime, timedelta, timezone from pathlib import Path import numpy as np sys.path.insert(0, str(Path(sys.argv[1]) / "scripts")) import data # noqa: E402 import dataset # noqa: E402 # Labels as bench/score.py: bounds excluded; a hole (no instant inside) keeps its bounds. instants = ["2026-10-01T00:00Z", "2026-10-01T00:15Z", "2026-10-01T00:30Z", "2026-10-01T01:30Z"] y = dataset.label_families([ {"start": "2026-10-01T00:00Z", "end": "2026-10-01T00:30Z", "family": "Visibility"}, {"start": "2026-10-01T00:30Z", "end": "2026-10-01T01:30Z", "family": "No data"}, {"start": "2026-10-01T00:00Z", "end": "2026-10-01T01:30Z", "family": "None"}, ], instants) assert y[:, 0].tolist() == [0, 1, 0, 0], y assert y[:, 5].tolist() == [0, 0, 1, 1], y # Four days at 15 min, two targets and a reference; T1 jumps by 10 px on the last day, all rejected at one instant. t0 = datetime(2026, 10, 1, tzinfo=timezone.utc) rng = np.random.default_rng(0) measurements = {} for s, kind in (("T1", "target"), ("T2", "target"), ("R1", "global_ref")): v = [] for i in range(4 * 96): t = t0 + timedelta(minutes=15 * i, seconds=7) x = rng.normal(0, 0.05) + (10 if s == "T1" and i >= 3 * 96 + 10 else 0) ev = 0.2 + rng.normal(0, 0.01) + (0.5 if i == 3 * 96 + 40 else 0) m = {c: None for c in data.NUM} m.update(t=t, pattern_type=kind, corr_x=x, corr_y=rng.normal(0, 0.05), error_value=ev, error_threshold=0.5, sigma0=0.01) if data.rejected(m): m["corr_x"] = m["corr_y"] = None v.append(m) measurements[s] = v class Data: # data.py with the synthetic station load = staticmethod(lambda folder: measurements) load_camera = staticmethod(lambda folder: []) load_temperature = staticmethod(lambda folder: []) is_reference, parse_time, iso = staticmethod(data.is_reference), staticmethod(data.parse_time), staticmethod(data.iso) d = dataset.build("-", [], "2026-10-04T00:00Z", "2026-10-05T00:00Z", Data) names, sensors = list(d["xs_names"]), list(d["sensors"]) assert d["xs"].shape == (96, 3, len(names)) and d["xc"].shape[0] == 96 and d["y"].sum() == 0 assert d["instants"][0] == "2026-10-04T00:00Z" and list(d["kinds"]) == ["target", "target", "global_ref"] jx, rx, step = (d["xs"][:, sensors.index("T1"), names.index(k)] for k in ("jx", "rx", "step_x_6h")) assert abs(jx[10]) > 50 and np.nanmax(np.abs(jx[:10])) < 5, jx[:12] # the jump, in noise units assert step[9] > 50 and abs(step[60]) < 10, (step[9], step[60]) # a step seen 6 h before and after assert np.nanmin(rx[10:30]) > 50 # the other target does not move: residual rej = d["xs"][40, :, names.index("rejected")] assert rej.tolist() == [1, 1, 1] and d["xc"][40, list(d["xc_names"]).index("rej_targets")] == 1 assert np.isnan(d["xs"][:, :, names.index("q_snr")]).all() # no image quality on this camera print("ok")