forked from gwastro/pycbc-live-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pycbclive_duty_factor_stats.py
executable file
·70 lines (58 loc) · 2.08 KB
/
pycbclive_duty_factor_stats.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python
"""Read the duty factors from a PyCBC Live log and show some stats about them."""
import argparse
import numpy as np
import matplotlib.pyplot as pp
def plot_cdf_nicely(x, **kwa):
"""A nicer version of pp.hist([...] cumulative=-1): it does not bin and
does not plot a spurious vertical line at the lowest sample.
"""
sorter = np.argsort(x)
fraction = np.arange(len(x))[::-1] / len(x)
pp.step(np.array(x)[sorter], fraction, **kwa)
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--input-log', required=True)
parser.add_argument('--out-plot')
args = parser.parse_args()
duty_factors = {}
with open(args.input_log, 'r') as lf:
for line in lf:
if 'Took' not in line:
continue
pieces = line.split()
rank = int(pieces[3])
duty_factor = float(pieces[9].replace(',', ''))
if rank not in duty_factors:
duty_factors[rank] = []
duty_factors[rank].append(duty_factor)
print('Duty factors:')
for rank in sorted(duty_factors):
print('{:04d}: {:d} samples, median {:.2f}, 90th percentile {:.2f}'.format(
rank,
len(duty_factors[rank]),
np.median(duty_factors[rank]),
np.percentile(duty_factors[rank], 90)
))
if args.out_plot is not None:
df_max = 0
df_min = np.inf
for rank in sorted(duty_factors):
color = pp.cm.viridis(rank / max(duty_factors))
lw = 2 if rank == 0 else 0.5
plot_cdf_nicely(duty_factors[rank], color=color, lw=lw)
df_max = max(df_max, max(duty_factors[rank]))
df_min = min(df_min, min(duty_factors[rank]))
pp.axvspan(
1, df_max, hatch='/', facecolor='none', edgecolor='gray'
)
pp.xscale('log')
pp.xlim(max(df_min, 0.1), df_max)
pp.ylim(0, 1)
pp.xlabel('Duty factor')
pp.ylabel('Cumulative fraction')
pp.title('Median at rank 0: {:.2f} {}'.format(
np.median(duty_factors[0]),
'\N{CHECK MARK}' if np.median(duty_factors[0]) < 1 else '\N{WARNING SIGN}'
))
pp.tight_layout()
pp.savefig(args.out_plot, dpi=200)