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# (c) Rainer Corley 2018, Stefan Countryman 2016-2018 

2 

3""" 

4Defines a FileHandler for generating lists of GRBs for an LVC GW trigger 

5(or another trigger at a given time) as well as methods for obtaining 

6historical GRB events from stored lists. 

7""" 

8 

9from llama.utils import RemoteFileCacher 

10from llama.filehandler import JSONFile 

11from llama.files import healpix 

12from llama.files.skymap_info import SkymapInfo 

13from llama.files.lvc_skymap import LvcSkymapHdf5 

14from llama import detectors 

15 

16FILENAMES = ['O1GRBlist.csv', 'O2_GRB_o2abcFermiSwift.csv'] 

17FILES = [ 

18 RemoteFileCacher( 

19 'https://nyc3.digitaloceanspaces.com/llama/llama/objects/' 

20 '95b0620101c135a4b749ffbc45e63d74e1564f5c2f267231741eaad151bd16ed' 

21 ), 

22 RemoteFileCacher( 

23 'https://nyc3.digitaloceanspaces.com/llama/llama/objects/' 

24 '6b7a982152296206ac8bd2c8d6502728f4b3711571e2a854ee3c0aca46f07bf3' 

25 ), 

26] 

27 

28 

29@healpix.HEALPixPSF.set_class_attributes 

30class FermiGRBsJSON(JSONFile, healpix.HEALPixPSF): 

31 """ 

32 New and historical Fermi GRB triggers saved in a JSON file. Triggers 

33 are in a list of JSON objects, where each trigger will have (at least) the 

34 following properties: 

35 

36 ra : float 

37 Right ascension in degrees. 

38 dec : float 

39 Declination in degrees. 

40 sigma : float 

41 Angular uncertainty in degrees. 

42 gps_time : float 

43 GPS time of the trigger. 

44 

45 Additional properties might include: 

46 

47 graceid : str 

48 GraceID of the event, if available. 

49 skymap_url : str 

50 URL of a FITS skymap, if available. 

51 """ 

52 

53 @property 

54 def num_triggers(self): 

55 return len(self.read_json()) 

56 

57 FILENAME = "fermi_grbs.json" 

58 DEPENDENCIES = (SkymapInfo,) 

59 DETECTORS = (detectors.Fermi,) 

60 

61 def _generate(self): # pylint: disable=W0221 

62 gwtime = SkymapInfo(self).event_time_gps_seconds 

63 grbs = get_grbs_from_csv(gwtime-500, gwtime+500) 

64 self._write_json(grbs) 

65 

66 @property 

67 def template_skymap_filehandler(self): 

68 return LvcSkymapHdf5 

69 

70 def source_locations(self): 

71 return [(g['ra'], g['dec'], g['sigma']) for g in self.read_json()] 

72 

73 

74def get_grbs_from_csv(start_time, end_time): 

75 """ Use the get_grbs_from_csv(start_time, end_time) function to obtain a 

76 list of dictionaries of past Gamma-Ray Bursts (GRB)s. The contents of each 

77 GRB dictionary are: 

78 

79 Parameters 

80 ---------- 

81 start_time : int or float 

82 The start time in GPS seconds of the interval in which to search for 

83 GRBs. 

84 end_time : int or float 

85 The end time of the search interval, also in GPS seconds. 

86 

87 Returns 

88 ------- 

89 grbs : list 

90 GRB events in the given time window, where each GRB is a dictionary: 

91 

92 .. code:: python 

93 

94 { 

95 'ra': ra, # Right Ascension of the GRB in [deg] 

96 'dec': dec, # Declination of the GRB [deg] 

97 'sigma': sigma, # Standard deviation of the GRB location [deg] 

98 'time': gps_time, # GPS time of the GRB event [deg] 

99 } 

100 

101 

102 Examples 

103 -------- 

104 >>> grbs = get_grbs_from_csv(1126089475.0,1126200000.0) 

105 >>> sorted(grbs[0]) 

106 ['dec', 'ra', 'sigma', 'time'] 

107 >>> [g['dec'] for g in grbs] 

108 [-21.0339, 73.26, -53.79] 

109 >>> [g['ra'] for g in grbs] 

110 [248.4429, 321.36, 241.05] 

111 >>> [g['sigma'] for g in grbs] 

112 [0.033, 6.38, 1.95] 

113 >>> [g['time'] for g in grbs] 

114 [1126089476.0, 1126103089.0, 1126151534.0] 

115 """ 

116 import numpy as np 

117 # Import and parse into lists 

118 lists = [np.genfromtxt(c.get(), skip_header=1, delimiter=',') 

119 for c in FILES] 

120 full_list = np.concatenate(lists) 

121 num_trigs = len(full_list) 

122 

123 gps_list = full_list[:, 3] 

124 ra_list = full_list[:, 6] 

125 dec_list = full_list[:, 7] 

126 sigma_list = full_list[:, 8] 

127 

128 # Find indices of GRBs between the two GPS times 

129 idxs = [i 

130 for i in range(num_trigs) 

131 if gps_list[i] >= start_time and gps_list[i] <= end_time] 

132 

133 # Make a list of dictionaries for these specific GRBs 

134 dict_list = [] 

135 for i in idxs: 

136 dict_list.append({ 

137 'time': gps_list[i], 

138 'ra': ra_list[i], 

139 'dec': dec_list[i], 

140 'sigma': sigma_list[i] 

141 }) 

142 return dict_list