gstlal-inspiral  1.9.3
 All Classes Namespaces Files Functions
gstlal_inspiral_summary_page_lite
1 #!/usr/bin/env python3
2 #
3 # Copyright (C) 2018 Chad Hanna
4 # Copyright (C) 2019 Patrick Godwin
5 #
6 # This program is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License as published by the
8 # Free Software Foundation; either version 2 of the License, or (at your
9 # option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
14 # Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along
17 # with this program; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 
20 import sys, os, glob, shutil, time
21 import re
22 import subprocess
23 import json
24 
25 from optparse import OptionParser
26 from ligo.scald import report
27 
28 ABOUT_URL = 'https://docs.google.com/document/d/12wJjCz8L1UczqRm86q3-EFnpnIZ2FHPSwKR_kym2L5g/pub?embedded=true'
29 SCHEDULE_URL = 'https://docs.google.com/spreadsheets/d/e/2PACX-1vR1XwazhZYoVbMXFZCq_s2rlzyNwcF0xC4kyhnKrCeXFSWte-2jRodL590RU3PsoX4OVypYyAZ7Nl_8/pubhtml?widget=true&headers=false'
30 IMAGE_URL = 'https://results.ligo.uwm.edu/~gstlalcbc/share/vis/gstlal.png'
31 
32 
33 def load_json(path):
34  with open(path, 'r') as f:
35  return json.loads(f.read())
36 
37 
38 def parse_command_line():
39  parser = OptionParser(usage = "%prog [options] [file ...]", description = "%prog summary web page")
40  parser.add_option("--webserver-dir", help = "Set the directory for the webserver. Required. Example /archive/home/channa/public_html/highmass_months_23-24_summary_page")
41  parser.add_option("--open-box", action = "store_true", help = "Produce open box page")
42  parser.add_option("--output-user-tag", action = "append", metavar = "name", help = "Set the basename for image search")
43  parser.add_option("--title", default="gstlal_inspiral offline analysis")
44  parser.add_option("--glob-path", help = "This is the path to search for images")
45 
46  opts, filenames = parser.parse_args()
47  return opts, filenames
48 
49 
50 #
51 # Setup
52 #
53 
54 opts, files = parse_command_line()
55 reportdir = opts.webserver_dir+'_lite'
56 
57 thisreport = report.Report('gstlal analysis', image=IMAGE_URL)
58 
59 try:
60  os.makedirs(reportdir)
61 except OSError:
62  pass
63 
64 #
65 # Add the page tabs
66 #
67 
68 summary = report.Tab('Summary')
69 about_doc = report.Tab('About', url=ABOUT_URL)
70 sched_doc = report.Tab('Schedule', url=SCHEDULE_URL)
71 
72 
73 #
74 # add page header
75 #
76 
77 summary += report.Header('Summary')
78 summary += report.Description("This page was generated on %s by %s in the working directory: %s" % (time.strftime("%Y-%m-%d %H:%M"), os.environ["USER"], os.environ["PWD"]))
79 
80 
81 #
82 # IFAR, ln L plots and table
83 #
84 
85 summary += report.Header('Rate vs. Threshold')
86 summary += report.Description("This section provides the detection statistic plots and a summary of the loudest event.")
87 
88 summary += report.Header('Closed Box Results')
89 imgfooter = "Comparison of single time slide event rate to event rate expected from background as a function of threshold."
90 summary += report.ImageGrid("Rate vs. Threshold", grid_size=3, footer=imgfooter).glob(os.path.join(opts.glob_path, '*5_count_vs_*_closedbox*.png'))
91 
92 tabledata = load_json(os.path.join(opts.glob_path, '%sbgsummary_table.json' % opts.output_user_tag[0]))
93 summary += report.Table('Closed Box Summary Table').save(tabledata, reportdir)
94 
95 if opts.open_box:
96  summary += report.Header('Open Box Results')
97  imgfooter = "Comparison of single time slide event rate to event rate expected from background as a function of threshold."
98  summary += report.ImageGrid("Rate vs. Threshold", grid_size=3, footer=imgfooter).glob(os.path.join(opts.glob_path, '*5_count_vs_*_openbox*.png'))
99 
100  tabledata = load_json(os.path.join(opts.glob_path, '%ssummary_table.json' % opts.output_user_tag[0]))
101  summary += report.Table('Open Box Summary Table').save(tabledata, reportdir)
102 
103 ## Include found/missed as function of decisive characteristic SNR
104 summary += report.Header("Found / Missed Expected SNR")
105 summary += report.Description("""Measuring the found and missed injections as a function of various parameters aids in diagnosing the pipeline as well as providing the expected sensitivity of the pipeline to real signals. The plots in this section show the missed and found injections for the various IFO times for coincident triggers.""")
106 
107 tabledata = load_json(os.path.join(opts.glob_path, '%s_injection_summary.json' % opts.output_user_tag[0]))
108 footer = "Summary of missed and found injections broken up by detector time for %s" % opts.output_user_tag[0]
109 summary += report.Table('Injection Summary Table', footer=footer).save(tabledata, reportdir)
110 
111 plots = os.path.join(opts.glob_path, '*%s*1_dec_expsnr_vs_mchirp_*.png' % opts.output_user_tag[0])
112 imgfooter = "Expected SNR of found and missed injections as a function of chirp mass: %s" % opts.output_user_tag[0]
113 summary += report.ImageGrid("Expected SNR vs. chirp mass", grid_size=4, footer=imgfooter).glob(plots)
114 
115 ## Include missed injection table
116 summary += report.Header("Missed Table")
117 tabledata = load_json(os.path.join(opts.glob_path, '%s_missed_summary.json' % opts.output_user_tag[0]))
118 summary += report.Table('Missed Injection Table for %s' % opts.output_user_tag[0]).save(tabledata, reportdir)
119 
120 
121 ## Include search sensitivity binned by source type
122 summary += report.Header('Search Sensitivity')
123 summary += report.Description("""These plots characterize the overall sensitivity of the search. The detection rate is directly proportional to the observed sensitive volume, which is a function of the significance threshold used to identify candidates. These plots are useful for determining how sensitive the search was to the input injection population. Here we show the sensitivity as a function of source type: BNS mchirp between 0.8 and 2, NSBH between 2 and 4.5, BBH between 4.5 and 45.0, IMBH between 45.0 and 450.0""")
124 
125 plots = os.path.join(opts.glob_path, '*%s*_BINNED_BY_SOURCE_TYPE*.png' % opts.output_user_tag[0])
126 imgfooter = "Binned by source type"
127 summary += report.ImageGrid("Sensitive volume (V*T) and mean sensitive distance: %s" % opts.output_user_tag[0], grid_size=4, footer=imgfooter, visible=False).glob(plots)
128 
129 ## Include horizon distance plots
130 imgfooter = "This is the distance at which you should see a 1.4 1.4 Msun binary at SNR 8. The first panel shows the time evolution of the horizon distance and the second panel shows the same information in histogram form."
131 summary += report.ImageGrid("Horizon distance", grid_size=1, footer=imgfooter).glob(os.path.join(opts.glob_path, '*HORIZON*.png'))
132 
133 ## Search summary
134 tabledata = load_json(os.path.join(opts.glob_path, '%s_plot_summary.json' % opts.output_user_tag[0]))
135 summary += report.Table('Search Summary').save(tabledata, reportdir)
136 
137 ## Include Chi-square distribution plots
138 summary += report.Header("Chi-squared Distributions")
139 summary += report.Description("The chi-squared test checks that the snr accumulated matches expectation.")
140 
141 imgfooter = "Chi-squared vs snr for single detectors after coincidence. Blue points are full data zero lag, red are software injections and black are time slides."
142 summary += report.ImageGrid("Chi-squared Distributions", grid_size=3, footer=imgfooter).glob(os.path.join(opts.glob_path, '*3_chi2_vs_rho_*closedbox*.png'))
143 if opts.open_box:
144  summary += report.ImageGrid("Chi-squared Distributions: Zero lag", grid_size=3, footer=imgfooter).glob(os.path.join(opts.glob_path, '*3_chi2_vs_rho_*openbox*.png'))
145 
146 thisreport += summary
147 thisreport += about_doc
148 thisreport += sched_doc
149 
150 #
151 # write the result
152 #
153 
154 thisreport.save(reportdir, config_name='report_lite')