From e225a5200e9856dd7b87a7dd8610b45dbdd8c1ae Mon Sep 17 00:00:00 2001 From: Camilla Compton Date: Tue, 7 Jul 2020 15:27:09 -0700 Subject: [PATCH 1/5] change shift plot in summary.py to look at hours --- locklost/summary.py | 59 +++++++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/locklost/summary.py b/locklost/summary.py index 50abc7e..1bb2718 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,35 @@ 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_sum = [] + for shift_name in shifts: + times.append(shifts[shift_name].keys()) + counts.append(shifts[shift_name].values()) + shift_sum.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, + shift_x = np.arange(0, len(tags)) + for time, count, shift, sum, color in zip(times, counts, shifts.keys(), shift_sum, colors): + ax.bar( + time, + count, + color=color, + label='{} total count: {}'.format(shift.upper(), sum), align='center', ) - ax.set_xlabel('Operating shift', labelpad=10) + ax.set_xlabel('Hour lockloss occurred (UTC)', 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 Observe) per 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() -- GitLab From 4baafda660ac2e4f253af5abc92d77d2684b7782 Mon Sep 17 00:00:00 2001 From: Camilla Compton Date: Tue, 7 Jul 2020 15:36:27 -0700 Subject: [PATCH 2/5] change variable name from sum to total in summary.py --- locklost/summary.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/locklost/summary.py b/locklost/summary.py index 1bb2718..b5a16eb 100644 --- a/locklost/summary.py +++ b/locklost/summary.py @@ -282,19 +282,19 @@ def plot_summary(path, epoch): colors = ['#1f77b4', '#dbcb2b', '#b41f2d'] times = [] counts =[] - shift_sum = [] + shift_total = [] for shift_name in shifts: times.append(shifts[shift_name].keys()) counts.append(shifts[shift_name].values()) - shift_sum.append(sum(shifts[shift_name].values())) + shift_total.append(sum(shifts[shift_name].values())) fig, ax = plt.subplots(1, figsize=(22, 16)) shift_x = np.arange(0, len(tags)) - for time, count, shift, sum, color in zip(times, counts, shifts.keys(), shift_sum, colors): + 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(), sum), + label='{} total count: {}'.format(shift.upper(), total), align='center', ) ax.set_xlabel('Hour lockloss occurred (UTC)', labelpad=10) -- GitLab From f1f1878321029c4ff8a33966966fa259284f7703 Mon Sep 17 00:00:00 2001 From: Camilla Compton Date: Tue, 7 Jul 2020 15:38:06 -0700 Subject: [PATCH 3/5] remove incorrectley copied line from summary.py --- locklost/summary.py | 1 - 1 file changed, 1 deletion(-) diff --git a/locklost/summary.py b/locklost/summary.py index b5a16eb..0812e10 100644 --- a/locklost/summary.py +++ b/locklost/summary.py @@ -288,7 +288,6 @@ def plot_summary(path, epoch): 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.arange(0, len(tags)) for time, count, shift, total, color in zip(times, counts, shifts.keys(), shift_total, colors): ax.bar( time, -- GitLab From 41dcce49b8175619bf563b618affd985952702a4 Mon Sep 17 00:00:00 2001 From: Camilla Compton Date: Tue, 7 Jul 2020 16:21:50 -0700 Subject: [PATCH 4/5] re-label UTC time to local timezone for hour plot in summary.py --- locklost/summary.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/locklost/summary.py b/locklost/summary.py index 0812e10..58ca6b3 100644 --- a/locklost/summary.py +++ b/locklost/summary.py @@ -296,9 +296,9 @@ def plot_summary(path, epoch): label='{} total count: {}'.format(shift.upper(), total), align='center', ) - ax.set_xlabel('Hour lockloss occurred (UTC)', 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 (from Observe) per hour: {}'.format(epoch)) + ax.set_title('Number of locklosses from observing per hour: {}'.format(epoch)) ax.set_xlim([-0.9, 23.9]) ax.grid() plt.legend(loc='upper left') -- GitLab From f8bafc8685e0543deeec30866319991ef5158a70 Mon Sep 17 00:00:00 2001 From: Camilla Compton Date: Tue, 7 Jul 2020 16:24:53 -0700 Subject: [PATCH 5/5] change wording of hour plot title in summary.py --- locklost/summary.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/locklost/summary.py b/locklost/summary.py index 58ca6b3..24e2b97 100644 --- a/locklost/summary.py +++ b/locklost/summary.py @@ -298,7 +298,7 @@ def plot_summary(path, epoch): ) ax.set_xlabel('Hour lockloss occurred ({})'.format(local_tz.zone), labelpad=10) ax.set_ylabel('Number of locklosses') - ax.set_title('Number of locklosses from observing per hour: {}'.format(epoch)) + 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') -- GitLab