Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

from lxml import etree 

from urllib.parse import urlparse 

from celery.utils.log import get_logger 

 

from . import detchar 

from . import gcn 

from . import gracedb 

from . import ligo_fermi_skymaps 

from . import lvalert 

from . import raven 

 

log = get_logger(__name__) 

 

 

@gcn.handler(gcn.NoticeType.SNEWS, 

queue='exttrig', 

shared=False) 

def handle_snews_gcn(payload): 

"""Handles the payload from SNEWS alerts. 

 

Prepares the alert to be sent to graceDB as 'E' events. 

""" 

root = etree.fromstring(payload) 

 

# Get TrigID and Test Event Boolean 

trig_id = root.find("./What/Param[@name='TrigID']").attrib['value'] 

test_event = root.find("./What/Group[@name='Trigger_ID']" + 

"/Param[@name='Test']").attrib['value'] 

 

event_observatory = 'SNEWS' 

query = 'group: External pipeline: {} grbevent.trigger_id = "{}"'.format( 

event_observatory, trig_id) 

events = gracedb.get_events(query=query) 

 

if events: 

assert len(events) == 1, 'Found more than one matching GraceDB entry' 

event, = events 

graceid = event['graceid'] 

gracedb.replace_event(graceid, payload) 

return 

 

elif test_event == 'true': 

graceid = gracedb.create_event(filecontents=payload, 

search='Supernova', 

group='Test', 

pipeline=event_observatory) 

 

else: 

graceid = gracedb.create_event(filecontents=payload, 

search='Supernova', 

group='External', 

pipeline=event_observatory) 

event = gracedb.get_event(graceid) 

start, end = event['gpstime'], event['gpstime'] 

# Pre-start and post-end padding is applied by check_vectors 

detchar.check_vectors(event, event['graceid'], start, end) 

 

 

@gcn.handler(gcn.NoticeType.FERMI_GBM_ALERT, 

gcn.NoticeType.FERMI_GBM_FLT_POS, 

gcn.NoticeType.FERMI_GBM_GND_POS, 

gcn.NoticeType.FERMI_GBM_FIN_POS, 

gcn.NoticeType.SWIFT_BAT_GRB_ALERT, 

gcn.NoticeType.SWIFT_BAT_GRB_LC, 

gcn.NoticeType.FERMI_GBM_SUBTHRESH, 

queue='exttrig', 

shared=False) 

def handle_grb_gcn(payload): 

"""Handles the payload from Fermi and Swift alerts. 

 

Prepares the alert to be sent to graceDB as 'E' events. 

""" 

root = etree.fromstring(payload) 

u = urlparse(root.attrib['ivorn']) 

stream_path = u.path 

 

# Get TrigID 

try: 

trig_id = root.find("./What/Param[@name='TrigID']").attrib['value'] 

except AttributeError: 

trig_id = root.find("./What/Param[@name='Trans_Num']").attrib['value'] 

 

stream_obsv_dict = {'/SWIFT': 'Swift', 

'/Fermi': 'Fermi'} 

event_observatory = stream_obsv_dict[stream_path] 

 

reliability = root.find("./What/Param[@name='Reliability']") 

if reliability is not None and int(reliability.attrib['value']) <= 4: 

return 

 

ivorn = root.attrib['ivorn'] 

if 'subthresh' in ivorn.lower(): 

search = 'SubGRB' 

else: 

search = 'GRB' 

 

query = 'group: External pipeline: {} grbevent.trigger_id = "{}"'.format( 

event_observatory, trig_id) 

events = gracedb.get_events(query=query) 

 

if events: 

assert len(events) == 1, 'Found more than one matching GraceDB entry' 

event, = events 

graceid = event['graceid'] 

gracedb.replace_event(graceid, payload) 

 

else: 

graceid = gracedb.create_event(filecontents=payload, 

search=search, 

group='External', 

pipeline=event_observatory) 

event = gracedb.get_event(graceid) 

start = event['gpstime'] 

end = start + event['extra_attributes']['GRB']['trigger_duration'] 

detchar.check_vectors(event, event['graceid'], start, end) 

ligo_fermi_skymaps.get_upload_external_skymap(graceid) 

 

 

@lvalert.handler('superevent', 

'mdc_superevent', 

'external_fermi', 

'external_grb', 

'external_swift', 

shared=False) 

def handle_grb_lvalert(alert): 

"""Parse an LVAlert message related to superevents/GRB external triggers 

and dispatch it to other tasks. 

 

Notes 

----- 

This LVAlert message handler is triggered by creating a new superevent or 

GRB external trigger event, or applying the ``EM_COINC`` label to any 

superevent: 

 

* Any new event triggers a coincidence search with 

:meth:`gwcelery.tasks.raven.coincidence_search`. 

* The ``EM_COINC`` label triggers the creation of a combined GW-GRB sky map 

using :meth:`gwcelery.tasks.ligo_fermi_skymaps.create_combined_skymap`. 

 

""" 

# Determine GraceDB ID 

graceid = alert['uid'] 

 

if alert['alert_type'] == 'new' and \ 

alert['object'].get('group', '') == 'External': 

raven.coincidence_search(graceid, alert['object'], group='CBC') 

raven.coincidence_search(graceid, alert['object'], 

group='Burst') 

elif graceid.startswith('S'): 

preferred_event_id = gracedb.get_superevent(graceid)['preferred_event'] 

group = gracedb.get_event(preferred_event_id)['group'] 

if alert['alert_type'] == 'new': 

raven.coincidence_search(graceid, alert['object'], 

group=group, 

pipelines=['Fermi', 'Swift']) 

elif alert['alert_type'] == 'label_added' and \ 

alert['data']['name'] == 'EM_COINC': 

ligo_fermi_skymaps.create_combined_skymap(graceid).delay() 

 

 

@lvalert.handler('superevent', 

'mdc_superevent', 

'external_snews', 

shared=False) 

def handle_snews_lvalert(alert): 

"""Parse an LVAlert message related to superevents/SN external triggers and 

dispatch it to other tasks. 

 

Notes 

----- 

This LVAlert message handler is triggered by creating a new superevent or 

SN external trigger event, or applying the ``EM_COINC`` label to any 

superevent: 

 

* Any new event triggers a coincidence search with 

:meth:`gwcelery.tasks.raven.coincidence_search`. 

 

""" 

# Determine GraceDB ID 

graceid = alert['uid'] 

 

if alert['object'].get('group', '') == 'Test': 

pass 

elif alert['alert_type'] == 'new' and \ 

alert['object'].get('group', '') == 'External': 

raven.coincidence_search(graceid, alert['object'], 

group='Burst', pipelines=['SNEWS']) 

elif graceid.startswith('S'): 

preferred_event_id = gracedb.get_superevent(graceid)['preferred_event'] 

group = gracedb.get_event(preferred_event_id)['group'] 

if alert['alert_type'] == 'new' and group == 'Burst': 

raven.coincidence_search(graceid, alert['object'], 

group=group, pipelines=['SNEWS'])