Coverage for gwcelery/tasks/rrt_utils.py: 100%
38 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-11-14 05:52 +0000
« prev ^ index » next coverage.py v7.4.4, created at 2024-11-14 05:52 +0000
1import json
3from ligo.skymap.io import read_sky_map
4from ligo.skymap.postprocess.crossmatch import crossmatch
6from .. import app
7from ..util.tempfile import NamedTemporaryFile
8from . import gracedb
11@app.task(shared=False)
12def check_high_profile(skymap, em_bright,
13 p_astro, superevent):
14 superevent_id = superevent['superevent_id']
15 # conditions are defined in L2100046
16 # RAVEN_ALERT HIGH_PROFILE is implemented in raven.py
17 # Checking if the label is applied beforehand
18 if 'HIGH_PROFILE' in superevent['labels']:
19 return "HIGH_PROFILE already applied"
21 # low-far unmodelled burst condition
22 far_list = []
23 gw_events = superevent["gw_events"]
24 for event in gw_events:
25 events_dict = gracedb.get_event(event)
26 far_list.append({"group": events_dict["group"],
27 "search": events_dict["search"],
28 "far": events_dict["far"]})
29 far_list_sorted = sorted(far_list, key=lambda k: k["far"])
31 if far_list_sorted[0]["group"] == "Burst" and \
32 far_list_sorted[0]["search"] != "BBH":
33 gracedb.create_label.si(
34 'HIGH_PROFILE', superevent_id).delay()
35 return "Event with the lowest FAR is a Burst event. Applying label"
37 # annotation number condition
38 preferred_event = superevent['preferred_event_data']
39 if preferred_event["group"] == "CBC":
40 em_bright_dict = json.loads(em_bright)
41 has_remnant = em_bright_dict['HasRemnant']
43 pastro_dict = json.loads(p_astro)
44 p_bns = pastro_dict['BNS']
45 p_terr = pastro_dict['Terrestrial']
46 p_nsbh = pastro_dict['NSBH']
48 with NamedTemporaryFile(content=skymap) as skymap_file:
49 gw_skymap = read_sky_map(skymap_file.name, moc=True)
50 cl = 90
51 result = crossmatch(gw_skymap, contours=[cl / 100])
52 sky_area = result.contour_areas[0]
54 if p_terr < 0.5:
55 if (p_bns > 0.1 or p_nsbh > 0.1 or has_remnant > 0.1 or sky_area < 100): # noqa: E501
56 gracedb.create_label.si(
57 'HIGH_PROFILE', superevent_id).delay()
58 return "Annotations condition satisfied. Applying label"
59 return "No conditions satisfied. Skipping"