Skip to content
Snippets Groups Projects
Commit 02e8f5c1 authored by Yannick Lecoeuche's avatar Yannick Lecoeuche Committed by Jameson Graef Rollins
Browse files

Mark/Annotate threshold crossings for tags

Add convenience function for adding threshold crossing indicators to
plots.  thresh_crossing variable calculations are added to the
followups that need it.

Also move rcparams function into new plotutils module.
parent dd8871c7
No related branches found
No related tags found
No related merge requests found
import os
import sys
from collections import OrderedDict
import matplotlib.pyplot as plt
IFO = os.getenv('IFO')
if not IFO:
......@@ -498,14 +497,3 @@ LSC_ASC_CHANNELS['ASC Centering Control Signals'] = [
]
for key in LSC_ASC_CHANNELS:
LSC_ASC_CHANNELS[key] = ['%s:%s' % (IFO, chan) for chan in LSC_ASC_CHANNELS[key]]
def set_rcparams():
""" Sets matplotlib parameters for followups. """
plt.rcParams['font.size'] = 30
plt.rcParams['axes.titlesize'] = 30
plt.rcParams['axes.labelsize'] = 30
plt.rcParams['xtick.labelsize'] = 30
plt.rcParams['ytick.labelsize'] = 30
plt.rcParams['legend.fontsize'] = 30
plt.rcParams['agg.path.chunksize'] = 1000
import matplotlib.pyplot as plt
def set_thresh_crossing(ax, thresh_crossing, gps, segment):
""" Plots and annotates vertical position of threshold crossing. """
ax.axvline(
thresh_crossing-gps,
linestyle='--',
color='firebrick',
lw=5,
)
x_fraction = (thresh_crossing-segment[0])/(segment[1]-segment[0])
ax.annotate(
'First threshold crossing',
xy=(x_fraction, 1),
xycoords='axes fraction',
horizontalalignment='center',
verticalalignment='bottom',
bbox=dict(boxstyle="round", fc="w", ec="red", alpha=0.95),
)
def set_rcparams():
""" Sets matplotlib parameters for followups. """
plt.rcParams['font.size'] = 30
plt.rcParams['axes.titlesize'] = 30
plt.rcParams['axes.labelsize'] = 30
plt.rcParams['xtick.labelsize'] = 30
plt.rcParams['ytick.labelsize'] = 30
plt.rcParams['legend.fontsize'] = 30
plt.rcParams['agg.path.chunksize'] = 1000
......@@ -8,6 +8,7 @@ from gwpy.segments import Segment
from ..event import LocklossEvent
from .. import config
from .. import data
from .. import plotutil
#################################################
......@@ -22,7 +23,7 @@ def check_ads(event):
logging.info('lockloss not from nominal low noise')
return
config.set_rcparams()
plotutil.set_rcparams()
mod_window = [config.ADS_SEARCH_WINDOW[0], config.ADS_SEARCH_WINDOW[1]]
segment = Segment(mod_window).shift(int(event.gps))
......@@ -30,7 +31,7 @@ def check_ads(event):
saturating = False
max_ads = 0
first_glitch = segment[1]
thresh_crossing = segment[1]
for buf in ads_channels:
srate = buf.sample_rate
t = np.arange(segment[0], segment[1], 1/srate)
......@@ -40,12 +41,13 @@ def check_ads(event):
saturating = True
glitch_idx = np.where(abs(buf.data) > config.ADS_THRESH)[0][0]
glitch_time = t[glitch_idx]
first_glitch = min(glitch_time, first_glitch)
thresh_crossing = min(glitch_time, thresh_crossing)
if saturating:
event.add_tag('ADS_EXCURSION')
else:
logging.info('no ADS excursion detected')
fig, ax = plt.subplots(1, figsize=(22,16))
for idx, buf in enumerate(ads_channels):
srate = buf.sample_rate
......@@ -71,33 +73,20 @@ def check_ads(event):
color='black',
lw=5,
)
if thresh_crossing != segment[1]:
plotutils.set_thresh_crossing(ax, thresh_crossing, event.gps, segment)
if max_ads < config.ADS_THRESH:
ymin, ymax = -config.ADS_THRESH-0.01, config.ADS_THRESH+0.01
else:
ymin, ymax = -max_ads-0.01, max_ads+0.01
if first_glitch != segment[1]:
ax.axvline(
first_glitch-event.gps,
linestyle='--',
color='firebrick',
lw=5,
)
ax.annotate(
'First threshold crossing',
xy=(first_glitch-event.gps, ymax),
xycoords='data',
textcoords='offset points',
horizontalalignment='center',
verticalalignment='bottom',
bbox=dict(boxstyle="round", fc="w", ec="red", alpha=0.95),
)
ax.grid()
ax.set_xlabel('Time [s] since lock loss at {}'.format(event.gps), labelpad=10)
ax.set_ylabel('ADS Counts')
ax.set_ylim(ymin, ymax)
ax.set_xlim(t[0]-event.gps, t[-1]-event.gps)
ax.legend(loc='best')
ax.set_title('ADS Channels Before Lockloss', y=1.05)
ax.set_title('ADS Channels Before Lockloss', y=1.04)
fig.tight_layout(pad=0.05)
outfile_plot = 'ads.png'
......
......@@ -8,6 +8,7 @@ from gwpy.segments import Segment
from ..event import LocklossEvent
from .. import config
from .. import data
from .. import plotutil
##############################################
......@@ -19,19 +20,23 @@ def check_boards(event):
tag/table if above a certain threshold.
"""
config.set_rcparams()
plotutil.set_rcparams()
mod_window = [config.BOARD_SEARCH_WINDOW[0], config.BOARD_SEARCH_WINDOW[1]]
segment = Segment(mod_window).shift(int(event.gps))
board_channels = data.fetch(config.ANALOG_BOARD_CHANNELS, segment)
saturating = False
thresh_crossing = segment[1]
for buf in board_channels:
srate = buf.sample_rate
t = np.arange(segment[0], segment[1], 1/srate)
before_loss = buf.data[np.where(t<event.gps)]
if any(abs(before_loss) >= config.BOARD_SAT_THRESH):
saturating = True
glitch_idx = np.where(abs(buf.data) > config.BOARD_SAT_THRESH)[0][0]
glitch_time = t[glitch_idx]
thresh_crossing = min(glitch_time, thresh_crossing)
if saturating:
event.add_tag('BOARD_SAT')
......@@ -63,13 +68,15 @@ def check_boards(event):
color='black',
lw=5,
)
if thresh_crossing != segment[1]:
plotutils.set_thresh_crossing(ax, thresh_crossing, event.gps, segment)
ax.grid()
ax.set_xlabel('Time [s] since lock loss at {}'.format(event.gps), labelpad=10)
ax.set_ylabel('Voltage [V]')
ax.set_ylim(-config.BOARD_SAT_THRESH-1, config.BOARD_SAT_THRESH+1)
ax.set_xlim(t[0]-event.gps, t[-1]-event.gps)
ax.legend(loc='best')
ax.set_title('Analog board monitors')
ax.set_title('Analog board monitors', y=1.04)
fig.tight_layout(pad=0.05)
outfile_plot = 'board_sat.png'
......
......@@ -8,6 +8,7 @@ from gwpy.segments import Segment
from ..event import LocklossEvent
from .. import config
from .. import data
from .. import plotutil
#################################################
......@@ -18,7 +19,7 @@ def check_brs(event):
time of lockloss (at both endstations) and creates tag/plot if it is.
"""
config.set_rcparams()
plotutil.set_rcparams()
mod_window = [config.BRS_SEARCH_WINDOW[0], config.BRS_SEARCH_WINDOW[1]]
segment = Segment(mod_window).shift(int(event.gps))
......@@ -27,7 +28,7 @@ def check_brs(event):
glitch_count = 0
max_brs = 0
first_glitch = segment[1]
thresh_crossing = segment[1]
for buf in brs_channels:
max_brs = max([max_brs, max(buf.data)])
if any(buf.data > config.BRS_THRESH):
......@@ -36,7 +37,7 @@ def check_brs(event):
t = np.arange(segment[0], segment[1], 1/srate)
glitch_idx = np.where(buf.data > config.BRS_THRESH)[0][0]
glitch_time = t[glitch_idx]
first_glitch = min(glitch_time, first_glitch)
thresh_crossing = min(glitch_time, thresh_crossing)
if glitch_count > 1:
......@@ -62,19 +63,16 @@ def check_brs(event):
label='BRS glitch threshold',
lw=5,
)
ax.axvline(
first_glitch-event.gps,
linestyle='--',
color='firebrick',
lw=5,
)
if thresh_crossing != segment[1]:
plotutils.set_thresh_crossing(ax, thresh_crossing, event.gps, segment)
ax.grid()
ax.set_xlabel('Time [s] since lock loss at {}'.format(event.gps), labelpad=10)
ax.set_ylabel('RMS Velocity [nrad/s]')
ax.set_ylim(0, max_brs+1)
ax.set_xlim(t[0]-event.gps, t[-1]-event.gps)
ax.legend(loc='best')
ax.set_title('%s BRS BLRMS' % (endstation))
ax.set_title('%s BRS BLRMS' % (endstation), y=1.04)
fig.tight_layout(pad=0.05)
outfile_plot = 'brs_%s.png' % (endstation)
......
......@@ -11,6 +11,7 @@ from gwpy.segments import Segment
from .. import config
from ..event import LocklossEvent
from .. import data
from .. import plotutil
#################################################
......@@ -21,7 +22,7 @@ def find_lpy(event):
"""
config.set_rcparams()
plotutil.set_rcparams()
gps = event.gps
# determine first suspension channel to saturate from saturation plugin
......
......@@ -7,13 +7,14 @@ from gwpy.segments import Segment
from .. import config
from ..event import LocklossEvent
from .. import data
from .. import plotutil
##############################################
def plot_lsc_asc(event):
gps = event.gps
config.set_rcparams()
plotutil.set_rcparams()
for chan_group, channels in config.LSC_ASC_CHANNELS.items():
for window_type, window in config.PLOT_WINDOWS.items():
......
......@@ -10,6 +10,7 @@ from gwpy.segments import Segment
from .. import config
from ..event import LocklossEvent
from .. import data
from .. import plotutil
#################################################
......@@ -21,7 +22,7 @@ def find_saturations(event):
time (and returns corresponding gps times for saturations).
"""
config.set_rcparams()
plotutil.set_rcparams()
saturation_threshold = config.SATURATION_THRESHOLD
low_thresh_channels = config.SIXTEEN_BIT_CHANNELS
......
......@@ -8,6 +8,7 @@ from gwpy.segments import Segment
from ..event import LocklossEvent
from .. import config
from .. import data
from .. import plotutil
##############################################
......@@ -18,7 +19,7 @@ def check_seismic(event):
of lockloss, plot the data, and create a tag if above a certain threshold.
"""
config.set_rcparams()
plotutil.set_rcparams()
mod_window = [config.SEI_SEARCH_WINDOW[0], config.SEI_SEARCH_WINDOW[1]]
segment = Segment(mod_window).shift(int(event.gps))
......
......@@ -8,6 +8,7 @@ from gwpy.segments import Segment
from ..event import LocklossEvent
from .. import config
from .. import data
from .. import plotutil
##############################################
......@@ -19,7 +20,7 @@ def check_wind(event):
if above a certain threshold.
"""
config.set_rcparams()
plotutil.set_rcparams()
mod_window = [config.WIND_SEARCH_WINDOW[0], config.WIND_SEARCH_WINDOW[1]]
segment = Segment(mod_window).shift(int(event.gps))
......@@ -27,10 +28,16 @@ def check_wind(event):
windy = False
max_windspeed = 0
thresh_crossing = segment[1]
for buf in wind_channels:
max_windspeed = max([max_windspeed, max(buf.data)])
if any(buf.data > config.WIND_THRESH):
windy = True
srate = buf.sample_rate
t = np.arange(segment[0], segment[1], 1/srate)
glitch_idx = np.where(buf.data > config.WIND_THRESH)[0][0]
glitch_time = t[glitch_idx]
thresh_crossing = min(glitch_time, thresh_crossing)
if windy:
event.add_tag('WINDY')
......@@ -55,13 +62,15 @@ def check_wind(event):
label='windspeed threshold',
lw=5,
)
if thresh_crossing != segment[1]:
plotutils.set_thresh_crossing(ax, thresh_crossing, event.gps, segment)
ax.grid()
ax.set_xlabel('Time [s] since lock loss at {}'.format(event.gps), labelpad=10)
ax.set_ylabel('Velocity [mph]')
ax.set_ylim(0, max_windspeed+1)
ax.set_xlim(t[0]-event.gps, t[-1]-event.gps)
ax.legend(loc='best')
ax.set_title('End/corner station wind speeds')
ax.set_title('End/corner station wind speeds', y=1.04)
fig.tight_layout(pad=0.05)
outfile_plot = 'windy.png'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment