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#!/usr/bin/env python 

2# (c) Stefan Countryman 2016-2018, Rainer Corley 2016 

3 

4""" 

5``FileHandler`` for making a nicely-formatted LaTeX table of IceCube neutrinos 

6including their reconstructed properties and their joint significance when 

7combined with a gravitational wave. 

8""" 

9 

10import json 

11from llama.filehandler import FileHandler 

12from llama.files.skymap_info import SkymapInfo 

13from llama.files.i3.json import ( 

14 IceCubeNeutrinoList, 

15 Neutrino, 

16) 

17from llama.files.coinc_significance import CoincSignificanceI3Lvc 

18 

19NEUTRINO_LIST_HEADER_FORMAT = ( 

20 r"No." 

21 r" & {}" # we can do t_nu - t_GW or just UTC time; decided later 

22 r" & RA [deg]" 

23 r" & Dec [deg]" 

24 r" & $E$ [TeV]" 

25 r" & $\sigma$ [deg]" 

26 r"{}" # if we are including p-value, it goes here 

27 r" \\" 

28 "\n" 

29 r"\hline" 

30 "\n" 

31) 

32NEUTRINO_LIST_ROW_FORMAT = ( 

33 r"{number}" 

34 r" & {time:11.2f}" 

35 r" & {ra:11.2f}" 

36 r" & {dec:11.2f}" 

37 r" & {energy:11.2f}" 

38 r" & {sigma:11.2f}" 

39 r"{p_value}" 

40 r" \\" 

41 "\n" 

42) 

43AUXILLIARY_DATA_HEADER_FORMAT = ( 

44 r"No." 

45 r" & {}" # we can do t_nu - t_GW or just UTC time; decided later 

46 r" & RA [deg]" 

47 r" & Dec [deg]" 

48 r" & $E$ [TeV]" 

49 r" & $\sigma$ [deg]" 

50 r"{}" # if we are including p-value, it goes here 

51 r" \\" 

52 "\n" 

53 r"\hline" 

54 "\n" 

55) 

56AUXILLIARY_DATA_ROW_FORMAT = ( 

57 r"{number}" 

58 r" & {time:11.2f}" 

59 r" & {ra:11.2f}" 

60 r" & {dec:11.2f}" 

61 r" & {energy:11.2f}" 

62 r" & {sigma:11.2f}" 

63 r"{p_value}" 

64 r" \\" 

65 "\n" 

66) 

67LATEX_FOOTER = r"""\end{tabular} 

68\caption{ 

69 List of neutrinos used in the joint LLAMA analysis. P-values and odds 

70 ratios (our test statistic) are the values that each neutrino would have if 

71 it were the only neutrino received; they should be interpreted as 

72 indications of which neutrinos contributed the most to the final test 

73 statistic. 

74} 

75\label{fig:coinc-scatterplot} 

76\end{table*}""" 

77 

78 

79def latex_header(num_cols): 

80 """Return a header with the appropriate number of columns for a LaTeX table 

81 section.""" 

82 return (r"\begin{table*}" "\n" 

83 r"\centering" "\n" 

84 r"\small" "\n" 

85 r"\begin{tabular}{") + '|'.join(num_cols*["l"]) + "}\n" 

86 

87 

88@FileHandler.set_class_attributes 

89class IceCubeNeutrinoListTex(FileHandler): 

90 """ 

91 A list of neutrinos and their reconstructed properties as well as the 

92 significance of the joint event) in LaTeX format suitable for use in papers 

93 and coincident skymap summary plots. 

94 """ 

95 

96 FILENAME = "IceCubeNeutrinoList.tex" 

97 DEPENDENCIES = ( 

98 IceCubeNeutrinoList, 

99 SkymapInfo, 

100 CoincSignificanceI3Lvc, 

101 ) 

102 

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

104 infilename = IceCubeNeutrinoList(self).fullpath 

105 outfilename = self.fullpath 

106 gpstime = SkymapInfo(self).event_time_gps 

107 pvals = CoincSignificanceI3Lvc(self).p_values 

108 convert_json_neutrinos_to_latex(infilename, outfilename, 

109 gpstime=gpstime, p_values=pvals) 

110 

111 

112def convert_json_neutrinos_to_latex(infilename, outfilename, gpstime=None, 

113 p_values=None): 

114 """Take a json-formatted input filename and an output filename (both full 

115 paths) as arguments. Convert the neutrino list in the infile into a 

116 LaTeX table that can be inserted into a LaTeX document and save it to the 

117 path specified in outfilename. If an optional gpstime is given, then the 

118 time column will be given as the time difference in seconds between the 

119 neutrino's arrival and the GPS time provided, i.e. the neutrino detection 

120 time with t=0 defined as the GPS time. If a list of ``p_values`` 

121 corresponding to the neutrinos in ``infilename`` are provided, then an 

122 extra column is added with the P-values.""" 

123 with open(infilename, 'r') as infile: 

124 data = json.load(infile) 

125 if isinstance(data, dict): 

126 triggers = data['triggers'] 

127 else: 

128 triggers = data 

129 neutrinos = [Neutrino(**n) for n in triggers] 

130 # if p-values are provided, include a column for them 

131 if p_values is None: 

132 pvalue_title = "" 

133 pval = "" 

134 else: 

135 pvalue_title = r" & P-Value" 

136 # if gpstime is provided, use that as t_0 

137 if gpstime is None: 

138 time_title = r'$t_{\nu} [GPS]' 

139 gpstime = 0 

140 else: 

141 time_title = r'$t_{\nu}-t_{GW}$ [s]' 

142 with open(outfilename, 'w') as out: 

143 # write the start of the LaTeX table 

144 out.write(latex_header(6 if p_values is None else 7)) 

145 # write the header column showing column variables 

146 out.write(NEUTRINO_LIST_HEADER_FORMAT.format(time_title, pvalue_title)) 

147 # write each neutrino to its own column 

148 for i, neutrino in enumerate(neutrinos): 

149 # if p-values are provided, also write them to their own column 

150 if p_values is not None: 

151 pval = r" & {:11.8f}".format(p_values[i]) 

152 out.write( 

153 NEUTRINO_LIST_ROW_FORMAT.format( 

154 number=i+1, 

155 time=neutrino.gps-gpstime, 

156 ra=neutrino.ra, 

157 dec=neutrino.dec, 

158 energy=neutrino.energy*1e-3, # GeV -> TeV 

159 sigma=neutrino.sigma, 

160 p_value=pval, 

161 ) 

162 ) 

163 out.write(LATEX_FOOTER)