diff --git a/locklost/summary.py b/locklost/summary.py index 50abc7e10816951beda341fcec1ae1ab6b86650e..24e2b9726303751e3d9d3fb201cb02fc564404fe 100644 --- a/locklost/summary.py +++ b/locklost/summary.py @@ -32,15 +32,13 @@ def grab_data(gps): """ shift_times = { 'H1': [np.arange(0, 8), np.arange(8, 16), np.arange(16, 24)], - 'L1': [np.concatenate(([23], np.arange(0, 8))), np.arange(8, 12), np.arange(12, 22)] + 'L1': [np.concatenate(([22, 23], np.arange(0, 8))), np.arange(8, 12), np.arange(12, 22)] } shift_names = ['owl', 'day', 'eve'] - shifts = { - shift_names[x]: { - 'time': shift_times[config.IFO][x], - 'counts': 0 - } for x in range(3) - } + shifts = defaultdict(lambda: defaultdict(int)) + for x in range(3): + for time in shift_times[config.IFO][x]: + shifts[shift_names[x]][time] = 0 transitions = defaultdict(int) observe_durations = [] saturations = { @@ -102,18 +100,18 @@ def check_tags(event, tags, tag_count): def check_shift(event, shifts): - """Checks which operating shift event happened during. + """Checks which operating shift and hour event happened during. - Checks which operator shift the lockloss gps happened during and increments - a counter for that shift (for locklosses from Observe). + Checks which operator shift and hour the lockloss gps happened during and + increments a counter for that hour (for locklosses from Observe). """ if not event.has_tag('OBSERVE'): return shifts gt = gpstime.fromgps(event.gps) gt = gt.astimezone(local_tz) - for key in shifts: - if gt.hour in shifts[key]['time']: - shifts[key]['counts'] += 1 + for shift_name in shifts: + if gt.hour in shifts[shift_name]: + shifts[shift_name][gt.hour] += 1 break return shifts @@ -280,26 +278,34 @@ def plot_summary(path, epoch): fig.savefig(outpath_plot, bbox_inches='tight') plt.close() - # Lockloss shift plot - counts = [x['counts'] for x in shifts.values()] - shifts = shifts.keys() + # Lockloss shift hour plot + colors = ['#1f77b4', '#dbcb2b', '#b41f2d'] + times = [] + counts =[] + shift_total = [] + for shift_name in shifts: + times.append(shifts[shift_name].keys()) + counts.append(shifts[shift_name].values()) + shift_total.append(sum(shifts[shift_name].values())) fig, ax = plt.subplots(1, figsize=(22, 16)) - shift_x = np.array([0, 1, 2]) - ax.bar( - shift_x, - counts, + for time, count, shift, total, color in zip(times, counts, shifts.keys(), shift_total, colors): + ax.bar( + time, + count, + color=color, + label='{} total count: {}'.format(shift.upper(), total), align='center', ) - ax.set_xlabel('Operating shift', labelpad=10) + ax.set_xlabel('Hour lockloss occurred ({})'.format(local_tz.zone), labelpad=10) ax.set_ylabel('Number of locklosses') - ax.set_title('Number of locklosses per shift: %s' % (epoch)) - ax.set_xticks(shift_x) - ax.set_xticklabels(shifts, rotation=45, ha='right') - ax.set_xlim([-1, shift_x.size]) + ax.set_title('Number of locklosses from observing by hour: {}'.format(epoch)) + ax.set_xlim([-0.9, 23.9]) + ax.grid() + plt.legend(loc='upper left') plt.gcf().text(0.02, 0.02, "Created: {}".format(gpsnow()), fontsize=16) fig.tight_layout() - outpath_plot = os.path.join(epoch_path, 'Lockloss_by_shift') + outpath_plot = os.path.join(epoch_path, 'Lockloss_by_hour') fig.savefig(outpath_plot, bbox_inches='tight') plt.close()