24 lines
1.1 KiB
Python
24 lines
1.1 KiB
Python
# Lists the Perturbation labels of the given stations that a Perturbation event of detectors copy A overlaps and no Perturbation event of copy B does (what B absorbed). Args: <labels folder> <data folder> <detectors A> <detectors B> STATION...
|
|
import json
|
|
import subprocess
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
labels_dir, data_dir, a, b, *stations = sys.argv[1:]
|
|
|
|
|
|
def perturbations(det, st):
|
|
out = subprocess.run([sys.executable, str(Path(det) / "scripts" / "categories.py"), str(Path(data_dir) / st)],
|
|
capture_output=True, text=True).stdout
|
|
return [(l.split()[0], l.split()[2]) for l in out.splitlines() if " Perturbation " in l]
|
|
|
|
|
|
for st in stations:
|
|
pa, pb = perturbations(a, st), perturbations(b, st)
|
|
for l in map(json.loads, filter(str.strip, open(Path(labels_dir) / f"{st}.jsonl"))):
|
|
if l["family"] != "Perturbation":
|
|
continue
|
|
hit = lambda ev: any(s <= l["end"] and e >= l["start"] for s, e in ev) # noqa: E731
|
|
if hit(pa) and not hit(pb):
|
|
print(st, l["id"], l["start"], l["end"], "|", l["description"][:200])
|