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) Stefan Countryman, 2019 

2 

3""" 

4Download the UW Madison GW/High Energy Neutrino analysis summary results for a 

5given event. 

6""" 

7 

8import re 

9from requests import get 

10from requests.auth import HTTPBasicAuth 

11from llama.filehandler import ( 

12 FileHandler, 

13) 

14from llama.filehandler.mixins import ( 

15 OnlineVetoMixin, 

16) 

17from llama.files.lvc_gcn_xml import LvcGcnXml 

18from llama.intent import CoolDownParams 

19 

20 

21@FileHandler.set_class_attributes 

22class UwSummary(FileHandler, OnlineVetoMixin): 

23 """ 

24 The UW Madison group's LaTeX summary of a GW/HEN joint trigger. 

25 """ 

26 

27 DEPENDENCIES = ( 

28 LvcGcnXml, 

29 ) 

30 

31 FILENAME = 'uw_summary.tex' 

32 COOLDOWN_PARAMS = CoolDownParams(base=20, increment=5, maximum=240*60) 

33 

34 def _generate(self): 

35 # https://icecube.wisc.edu/~rhussain/O3_followups/S190814bv-2-Initial/ 

36 event = LvcGcnXml(self).ivorn.split('LVC#')[-1] 

37 url = f"https://icecube.wisc.edu/~rhussain/O3_followups/{event}/r.tex" 

38 res = get(url, auth=HTTPBasicAuth(ICECUBE_USERNAME, ICECUBE_PASSWORD)) 

39 if res.status_code == 404: 

40 raise GenerationError(f"UW Madison summary not ready at {url}") 

41 if res.status_code != 200: 

42 raise GenerationError(f"Unexpected error code {res.status_code}, " 

43 f"dumping result: {res.content}") 

44 with open(self.filename, 'wb') as outfile: 

45 outfile.write(res.content) 

46 

47 @property 

48 def p_value(self): 

49 """Extract the UW Madison p-value from their summary TeX file.""" 

50 with self.open() as summary: 

51 matches = set(re.findall(r"P value & ([\d.]+)", summary.read())) 

52 if len(matches) != 1: 

53 raise ValueError("Could not find a unique p-value. Instead, got " 

54 f"{matches}") 

55 return float(matches.pop())