Example #1
0
#! /usr/bin/env python
# -*- coding: utf-8 -*-

from obspy import read
from merge_single import merge_single
import matplotlib.pyplot as plt
import numpy as np

tr = merge_single(6, 1000676, 1001350)
spec1 = np.fft.rfft(tr.data)
fmax = 250  # sampling frequency divided by 2 --> Nyquist frequency
freq = np.linspace(0, fmax, len(spec1))


# lowpass-filter the crossc_beat correlation function


tr2 = tr.filter("lowpass", freq=24, zerophase=True, corners=8)
tr2.filter("bandstop", freqmin=8, freqmax=14, corners=4, zerophase=True)
spec2 = np.fft.rfft(tr2.data)


ax = plt.subplot(111)
ax.plot(freq, np.abs(spec1))  # take absolute value as the spectrum is complex valued
ax.set_xticks(np.linspace(0, 250, 126))
ax.set_ylabel("amplitude")
ax.set_xlabel("frequency [Hz]")
ax.set_title(str(tr.stats.starttime) + "    -    " + str(tr.stats.endtime))
# plt.subplot(212)
# plt.plot(freq,spec2)
Example #2
0
#! /usr/bin/env python
# -*- coding: utf-8 -*-

from obspy import read
from merge_single import merge_single
import matplotlib.pyplot as plt
import numpy as np

tr = merge_single(6,1001001,1001113)
ax=plt.subplot(121)
ax2=plt.subplot(122)

time=np.linspace(0,len(tr)/500,len(tr))

#### Spectrogram
tr.spectrogram(wlen=1, per_lap=0.5, mult=1, dbscale=True, title='Spectrogram unfiltered for one hour', axes=ax2)
ax2.set_title('Spectrogram unfiltered for one hour', fontsize=15, fontweight='bold')
ax2.set_xlabel('time [s]')
ax2.set_ylabel('frequency [Hz]')

#### Spectrum

spec1 = np.fft.rfft(tr.data)
fmax = 250  # sampling frequency divided by 2 --> Nyquist frequency
freq = np.linspace(0,fmax,len(spec1))
# lowpass-filter the crossc_beat correlation function 
tr2 = tr.filter('lowpass', freq = 24, zerophase=True, corners=8)
tr2.filter('bandstop', freqmin=8, freqmax=14, corners=4, zerophase=True)
spec2 = np.fft.rfft(tr2.data)
ax.plot(freq,np.abs(spec1), color='DodgerBlue',label='unfiltered') # take absolute value as the spectrum is complex valued
ax.plot(freq,np.abs(spec2), color='Darkred',label='filtered')
Example #3
0
#! /usr/bin/env python

from obspy import read
from merge_single import merge_single

tr = merge_single(6,1000001,1000675)

# lowpass-filter the crossc_beat correlation function 

tr.filter('lowpass', freq = 24, zerophase=True, corners=8)
tr.filter('bandstop', freqmin=8, freqmax=14, corners=2, zerophase=True)

tr.spectrogram(wlen=2, per_lap=0.5, mult=1, dbscale=True)
Example #4
0

import matplotlib.pyplot as plt
from merge_single import merge_single
from numpy import sign
import numpy as np
from obspy.signal.cross_correlation import xcorr
corr=0

ax = plt.subplot(111)
time_vector = np.linspace(-50.0,50.0,50001)
for k in range(1048728,1048840,4):
 end=k+4
 print end
 tr1=merge_single(6,k,end)
 tr2=merge_single(7,k,end)
 tr1.detrend('linear')
 tr2.detrend('linear')
 tr1.filter('bandpass', freqmin=0.1, freqmax=2, corners=2, zerophase=True)
 tr2.filter('bandpass', freqmin=0.1, freqmax=2, corners=2, zerophase=True)
 tr1=sign(tr1.data)
 tr2=sign(tr2.data)

 index,value,acorr = xcorr(tr1, tr2, 25000, full_xcorr=True)
 print acorr
 ax.plot(time_vector,acorr/np.max(acorr) +k-1048728)
 corr+=acorr
ax.plot(time_vector,corr/np.max(corr)-4)
plt.show()