RunCrossCorrelations AcrossSmallArray PlotAndMapResults-forStudents-AfterCompletingRunning
RunCrossCorrelations AcrossSmallArray PlotAndMapResults-forStudents-AfterCompletingRunning
forStudents-AfterCompletingRunning
import numpy as np
import obspy
import obspy.signal.filter
import pandas as pd
import sys
import os
import glob
import scipy
import scipy.signal as scisignal
from scipy import fftpack
,→7874&maxlon=-100.4644&minlat=32.7116&minlon=-100.
,→5149&drawingmode=box&planet=earth
mdir='/uufs/chpc.utah.edu/common/home/flin-group4/emberg/ROSES/Unit4_XCorr'
datadir=mdir+'/RawData'
stafile=datadir+'/DownloadedStations_SWTX.csv'
1
stainfo=pd.read_csv(stafile,sep=' ')
display(stainfo)
StartTime EndTime
0 2014-01-01T00:00:00 2014-12-12T23:59:59
1 2014-01-01T00:00:00 2014-12-12T23:59:59
2 2014-01-01T00:00:00 2014-12-12T23:59:59
3 2014-01-01T00:00:00 2014-12-12T23:59:59
4 2014-01-01T00:00:00 2014-12-12T23:59:59
.. ... ...
226 2014-01-01T00:00:00 2014-12-12T23:59:59
227 2014-01-01T00:00:00 2014-12-12T23:59:59
228 2014-01-01T00:00:00 2014-12-12T23:59:59
229 2014-01-01T00:00:00 2014-12-12T23:59:59
230 2014-01-01T00:00:00 2014-12-12T23:59:59
#### WARNING: This takes a while to run, so decide what settings you want␣
,→before running ... ####
srcsta='6R509'
2
srcst=obspy.read(datadir+'/'+srcsta+'.BHZ.mseed')
tr1 = srcst[0]
src = tr1.data
dt4 = tr1.stats.delta
nx4 = tr1.stats.npts
t = np.arange(nx4)*dt4
hourinds=np.arange(0,len(src),winlen)
outsamples=int(corrlen/dt4)
fig=plt.figure(6,figsize=[10,5])
3
tr2 = recst[0]
rec = tr2.data
if recidx==0:
sumxc=np.nan #safety catch
for ii in range(len(hourinds)-1):
#print('on time index: ',ii)
starti=hourinds[ii]
stopi=hourinds[ii+1]
#1. Demean
x4 = scisignal.detrend(ttx,type='constant')
y4 = scisignal.detrend(tty, type='constant')
#print('demean complete')
#2. Detrend
x4 = scisignal.detrend(x4,type='linear')
y4 = scisignal.detrend(y4, type='linear')
npts = len(ttx)#nx4
npts2 = 2*npts+1 # make padding odd.
npts2=scipy.fftpack.next_fast_len(npts2) #get faster array length␣
,→for fft purposes
4
#df4 = freq4[1]
#print('taper complete..')
# FFT of data
fx4 = np.fft.fft(dat_x4,npts2)
fy4 = np.fft.fft(dat_y4,npts2)
#Correlate
Sxy = np.conj(fx4)*fy4
cohe = Sxy/(np.sqrt(Px4_smooth[0:npts2])*np.sqrt(Py4_smooth[0:npts2]))
xycorr = np.real(scipy.fft.ifft(cohe))
xycorr = scipy.fft.ifftshift(xycorr)
#Correlate
#Sxy = fx4*np.conj(fy4)
#xycorr = np.real(scipy.fft.ifft(Sxy))
#xycorr = scipy.fft.ifftshift(xycorr)
#print('correlation complete')
# Delay time vector, same as above.. only run on the first round
if recidx==0 and ii==0:
tdel = np.linspace(-nf4*dt4,nf4*dt4,npts2)
5
#find -10 to +10 indices
idxstart=find_nearest(tdel,beginningtime)
idxend=find_nearest(tdel,endingtime)
if ii==0:
sumxc=np.array(xycorr)*0
display(stainfo)
sumxc=sumxc+np.multiply(1/np.max(np.abs(xycorr)),xycorr)
#normalize sum
sumxc=np.multiply(1/np.max(np.abs(sumxc)),sumxc)
sumtmp=sumxc[idxstart:idxend]
#plot results..
sumtmp2=obspy.signal.filter.bandpass(np.array(sumtmp),freqmin=1.5,freqmax=2.
,→5,df=25,corners=4,zerophase=True)
plt.plot(tdel[idxstart:idxend],sumtmp2,alpha=0.5)
# break
plt.show() #heads up, this will be a mess -- which is good! We just want to see␣
,→things ran :)
6
.. ... ... ... ... ... ...
226 1B 79560 32.764599 -100.480698 598.9 261560
227 1B 79581 32.768700 -100.481903 601.7 261581
228 1B 79602 32.772900 -100.483002 609.2 261602
229 1B 79623 32.777000 -100.484200 609.8 261623
230 1B 79644 32.781101 -100.485397 603.9 261644
StartTime EndTime \
0 2014-01-01T00:00:00 2014-12-12T23:59:59
1 2014-01-01T00:00:00 2014-12-12T23:59:59
2 2014-01-01T00:00:00 2014-12-12T23:59:59
3 2014-01-01T00:00:00 2014-12-12T23:59:59
4 2014-01-01T00:00:00 2014-12-12T23:59:59
.. ... ...
226 2014-01-01T00:00:00 2014-12-12T23:59:59
227 2014-01-01T00:00:00 2014-12-12T23:59:59
228 2014-01-01T00:00:00 2014-12-12T23:59:59
229 2014-01-01T00:00:00 2014-12-12T23:59:59
230 2014-01-01T00:00:00 2014-12-12T23:59:59
XCorr_Sum
0 [nan, nan, nan, nan, nan, nan, nan, nan, nan, ...
1 [nan, nan, nan, nan, nan, nan, nan, nan, nan, ...
2 [nan, nan, nan, nan, nan, nan, nan, nan, nan, ...
3 [nan, nan, nan, nan, nan, nan, nan, nan, nan, ...
4 [nan, nan, nan, nan, nan, nan, nan, nan, nan, ...
.. ...
226 [nan, nan, nan, nan, nan, nan, nan, nan, nan, ...
227 [nan, nan, nan, nan, nan, nan, nan, nan, nan, ...
228 [nan, nan, nan, nan, nan, nan, nan, nan, nan, ...
229 [nan, nan, nan, nan, nan, nan, nan, nan, nan, ...
230 [nan, nan, nan, nan, nan, nan, nan, nan, nan, ...
/uufs/chpc.utah.edu/common/home/u1015716/miniconda3/envs/roses/lib/python3.7/sit
e-packages/pandas/core/indexing.py:671: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
7
See the caveats in the documentation: https://pandas.pydata.org/pandas-
docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
self._setitem_with_indexer(indexer, value)
working on: 67425
/uufs/chpc.utah.edu/common/home/u1015716/miniconda3/envs/roses/lib/python3.7/sit
e-packages/pandas/core/indexing.py:671: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
8
docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
self._setitem_with_indexer(indexer, value)
working on: 69446
/uufs/chpc.utah.edu/common/home/u1015716/miniconda3/envs/roses/lib/python3.7/sit
e-packages/pandas/core/indexing.py:671: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
9
working on: 6B425
/uufs/chpc.utah.edu/common/home/u1015716/miniconda3/envs/roses/lib/python3.7/sit
e-packages/pandas/core/indexing.py:671: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
10
/uufs/chpc.utah.edu/common/home/u1015716/miniconda3/envs/roses/lib/python3.7/sit
e-packages/pandas/core/indexing.py:671: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
11
See the caveats in the documentation: https://pandas.pydata.org/pandas-
docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
self._setitem_with_indexer(indexer, value)
working on: 6D491
/uufs/chpc.utah.edu/common/home/u1015716/miniconda3/envs/roses/lib/python3.7/sit
e-packages/pandas/core/indexing.py:671: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
12
docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
self._setitem_with_indexer(indexer, value)
working on: 6F377
/uufs/chpc.utah.edu/common/home/u1015716/miniconda3/envs/roses/lib/python3.7/sit
e-packages/pandas/core/indexing.py:671: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
13
working on: 6F482
/uufs/chpc.utah.edu/common/home/u1015716/miniconda3/envs/roses/lib/python3.7/sit
e-packages/pandas/core/indexing.py:671: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
14
/uufs/chpc.utah.edu/common/home/u1015716/miniconda3/envs/roses/lib/python3.7/sit
e-packages/pandas/core/indexing.py:671: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
15
See the caveats in the documentation: https://pandas.pydata.org/pandas-
docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
self._setitem_with_indexer(indexer, value)
working on: 6H491
/uufs/chpc.utah.edu/common/home/u1015716/miniconda3/envs/roses/lib/python3.7/sit
e-packages/pandas/core/indexing.py:671: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
16
docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
self._setitem_with_indexer(indexer, value)
working on: 6H605
/uufs/chpc.utah.edu/common/home/u1015716/miniconda3/envs/roses/lib/python3.7/sit
e-packages/pandas/core/indexing.py:671: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
17
working on: 6J425
/uufs/chpc.utah.edu/common/home/u1015716/miniconda3/envs/roses/lib/python3.7/sit
e-packages/pandas/core/indexing.py:671: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
18
/uufs/chpc.utah.edu/common/home/u1015716/miniconda3/envs/roses/lib/python3.7/sit
e-packages/pandas/core/indexing.py:671: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
19
See the caveats in the documentation: https://pandas.pydata.org/pandas-
docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
self._setitem_with_indexer(indexer, value)
working on: 6L368
/uufs/chpc.utah.edu/common/home/u1015716/miniconda3/envs/roses/lib/python3.7/sit
e-packages/pandas/core/indexing.py:671: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
20
docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
self._setitem_with_indexer(indexer, value)
working on: 6L473
/uufs/chpc.utah.edu/common/home/u1015716/miniconda3/envs/roses/lib/python3.7/sit
e-packages/pandas/core/indexing.py:671: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
21
working on: 6L578
/uufs/chpc.utah.edu/common/home/u1015716/miniconda3/envs/roses/lib/python3.7/sit
e-packages/pandas/core/indexing.py:671: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
22
/uufs/chpc.utah.edu/common/home/u1015716/miniconda3/envs/roses/lib/python3.7/sit
e-packages/pandas/core/indexing.py:671: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
23
See the caveats in the documentation: https://pandas.pydata.org/pandas-
docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
self._setitem_with_indexer(indexer, value)
working on: 6N521
/uufs/chpc.utah.edu/common/home/u1015716/miniconda3/envs/roses/lib/python3.7/sit
e-packages/pandas/core/indexing.py:671: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
24
docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
self._setitem_with_indexer(indexer, value)
working on: 6N626
/uufs/chpc.utah.edu/common/home/u1015716/miniconda3/envs/roses/lib/python3.7/sit
e-packages/pandas/core/indexing.py:671: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
25
working on: 6P452
/uufs/chpc.utah.edu/common/home/u1015716/miniconda3/envs/roses/lib/python3.7/sit
e-packages/pandas/core/indexing.py:671: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
26
/uufs/chpc.utah.edu/common/home/u1015716/miniconda3/envs/roses/lib/python3.7/sit
e-packages/pandas/core/indexing.py:671: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
27
See the caveats in the documentation: https://pandas.pydata.org/pandas-
docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
self._setitem_with_indexer(indexer, value)
working on: 6R410
/uufs/chpc.utah.edu/common/home/u1015716/miniconda3/envs/roses/lib/python3.7/sit
e-packages/pandas/core/indexing.py:671: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
28
docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
self._setitem_with_indexer(indexer, value)
working on: 6R509
/uufs/chpc.utah.edu/common/home/u1015716/miniconda3/envs/roses/lib/python3.7/sit
e-packages/pandas/core/indexing.py:671: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
29
working on: 6R599
/uufs/chpc.utah.edu/common/home/u1015716/miniconda3/envs/roses/lib/python3.7/sit
e-packages/pandas/core/indexing.py:671: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
30
/uufs/chpc.utah.edu/common/home/u1015716/miniconda3/envs/roses/lib/python3.7/sit
e-packages/pandas/core/indexing.py:671: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
31
See the caveats in the documentation: https://pandas.pydata.org/pandas-
docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
self._setitem_with_indexer(indexer, value)
working on: 6T542
/uufs/chpc.utah.edu/common/home/u1015716/miniconda3/envs/roses/lib/python3.7/sit
e-packages/pandas/core/indexing.py:671: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
32
docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
self._setitem_with_indexer(indexer, value)
working on: 6V431
/uufs/chpc.utah.edu/common/home/u1015716/miniconda3/envs/roses/lib/python3.7/sit
e-packages/pandas/core/indexing.py:671: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
33
working on: 6V536
/uufs/chpc.utah.edu/common/home/u1015716/miniconda3/envs/roses/lib/python3.7/sit
e-packages/pandas/core/indexing.py:671: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
34
/uufs/chpc.utah.edu/common/home/u1015716/miniconda3/envs/roses/lib/python3.7/sit
e-packages/pandas/core/indexing.py:671: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
35
See the caveats in the documentation: https://pandas.pydata.org/pandas-
docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
self._setitem_with_indexer(indexer, value)
working on: 6X563
/uufs/chpc.utah.edu/common/home/u1015716/miniconda3/envs/roses/lib/python3.7/sit
e-packages/pandas/core/indexing.py:671: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
36
docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
self._setitem_with_indexer(indexer, value)
working on: 6Z458
/uufs/chpc.utah.edu/common/home/u1015716/miniconda3/envs/roses/lib/python3.7/sit
e-packages/pandas/core/indexing.py:671: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
37
working on: 6Z563
/uufs/chpc.utah.edu/common/home/u1015716/miniconda3/envs/roses/lib/python3.7/sit
e-packages/pandas/core/indexing.py:671: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
38
/uufs/chpc.utah.edu/common/home/u1015716/miniconda3/envs/roses/lib/python3.7/sit
e-packages/pandas/core/indexing.py:671: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
39
See the caveats in the documentation: https://pandas.pydata.org/pandas-
docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
self._setitem_with_indexer(indexer, value)
working on: 71503
/uufs/chpc.utah.edu/common/home/u1015716/miniconda3/envs/roses/lib/python3.7/sit
e-packages/pandas/core/indexing.py:671: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
40
docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
self._setitem_with_indexer(indexer, value)
working on: 71608
/uufs/chpc.utah.edu/common/home/u1015716/miniconda3/envs/roses/lib/python3.7/sit
e-packages/pandas/core/indexing.py:671: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
41
working on: 73422
/uufs/chpc.utah.edu/common/home/u1015716/miniconda3/envs/roses/lib/python3.7/sit
e-packages/pandas/core/indexing.py:671: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
42
/uufs/chpc.utah.edu/common/home/u1015716/miniconda3/envs/roses/lib/python3.7/sit
e-packages/pandas/core/indexing.py:671: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
43
See the caveats in the documentation: https://pandas.pydata.org/pandas-
docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
self._setitem_with_indexer(indexer, value)
working on: 75365
/uufs/chpc.utah.edu/common/home/u1015716/miniconda3/envs/roses/lib/python3.7/sit
e-packages/pandas/core/indexing.py:671: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
44
docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
self._setitem_with_indexer(indexer, value)
working on: 75479
/uufs/chpc.utah.edu/common/home/u1015716/miniconda3/envs/roses/lib/python3.7/sit
e-packages/pandas/core/indexing.py:671: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
45
working on: 75617
/uufs/chpc.utah.edu/common/home/u1015716/miniconda3/envs/roses/lib/python3.7/sit
e-packages/pandas/core/indexing.py:671: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
46
/uufs/chpc.utah.edu/common/home/u1015716/miniconda3/envs/roses/lib/python3.7/sit
e-packages/pandas/core/indexing.py:671: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
47
See the caveats in the documentation: https://pandas.pydata.org/pandas-
docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
self._setitem_with_indexer(indexer, value)
working on: 77557
/uufs/chpc.utah.edu/common/home/u1015716/miniconda3/envs/roses/lib/python3.7/sit
e-packages/pandas/core/indexing.py:671: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
48
docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
self._setitem_with_indexer(indexer, value)
working on: 79371
/uufs/chpc.utah.edu/common/home/u1015716/miniconda3/envs/roses/lib/python3.7/sit
e-packages/pandas/core/indexing.py:671: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
49
working on: 79476
/uufs/chpc.utah.edu/common/home/u1015716/miniconda3/envs/roses/lib/python3.7/sit
e-packages/pandas/core/indexing.py:671: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
50
/uufs/chpc.utah.edu/common/home/u1015716/miniconda3/envs/roses/lib/python3.7/sit
e-packages/pandas/core/indexing.py:671: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
51
[8]: # Loop through and plot results..
#Making a series of images showing the cross-correlation for each receiver␣
,→station (no particular order..)
52
fig=plt.figure(3,figsize=[10,5])
for recidx in np.arange(len(stainfo['Station'])):
recsta=stainfo['Station'].iloc[recidx]
#great! Now bandpass this signal...
sumxctmp = scisignal.filtfilt(b, a, stainfo['XCorr_Sum'].iloc[recidx])
#sumxctmp=obspy.signal.filter.bandpass(np.array(sumxc),freqmin=1.
,→5,freqmax=2.5,df=25,corners=4,zerophase=True)
#sumxctmp=np.multiply(1/np.max(np.abs(sumxctmp)),sumxctmp) #normalize
plt.plot(tdel[idxstart:idxend],sumxctmp,alpha=0.5)
#plt.plot(tdel,sumxctmp);
#plt.ylim( -1*(max(abs(sumxctmp))), max(abs(sumxctmp)))
plt.ylim(-1,1) #good to be consistent in comparing overall signal amplitude
plt.xlim(-9,9)
ic=ic+1;
plt.title('Cross-Correlation Stacked '+srcsta+' '+recsta+' recidx:
,→'+str(recidx))
outf=outfigdir+'/corr_'+recsta.zfill(3)+'.png'
plt.savefig(outf)
plt.clf()
frames=[]
imgs=glob.glob(outfigdir+'/*.png')
for i in imgs:
new_frame=Image.open(i)
frames.append(new_frame)
frames[0].save(outfigdir+'/Src_Rec_Loops.
,→gif',format='GIF',append_images=frames[1:],save_all=True,duration=300,loop=0)
53
[10]: #Look at the gif
from IPython.display import Image
#insert gif location & name into the stream, as output above
stream='/uufs/chpc.utah.edu/common/home/flin-group4/emberg/ROSES/Unit4_XCorr/
,→RawData/StackHoursCoherency_AllStas/Src_Rec_Loops.gif'#'/uufs/chpc.utah.edu/
,→common/home/flin-group4/emberg/ROSES/Unit4_XCorr/RawData/
,→StackHoursCoherency_AllStas/Src_Rec_Loops.gif'
Image(stream)
[11]: #Let's glance at the table and see how it's been updated...
display(stainfo)
StartTime EndTime \
0 2014-01-01T00:00:00 2014-12-12T23:59:59
1 2014-01-01T00:00:00 2014-12-12T23:59:59
2 2014-01-01T00:00:00 2014-12-12T23:59:59
3 2014-01-01T00:00:00 2014-12-12T23:59:59
4 2014-01-01T00:00:00 2014-12-12T23:59:59
.. ... ...
226 2014-01-01T00:00:00 2014-12-12T23:59:59
227 2014-01-01T00:00:00 2014-12-12T23:59:59
228 2014-01-01T00:00:00 2014-12-12T23:59:59
229 2014-01-01T00:00:00 2014-12-12T23:59:59
230 2014-01-01T00:00:00 2014-12-12T23:59:59
XCorr_Sum
0 [-0.04665509750739268, -0.02750947538298701, 0...
1 [0.02963589588571354, 0.07208855208428898, -0....
2 [-0.308300216031186, 0.0015147208781930471, 0....
54
3 [-0.068716060225539, 0.2711057152066481, 0.018...
4 [-0.12365371654742816, 0.21557309095872018, -0...
.. ...
226 [-0.1299870030313654, 0.21471639138127588, 0.1...
227 [0.06010049417692747, -0.27100022888869685, -0...
228 [-0.17405177346561956, 0.0350206860994497, -0....
229 [0.07378820519593897, -0.09360811345762321, 0....
230 [0.0032564424144638873, -0.11431263262013527, ...
states_provinces=cfeature.NaturalEarthFeature(category='cultural',
name='admin_1_states_provinces_lines',
scale='50m',
facecolor='none')
lakes=cfeature.NaturalEarthFeature(category='physical',name='lakes',␣
,→scale='10m', edgecolor='black', facecolor='cornflowerblue',alpha='0.3')
# this is a basic map to highlight the exciting features (or lack thereof) at␣
,→this site
55
#make the figure non-interactive (just make it and show us...)
#%matplotlib inline
ax.cla()
ax.set_extent([lonlow,lonhi,latlow,lathi],crs=ccrs.Geodetic())
ax.add_image(stamen_terrain,12)
#choose zoom levels: http://maps.stamen.com/terrain/#9/32.7515/-100.4507
ax.add_feature(states_provinces,edgecolor='k')
lonticks=[-100.5, -100.45]
latticks=[32.75,32.8]
ax.set_xticks(lonticks, crs=ccrs.PlateCarree())
ax.set_yticks(latticks, crs=ccrs.PlateCarree())
ax.set_title('All Stations')
plt.show()
56
[15]: # Create a map of the stations... (interactive)
## plot up the stations...
#note that if you switch back to 'inline' mode, you need to switch this here,␣
,→kind of only goes 1-way
57
#%matplotlib inline
#print(len(substainfo['Station']))
fig=plt.figure(52,figsize=(12, 12), facecolor="none")
gs=gridspec.GridSpec(1, 1)#,hspace=0.1, height_ratios=[10, 1])
# create mercator projection
ax = plt.axes(projection=ccrs.Mercator())
ax.cla()
ax.set_extent([lonlow,lonhi,latlow,lathi],crs=ccrs.Geodetic())
ax.add_image(stamen_terrain,12)
#choose zoom levels: http://maps.stamen.com/terrain/#9/32.7515/-100.4507
ax.add_feature(states_provinces,edgecolor='k')
lonticks=[-100.5, -100.45]
latticks=[32.75,32.8]
ax.set_xticks(lonticks, crs=ccrs.PlateCarree())
ax.set_yticks(latticks, crs=ccrs.PlateCarree())
,→PlateCarree())
58
plt.show()
<IPython.core.display.Javascript object>
<IPython.core.display.HTML object>
# Let's bandpass our results and add this to a new part of our pandas dataframe
subtime=tdel[idxstart:idxend]
subtime=subtime[::skipval]
67368
67404
59
67425
67446
69359
69401
69422
69446
69467
69491
6B368
6B404
6B425
6B446
6B467
6B488
6B509
6B530
6D371
6D407
6D428
6D449
6D470
6D491
6D512
6D533
6D554
6D575
6F377
6F398
6F419
6F440
6F461
6F482
6F503
6F524
6F545
6F566
6F587
6F608
6H377
6H401
6H446
6H467
6H491
6H515
6H536
6H560
6H584
6H605
60
6H629
6J362
6J383
6J404
6J425
6J446
6J467
6J488
6J509
6J530
6J551
6J572
6J593
6J614
6J635
6L368
6L389
6L410
6L431
6L452
6L473
6L494
6L515
6L536
6L557
6L578
6L599
6L620
6L641
6N374
6N395
6N416
6N437
6N458
6N479
6N500
6N521
6N542
6N563
6N584
6N605
6N626
6P359
6P383
6P407
6P428
6P452
6P476
61
6P497
6P521
6P545
6P566
6P590
6P611
6P635
6R368
6R389
6R410
6R431
6R452
6R473
6R494
6R509
6R515
6R536
6R557
6R578
6R599
6R620
6R641
6T374
6T395
6T416
6T437
6T458
6T479
6T500
6T521
6T542
6T563
6T584
6T605
6T626
6V431
6V452
6V473
6V494
6V515
6V536
6V557
6V578
6V599
6V620
6V641
6X449
6X473
62
6X494
6X518
6X539
6X563
6X587
6X608
6X632
6Z437
6Z458
6Z479
6Z500
6Z521
6Z542
6Z563
6Z584
6Z626
6Z629
71356
71377
71398
71419
71440
71461
71482
71503
71524
71545
71566
71587
71608
71629
73359
73380
73401
73422
73443
73464
73485
73506
73527
73548
73569
73590
73611
73632
75365
75386
75410
63
75431
75455
75479
75500
75548
75569
75593
75617
75638
77368
77389
77410
77431
77452
77473
77494
77515
77536
77557
77578
77599
77620
77641
79371
79392
79413
79434
79455
79476
79497
79518
79539
79560
79581
79602
79623
79644
/uufs/chpc.utah.edu/common/home/u1015716/miniconda3/envs/roses/lib/python3.7/sit
e-packages/pandas/core/indexing.py:671: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
[17]: # let's make a simple map at a single point in time within the results..
64
#Play with the colormap! I'll use the default in the next section, but see what␣
,→you like!
%matplotlib inline
recsta='6D371'
recamps=stainfo.loc[stainfo['Station']==recsta]['XCorr_Sub_BP'].iloc[0]
mincolorval=-0.2
maxcolorval=0.2
tidx=200 #CHANGE this if you choose to skip to fewer results.. could be beyond␣
,→your subtimes length
ax = fig.add_subplot(gs[0],projection=ccrs.Mercator())
ax.cla()
ax.set_extent([lonlow,lonhi,latlow,lathi],crs=ccrs.Geodetic())
lonticks=[-100.5, -100.45]
latticks=[32.75,32.8]
ax.set_xticks(lonticks, crs=ccrs.PlateCarree())
ax.set_yticks(latticks, crs=ccrs.PlateCarree())
65
lon_formatter = LongitudeFormatter(number_format='.2f', degree_symbol='')
lat_formatter = LatitudeFormatter(number_format='.2f', degree_symbol='')
ax.xaxis.set_major_formatter(lon_formatter)
ax.yaxis.set_major_formatter(lat_formatter)
ax.xlabel_style = {'size': 15, 'color': 'gray'}
ax.ylabel_style = {'size': 15, 'color': 'gray'}
c=[stainfo.
,→loc[staidx,'XCorr_Sub_BP'][tidx]],vmin=mincolorval,vmax=maxcolorval,
#cmap='seismic',
zorder=7, s=50, marker='o', edgecolor='k',transform=ccrs.
,→PlateCarree())
elif stainfo['Station'].iloc[staidx]!=recsta:
ax.scatter([stainfo.loc[staidx,'Longitude']],[stainfo.
,→loc[staidx,'Latitude']],
c=[stainfo.
,→loc[staidx,'XCorr_Sub_BP'][tidx]],vmin=mincolorval,vmax=maxcolorval,
#cmap='seismic',
zorder=7, s=50, marker='o', edgecolor='k',transform=ccrs.
,→PlateCarree())
else:
ax.scatter([stainfo.loc[staidx,'Longitude']],[stainfo.
,→loc[staidx,'Latitude']],
c=[stainfo.
,→loc[staidx,'XCorr_Sub_BP'][tidx]],vmin=mincolorval,vmax=maxcolorval,
#cmap='seismic',
zorder=7, s=200, marker='^', edgecolor='k',transform=ccrs.
,→PlateCarree())
ax.
,→scatter([srclon],[srclat],s=250,marker='*',edgecolor='k',c='w',transform=ccrs.
,→PlateCarree(),zorder=7)
plt.colorbar(points,ax=ax,pad=0.
,→1,extend='both',ticks=[mincolorval,0,maxcolorval],shrink=0.75,fraction=0.046)
ax1=fig.add_subplot(gs[1])
ax1.plot(subtime,recamps)
66
ax1.scatter(subtime[tidx],0,marker='|',s=1000,color='r',lw=3,zorder=5,alpha=0.5)
ax1.set_ylim(mincolorval,maxcolorval)
plt.show()
67
#remove previous files -- CAREFUL!
pngfiles=glob.glob(outfigdir+'/*png')
for f in pngfiles:
os.remove(f)
recsta='6D371'
recamps=stainfo.loc[stainfo['Station']==recsta]['XCorr_Sub_BP'].iloc[0]
mincolorval=-0.2
maxcolorval=0.2
tidx=200
ax = fig.add_subplot(gs[0],projection=ccrs.Mercator())
ax.cla()
ax.set_extent([lonlow,lonhi,latlow,lathi],crs=ccrs.Geodetic())
ax.set_xticks(lonticks, crs=ccrs.PlateCarree())
ax.set_yticks(latticks, crs=ccrs.PlateCarree())
68
ax.xaxis.set_major_formatter(lon_formatter)
ax.yaxis.set_major_formatter(lat_formatter)
ax.xlabel_style = {'size': 15, 'color': 'gray'}
ax.ylabel_style = {'size': 15, 'color': 'gray'}
c=[stainfo.
,→loc[staidx,'XCorr_Sub_BP'][tidx]],vmin=mincolorval,vmax=maxcolorval,
#cmap='seismic',
zorder=7, s=50, marker='o', edgecolor='k',transform=ccrs.
,→PlateCarree())
elif stainfo['Station'].iloc[staidx]!=recsta:
ax.scatter([stainfo.loc[staidx,'Longitude']],[stainfo.
,→loc[staidx,'Latitude']],
c=[stainfo.
,→loc[staidx,'XCorr_Sub_BP'][tidx]],vmin=mincolorval,vmax=maxcolorval,
#cmap='seismic',
zorder=7, s=50, marker='o', edgecolor='k',transform=ccrs.
,→PlateCarree())
else:
ax.scatter([stainfo.loc[staidx,'Longitude']],[stainfo.
,→loc[staidx,'Latitude']],
c=[stainfo.
,→loc[staidx,'XCorr_Sub_BP'][tidx]],vmin=mincolorval,vmax=maxcolorval,
#cmap='seismic',
zorder=7, s=200, marker='^',␣
,→edgecolor='k',transform=ccrs.PlateCarree())
ax.
,→scatter([srclon],[srclat],s=250,marker='*',edgecolor='k',c='w',transform=ccrs.
,→PlateCarree(),zorder=7)
plt.colorbar(points,ax=ax,pad=0.
1,extend='both',ticks=[mincolorval,0,maxcolorval],shrink=0.75,fraction=0.046)
,→
ax1=fig.add_subplot(gs[1])
ax1.plot(subtime,recamps)
69
ax1.
,→ scatter(subtime[tidx],0,marker='|',s=1000,color='r',lw=3,zorder=5,alpha=0.5)
#plt.show()
tstr='%.2f' % (subtime[tidx])
idxstr='%5.0f' % (tidx)
on time: -8.980049273247005
on time: -8.90004883428719
on time: -8.820048395327376
on time: -8.740047956367562
on time: -8.660047517407293
on time: -8.580047078447478
on time: -8.500046639487664
on time: -8.42004620052785
on time: -8.340045761568035
on time: -8.26004532260822
on time: -8.180044883648407
on time: -8.100044444688137
on time: -8.020044005728323
on time: -7.940043566768509
on time: -7.860043127808694
on time: -7.78004268884888
on time: -7.700042249889066
on time: -7.620041810928797
on time: -7.540041371968982
on time: -7.460040933009168
on time: -7.380040494049354
on time: -7.300040055089539
on time: -7.220039616129725
on time: -7.140039177169456
on time: -7.0600387382096415
on time: -6.980038299249827
on time: -6.900037860290013
on time: -6.820037421330198
on time: -6.740036982370384
on time: -6.66003654341057
on time: -6.580036104450301
on time: -6.500035665490486
70
on time: -6.420035226530672
on time: -6.340034787570858
on time: -6.260034348611043
on time: -6.180033909651229
on time: -6.10003347069096
on time: -6.0200330317311455
on time: -5.940032592771331
on time: -5.860032153811517
on time: -5.780031714851702
on time: -5.700031275891888
on time: -5.620030836932074
on time: -5.540030397971805
on time: -5.46002995901199
on time: -5.380029520052176
on time: -5.300029081092362
on time: -5.220028642132547
on time: -5.140028203172733
on time: -5.060027764212464
on time: -4.9800273252526495
on time: -4.900026886292835
on time: -4.820026447333021
on time: -4.740026008373206
on time: -4.660025569413392
on time: -4.580025130453578
on time: -4.500024691493309
on time: -4.420024252533494
on time: -4.34002381357368
on time: -4.260023374613866
on time: -4.180022935654051
on time: -4.100022496694237
on time: -4.020022057733968
on time: -3.9400216187741535
on time: -3.860021179814339
on time: -3.7800207408545248
on time: -3.7000203018947104
on time: -3.620019862934896
on time: -3.5400194239750817
on time: -3.4600189850148126
on time: -3.3800185460549983
on time: -3.300018107095184
on time: -3.2200176681353696
on time: -3.1400172291755553
on time: -3.060016790215741
on time: -2.980016351255472
on time: -2.9000159122956575
on time: -2.820015473335843
on time: -2.740015034376029
on time: -2.6600145954162144
71
on time: -2.5800141564564
on time: -2.5000137174965857
on time: -2.4200132785363166
on time: -2.3400128395765023
on time: -2.260012400616688
on time: -2.1800119616568736
on time: -2.1000115226970593
on time: -2.020011083737245
on time: -1.9400106447769758
on time: -1.8600102058171615
on time: -1.7800097668573471
on time: -1.7000093278975328
on time: -1.6200088889377184
on time: -1.540008449977904
on time: -1.4600080110180897
on time: -1.3800075720578207
on time: -1.3000071330980063
on time: -1.220006694138192
on time: -1.1400062551783776
on time: -1.0600058162185633
on time: -0.9800053772587489
on time: -0.9000049382984798
on time: -0.8200044993386655
on time: -0.7400040603788511
on time: -0.6600036214190368
on time: -0.5800031824592224
on time: -0.5000027434994081
on time: -0.42000230453959375
on time: -0.34000186557932466
on time: -0.2600014266195103
on time: -0.18000098765969597
on time: -0.10000054869988162
on time: -0.020000109740067273
on time: 0.06000032921974707
on time: 0.14000076818001617
on time: 0.2200012071398305
on time: 0.30000164609964486
on time: 0.3800020850594592
on time: 0.46000252401927355
on time: 0.5400029629790879
on time: 0.6200034019389022
on time: 0.7000038408991713
on time: 0.7800042798589857
on time: 0.8600047188188
on time: 0.9400051577786144
on time: 1.0200055967384287
on time: 1.100006035698243
on time: 1.1800064746585122
72
on time: 1.2600069136183265
on time: 1.3400073525781409
on time: 1.4200077915379552
on time: 1.5000082304977695
on time: 1.580008669457584
on time: 1.6600091084173982
on time: 1.7400095473776673
on time: 1.8200099863374817
on time: 1.900010425297296
on time: 1.9800108642571104
on time: 2.0600113032169247
on time: 2.140011742176739
on time: 2.220012181137008
on time: 2.3000126200968225
on time: 2.380013059056637
on time: 2.460013498016451
on time: 2.5400139369762655
on time: 2.62001437593608
on time: 2.7000148148958942
on time: 2.7800152538561633
on time: 2.8600156928159777
on time: 2.940016131775792
on time: 3.0200165707356064
on time: 3.1000170096954207
on time: 3.180017448655235
on time: 3.260017887615504
on time: 3.3400183265753185
on time: 3.420018765535133
on time: 3.500019204494947
on time: 3.5800196434547615
on time: 3.660020082414576
on time: 3.740020521374845
on time: 3.8200209603346593
on time: 3.9000213992944737
on time: 3.980021838254288
on time: 4.060022277214102
on time: 4.140022716173917
on time: 4.220023155133731
on time: 4.300023594094
on time: 4.3800240330538145
on time: 4.460024472013629
on time: 4.540024910973443
on time: 4.6200253499332575
on time: 4.700025788893072
on time: 4.780026227853341
on time: 4.860026666813155
on time: 4.94002710577297
on time: 5.020027544732784
73
on time: 5.100027983692598
on time: 5.180028422652413
on time: 5.260028861612227
on time: 5.340029300572496
on time: 5.4200297395323105
on time: 5.500030178492125
on time: 5.580030617451939
on time: 5.6600310564117535
on time: 5.740031495371568
on time: 5.820031934331837
on time: 5.900032373291651
on time: 5.980032812251466
on time: 6.06003325121128
on time: 6.140033690171094
on time: 6.220034129130909
on time: 6.300034568090723
on time: 6.380035007050992
on time: 6.4600354460108065
on time: 6.540035884970621
on time: 6.620036323930435
on time: 6.7000367628902495
on time: 6.780037201850064
on time: 6.860037640810333
on time: 6.940038079770147
on time: 7.020038518729962
on time: 7.100038957689776
on time: 7.18003939664959
on time: 7.260039835609405
on time: 7.340040274569219
on time: 7.420040713529488
on time: 7.5000411524893025
on time: 7.580041591449117
on time: 7.660042030408931
on time: 7.7400424693687455
on time: 7.82004290832856
on time: 7.900043347288829
on time: 7.980043786248643
on time: 8.060044225208458
on time: 8.140044664168272
on time: 8.220045103128086
on time: 8.3000455420879
on time: 8.380045981047715
on time: 8.460046420007984
on time: 8.540046858967798
on time: 8.620047297927613
on time: 8.700047736887427
on time: 8.780048175847242
on time: 8.860048614807056
74
on time: 8.940049053767325
done making figures!
<Figure size 864x864 with 0 Axes>
frames=[]
imgs=glob.glob(outfigdir+'/*.png')
for i in imgs:
new_frame=Image.open(i)
frames.append(new_frame)
frames[0].save(outfigdir+'/Maps_Loops.gif',format='GIF',append_images=frames[1:
,→],save_all=True,duration=300,loop=0)
#as usual, insert the path & name to the gif you made..
stream='/uufs/chpc.utah.edu/common/home/flin-group4/emberg/ROSES/Unit4_XCorr/
,→RawData/StackHoursCoherency_AllStas_Maps/Maps_Loops.gif'#'/uufs/chpc.utah.
,→edu/common/home/flin-group4/emberg/ROSES/Unit4_XCorr/RawData/
,→StackHoursCoherency_AllStas_Maps/Maps_Loops.gif'
Image(stream)
[ ]: print(outfigdir)
[ ]:
75