24 import matplotlib.pyplot
as plt
25 import matplotlib.ticker
as tkr
28 from ligo
import segments
29 from ligo.lw.ligolw
import LIGOLWContentHandler
30 from ligo.lw
import array
as ligolw_array
31 from ligo.lw
import lsctables
32 from ligo.lw
import param
as ligolw_param
33 from ligo.lw
import utils
as ligolw_utils
34 from ligo.lw.utils
import segments
as ligolw_segments
35 from gstlal
import far
49 ligolw_array.use_in(ligolwcontenthandler)
50 ligolw_param.use_in(ligolwcontenthandler)
51 lsctables.use_in(ligolwcontenthandler)
53 def parse_segments_xml(path):
54 llwsegments = ligolw_segments.LigolwSegments(ligolw_utils.load_filename(path,contenthandler=ligolwcontenthandler))
56 'h(t) gate': llwsegments.get_by_name(
u'whitehtsegments'),
57 'state vector': llwsegments.get_by_name(
u'statevectorsegments'),
58 'trigger buffers': llwsegments.get_by_name(
u'triggersegments') }
60 seglistdicts[
'joint segments'] = {
'H1L1': seglistdicts[
'state vector'].intersection([
'H1',
'L1'])}
64 def plot_segments_history(seglistdicts, segments_to_plot = ['trigger buffers', 'h(t) gate
', 'state vector
'], t_max = None, length = 86400., labelspacing = 10800., colors = {'H1
': numpy.array((1.0, 0.0, 0.0)), 'L1
': numpy.array((0.0, 0.8, 0.0)), 'V1
': numpy.array((1.0, 0.0, 1.0)), 'H1L1
': numpy.array((.5, .5, .5))}, fig = None, axes = None):
66 fig = plt.figure(figsize=(15,5),)
68 axes = fig.add_subplot(111)
72 t_max = float(lal.GPSTimeNow())
74 seglist_to_drop = segments.segmentlist([segments.segment(lal.LIGOTimeGPS(t_max),segments.PosInfinity)])
75 for seglistdict
in seglistdicts.values():
76 for seglist
in seglistdict.values():
77 seglist -= seglist_to_drop
78 t_min = t_max - length
85 color_dict = {
'H1': numpy.array((1.0, 0.0, 0.0)),
'L1': numpy.array((0.0, 0.8, 0.0)),
'V1': numpy.array((1.0, 0.0, 1.0)),
'H1L1': numpy.array((.5, .5, .5))}
86 x_format = tkr.FuncFormatter(
lambda x, pos: datetime.datetime(*lal.GPSToUTC(int(x))[:7]).strftime(
'%Y-%m-%d, %H:%M:%S UTC'))
87 x_ticks = numpy.arange(t_min,t_max+labelspacing, labelspacing)
89 for j, segtype
in enumerate(segments_to_plot):
90 for row, (ifo, segmentlist)
in enumerate(seglistdicts[segtype].items()):
91 y_ticks.append(row + 2*j + 0.5)
92 y_tick_labels.append(
'%s %s' % (ifo, segtype))
93 bottom.extend([row + 2*j + 0.25] * len(segmentlist))
94 color_list.extend([color_dict[ifo]] * len(segmentlist))
95 for segment
in segmentlist:
96 width.append(float(segment[1]) - float(segment[0]))
97 left_edge.append(float(segment[0]))
99 edgecolor_list = [
'w'] * len(bottom)
100 fig.patch.set_alpha(0.0)
101 axes.barh(bottom, width, height=0.5, left=left_edge, color=color_list, edgecolor=edgecolor_list)
102 plt.xlim([t_min, t_max])
103 axes.xaxis.set_major_formatter(x_format)
104 plt.yticks(y_ticks, y_tick_labels)
105 plt.xticks(x_ticks, rotation=10.)
106 axes.tick_params(axis=
'y',which=
'both',left=
'off',right=
'off')
107 axes.grid(color=(0.1,0.4,0.5), linewidth=2)
112 fig.tight_layout(pad = .8)
114 except AttributeError: