"""Apply one pruning variant (a rule removed) to a copy of the detectors: variant.py ; --list lists them.""" import sys from pathlib import Path V = { "whole_step": ("displacement.py", "abs(d) >= SIZE * ampl and step <= abs(d) / 2 and back", "abs(d) >= SIZE * ampl and back"), "whole_retreat": ("displacement.py", " and back <= RETREAT * abs(d) else []", " else []"), "piece_step": ("displacement.py", "if d and abs(d) >= PIECE * ampl and step <= PIECE * ampl / 2:", "if d and abs(d) >= PIECE * ampl:"), "hours": ("displacement.py", "if len({m[\"t\"].hour for m in dm}) >= HOURS / 24 * slots)", ")"), "no_pieces": ("displacement.py", "else [(p, a) for a in axes for p in _pieces(*a)]", "else []"), "no_whole": ("displacement.py", "whole = [(w, a) for a in axes for w in _whole(*a)]", "whole = []"), "together": ("displacement.py", "for name, ms in [*targets.items(), (\"\", _together(targets, axis))]:", "for name, ms in targets.items():"), "floor": ("displacement.py", "floor = FLOOR * statistics.median(ns) if ns else 0", "floor = 0"), } V2 = { # after S1 (the whole-window drift removed) "two_days": ("displacement.py", 'axes = [a for col in ("corr_x", "corr_y") if len((a := _days(ms, col))[0]) >= 2]', 'axes = [_days(ms, col) for col in ("corr_x", "corr_y")]'), "together_one": ("displacement.py", 'if name or (state == "back" and a == b)}', 'if name or state == "back"}'), "bridge0": ("target_issue.py", "BRIDGE = 1 ", "BRIDGE = 0 "), "piece_tiebreak": ("displacement.py", "key=lambda x: (-abs(x[0]), x[2] - x[1])", "key=lambda x: -abs(x[0])"), } V.update(V2) if sys.argv[1] == "--list": print("\n".join(V2 if sys.argv[2:] == ["2"] else V)); sys.exit() f, old, new = V[sys.argv[2]] p = Path(sys.argv[1]) / "scripts" / f s = p.read_text() assert s.count(old) == 1, (sys.argv[2], s.count(old)) p.write_text(s.replace(old, new))