You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Chameleon/integration/ptz_predictive_zoom/check_replay_latency.py

89 lines
4.4 KiB
Python

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

"""Stress the pinned offline replay with independent video and ISAPI delays."""
import argparse
import json
from pathlib import Path
import replay_broad_tele as replay
DELAYS = ((180, 40), (180, 60), (220, 50), (250, 40), (250, 60))
SCENARIOS = ("wide", "tele", "tele_tail", "tele_centered", "tele_centered_tail")
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("output", type=Path, help="new directory for comparison and replay traces")
parser.add_argument("--scenario", action="append", choices=SCENARIOS)
parser.add_argument("--centered-hfov", type=float, default=13.)
parser.add_argument("--delay", nargs=2, action="append", type=int, metavar=("VIDEO_MS", "ISAPI_RTT_MS"))
args = parser.parse_args()
if not 10. <= args.centered_hfov < 18.:
parser.error("--centered-hfov must be at least 10 and below 18 degrees")
delays = tuple(dict.fromkeys(map(tuple, args.delay))) if args.delay else DELAYS
if any(not (180 <= video <= 250 and 40 <= api <= 60 and video % 10 == api % 10 == 0)
for video, api in delays):
parser.error("--delay must use 10 ms steps within 180–250 video and 40–60 ISAPI")
import torch
torch.set_num_threads(1)
pinned = replay.read(Path(__file__).with_name("pins.json"))
if replay.read(replay.NEW_PINS) != pinned:
raise ValueError("Local PR10 replay snapshot does not match the repository pins")
args.output.mkdir(parents=True, exist_ok=False)
field, pulses = replay.read(replay.FIELD), replay.read(replay.PULSES)
profiles = replay.read(replay.DATA / "profiles.json")["cameras"]
steering = replay.read(replay.LAB / "field-calibration-report.json")["cameras"]
report = []
for camera, (early, late) in replay.FLIGHTS.items():
episodes = pulses["episodes"][camera]
wide, narrow = (
replay.trajectory(camera, next(e for e in episodes if e["started_at"][11:19] == key), field)
for key in (late, early)
)
wide = dict(wide, duration=min(7., wide["duration"]))
narrow = dict(narrow, stress=True, edge_stress=True, duration=min(5., narrow["duration"]))
# A deliberately small, slow target creates genuine repeat-zoom
# opportunities at the floor. Keep it separate from reconstructed AIM.
centered = dict(
camera=int(camera), episode=None, duration=4.,
knots=((0., 0., 0.), (4., .24, .08)), angular_extent=(.28, .18),
initial_pose_offset_fov=(0., 0.),
)
for scenario, trace, fov, tail_ms in (
("wide", wide, 59., 0), ("tele", narrow, 12., 0), ("tele_tail", narrow, 12., 80),
("tele_centered", centered, args.centered_hfov, 0),
("tele_centered_tail", centered, args.centered_hfov, 80),
):
if args.scenario and scenario not in args.scenario:
continue
for video, api in delays:
row = dict(camera=int(camera), episode=trace["episode"], scenario=scenario,
video_ms=video, isapi_rtt_ms=api, initial_hfov_deg=fov, lens_tail_ms=tail_ms,
results={})
for revision in ("PR8", "BT"):
result = replay.run(
trace, profiles[camera]["replay_settings"], steering[camera]["fit"],
revision, video, api, fov, plant_stress=fov < 59., put_rtt=True, lens_tail_ms=tail_ms,
)
filename = f"{camera}-{scenario}-{video}-{api}-{revision}.json"
(args.output / filename).write_text(
json.dumps(result, allow_nan=False, separators=(",", ":")) + "\n", encoding="utf-8",
)
row["results"][revision] = dict(
trace=filename, metrics=result["metrics"],
before_first=result["zoom_block_reason_before_first"],
simultaneous_before_first=result["simultaneous_flags_before_first"],
)
report.append(row)
bt = row["results"]["BT"]["metrics"]
print(camera, scenario, video, api, bt["hfov_min"], bt["edge_during_narrowing_steps"],
bt["narrowing_below_floor_steps"], flush=True)
(args.output / "comparison.json").write_text(
json.dumps(report, indent=2, allow_nan=False) + "\n", encoding="utf-8",
)
if __name__ == "__main__":
main()