import matplotlib.pyplot as plt plt.style.use('seaborn-colorblind') import numpy as np import scipy.signal as sig import library as lib #------------------------------------------------------------------------------- # Load and Trim Data #------------------------------------------------------------------------------- # Since we want coherent data, grab x,y and z seismic channels. # Add these to random noise and inject a 22 Hz line fs, dur = 128, 512 channels = ['H1:PEM-CS_SEIS_LVEA_VERTEX_X_DQ', 'H1:PEM-CS_SEIS_LVEA_VERTEX_Y_DQ', 'H1:PEM-CS_SEIS_LVEA_VERTEX_Z_DQ'] wits = lib.stream_data(1253370524, channels, dur=dur, fsup=fs, ifo='H1') for chan in range(wits.shape[0]): wits[chan, :] -= np.mean(wits[chan, :]) fig, ax = plt.subplots(3, 1, sharex=False, sharey=False, figsize=(8, 7.5)) f, xpsd = sig.welch(wits[0, :], fs=fs) _, ypsd = sig.welch(wits[1, :], fs=fs) _, zpsd = sig.welch(wits[2, :], fs=fs) ff, xy = sig.coherence(wits[0, :], wits[1, :], fs=fs) ff, xz = sig.coherence(wits[0, :], wits[2, :], fs=fs) ff, yz = sig.coherence(wits[1, :], wits[2, :], fs=fs) ax[0].semilogy(f, xpsd, label='$\hat{x}$') ax[0].semilogy(f, ypsd, label='$\hat{y}$') ax[0].semilogy(f, zpsd, label='$\hat{z}$')
asc_chans = [ 'H1:ASC-PRC1_Y_INMON', 'H1:ASC-PRC2_P_INMON', 'H1:ASC-SRC2_Y_INMON', 'H1:ASC-DHARD_Y_INMON', 'H1:ASC-INP1_P_INMON', 'H1:ASC-INP1_Y_INMON', 'H1:ASC-MICH_P_INMON', 'H1:ASC-MICH_Y_INMON', 'H1:ASC-PRC1_P_INMON', 'H1:ASC-PRC2_Y_INMON', 'H1:ASC-SRC1_P_INMON', 'H1:ASC-SRC1_Y_INMON', 'H1:ASC-SRC2_P_INMON', 'H1:ASC-DHARD_P_INMON', 'H1:ASC-CHARD_P_INMON', 'H1:ASC-CHARD_Y_INMON', 'H1:ASC-DSOFT_P_INMON', 'H1:ASC-DSOFT_Y_INMON', 'H1:ASC-CSOFT_P_INMON', 'H1:ASC-CSOFT_Y_INMON' ] fs_fast, fs_slow, dur = 512, 16, 2048 st = 1242457832 et = st + dur if not os.path.isfile('darm.mat'): darm = lib.stream_data(st, [darm_chan], fs=fs_fast, dur=dur) darm = darm.reshape(darm.shape[1]) sio.savemat('darm.mat', mdict={'data': darm}) else: darm = sio.loadmat('darm.mat')['data'] darm = darm.reshape(darm.shape[1]) low, high = 56, 64 darm = lib.butter_filter(darm, low=low, high=high, fs=fs_fast) if not os.path.isfile('pem.mat'): pem = lib.stream_data(st, [pem_chan], fs=fs_fast, dur=dur) pem = pem.reshape(pem.shape[1]) sio.savemat('pem.mat', mdict={'data': pem}) else: pem = sio.loadmat('pem.mat')['data']
] fast_chans_list = [ 'H1:PEM-CS_ACC_HAM3_PR2_Y_DQ', 'H1:HPI-HAM3_BLND_L4C_RZ_IN1_DQ', 'H1:HPI-HAM3_BLND_L4C_X_IN1_DQ', 'H1:HPI-HAM3_SENSCOR_X_LOCAL_DIFF_DQ', 'H1:ISI-HAM3_BLND_GS13Y_IN1_DQ' ] darm = ['H1:CAL-DELTAL_EXTERNAL_DQ'] # get the slow, modulating witnesses print('getting slow channels') if os.path.isfile('48Hz_slow_chans.mat'): slow_chans = sio.loadmat('48Hz_slow_chans.mat')['data'] else: slow_chans = lib.stream_data(st, slow_chans_list, dur=dur, fs=fs_slow) sio.savemat('48Hz_slow_chans.mat', mdict={'data': slow_chans}) slow_chans = sig.resample(slow_chans, fs_fast * dur, axis=-1) # get the witnesses to the 48.5Hz line print('getting fast channels') if os.path.isfile('48Hz_fast_chans.mat'): fast_chans = sio.loadmat('48Hz_fast_chans.mat')['data'] else: fast_chans = lib.stream_data(st, fast_chans_list, dur=dur, fs=fs_fast) sio.savemat('48Hz_fast_chans.mat', mdict={'data': fast_chans}) # get darm (DELTAL_EXTERNAL), and bandpass print('getting darm') if os.path.isfile('48Hz_darm.mat'): darm = sio.loadmat('48Hz_darm.mat')['data']
for ix, ss in enumerate(subsystems): ss_channels = [cs for cs in channel_list.get(ss,'channels').split('\n') if len(cs) > 1] for ss_chan in ss_channels: channel_data.append([x for x in ss_chan.split(' ') if len(x) > 1]) channel_data = np.array(channel_data) # get the timeseries data. can fetch 400 channels at once # we may have more channels than that, so we loop print('Collecting data') fs_up = min([int(x) for x in channel_data[:, 1]]) max_chans = 400 iters = int(channel_data.shape[0] / max_chans) + 1 ts = [] for i in range(iters): timeseries = lib.stream_data(channel_data[i * max_chans:(i + 1) * max_chans, 0], fs_up = fs_up, duration = duration, start_time = start_time) ts.append(timeseries) timeseries = np.hstack(([np.array(ts[i]) for i in range(len(ts))])) # calculate the coherences: abs(Pxy)**2/(Pxx*Pyy) coherence_results = {} for ix in range(1, timeseries.shape[1]): f, Cxy = sig.coherence(timeseries[:,0], timeseries[:,ix], fs=fs_up) df = f[1] - f[0] coherence_results[channel_data[ix, 0]] = Cxy #########################################3 # Make some plots