-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_run.py
372 lines (307 loc) · 11.3 KB
/
test_run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
# -*- coding: utf-8 -*-
"""
Created on Thu Nov 26 19:55:33 2015
@author: irnakat
"""
# exporting external helper module
import numpy as np
import pylab as plt
import commondata as cd
import os
# test IOfile
import IOfile
from TFCalculator import TFCalculator as TFC
import TFDisplayTools
from TSCalculator import TSCalculator as TSC
# single layer test case
# filename
basedir = 'Example/Input'
fname = os.path.join(basedir,'sampleinput_linear_elastic_1layer_halfspace.dat')
fname2 = os.path.join(basedir,'sampleinput_psv_s_linear_elastic_1layer_halfspace.dat')
fname3 = os.path.join(basedir,'sampleinput_psv_p_linear_elastic_1layer_halfspace.dat')
fname4 = os.path.join(basedir,'GoverGmax.dat')
# input file reading
datash = IOfile.parsing_input_file(fname)
datapsvs = IOfile.parsing_input_file(fname2)
# datapsvp = IOfile.parsing_input_file(fname3)
datanonlin = IOfile.parsing_nonlinear_parameter(fname4,True)
def modnlayer(data,nlayer):
nl = nlayer
data['sourceloc']=nl
data['nlayer']=nl+1
data['tfPair'][0][1]=nl
newhl = []; newvs = []; newdn = []; newqs = []; newvp = []; newqp = []
newsoiltype = []
for j in range(nl):
newhl.append(data['hl'][0]/nl)
newvs.append(data['vs'][0])
newqs.append(data['qs'][0])
newdn.append(data['dn'][0])
newhl.append(data['hl'][-1])
newvs.append(data['vs'][-1])
newqs.append(data['qs'][-1])
newdn.append(data['dn'][-1])
data['hl']=newhl
data['vs']=newvs
data['qs']=newqs
data['dn']=newdn
try:
for j in range(nl):
newvp.append(data['vp'][0])
newqp.append(data['qp'][0])
newvp.append(data['vp'][-1])
newqp.append(data['qp'][-1])
data['vp']=newvp
data['qp']=newqp
except:
pass
try:
for j in range(nl):
newsoiltype.append(data['soiltype'][0])
newsoiltype.append(data['soiltype'][-1])
data['soiltype']=newsoiltype
except:
pass
return data
nlayer = 1
datash = modnlayer(datash,nlayer)
datapsvs = modnlayer(datapsvs,nlayer)
#@profile
def calc_kramer(data):
theclass = TFC(data)
theclass.tf_kramer286_sh()
return theclass
#@profile
def calc_knopoff_sh(data):
theclass = TFC(data)
theclass.tf_knopoff_sh()
return theclass
#@profile
def calc_knopoff_sh_adv(data):
theclass = TFC(data)
theclass.tf_knopoff_sh_adv()
return theclass
#@profile
def calc_knopoff_psv(data):
theclass = TFC(data)
theclass.tf_knopoff_psv_adv()
return theclass
#@profile
def calc_kennet(data):
theclass = TFC(data)
theclass.tf_kennet_sh()
return theclass
# kramer
print 'TF calculatoin using kramer approach'
theclass1 = calc_kramer(datash)
print 'calculation has been finished!'
# knopoff sh
print 'TF calculation using simple knopoff approach'
theclass2 = calc_knopoff_sh(datash)
print 'calculation has been finished!'
# knopoff sh complete
print 'TF calculation using complete knopoff sh approach'
theclass3 = calc_knopoff_sh_adv(datash)
print 'calculation has been finished!'
# knopoff psv-s
print 'TF calculation using complete knopoff psv-s approach'
theclass4 = calc_knopoff_psv(datapsvs)
print 'calculation has been finished!'
# kennet sh
print 'TF calculation using kennet sh method'
theclass5 = calc_kennet(datash)
print 'calculation has been finished!'
TFDisplayTools.TFPlot(theclass1,theclass2,theclass3,theclass5,theclass4, \
label=['Kramer SH','Knopoff SH','Knopoff SH2','Kennet SH','Knopoff PSV'])
TFDisplayTools.PhasePlot(theclass1,theclass2,theclass3,theclass5,theclass4, \
label=['Kramer SH','Knopoff SH','Knopoff SH2','Kennet SH','Knopoff PSV'])
"""
from TSCalculator import TSCalculator as TSC
TSclass = TSC('ricker.dat',fname)
time, amp =TSclass.TF2TS()
"""
"""
# creating ricker signal
from scipy import signal
points = 4000
a = 10.0
inputmotion = signal.ricker(points,a)/1000.
inputtime = np.linspace(0.,20.,points)
with open('ricker.dat','w+') as f:
for i in range(len(inputtime)):
f.write('%2.5f %2.5f\n'%(inputtime[i],inputmotion[i]))
# creating dirac signal
points = 4000
inputmotion = np.zeros(points)
inputmotion[512] = 0.001
inputtime = np.linspace(0.,20.,points)
with open('dirac.dat','w+') as f:
for i in range(len(inputtime)):
f.write('%2.5f %2.5f\n'%(inputtime[i],inputmotion[i]))
"""
"""
# creating dirac signal for paolucci
points = 2000
inputmotion = np.zeros(points)
inputmotion[512] = 1.
inputtime = np.linspace(0.,20.,points)
with open('diracpaolucci.dat','w+') as f:
for i in range(len(inputtime)/8):
j=i*8
f.write('%2.5f %2.5f %2.5f %2.5f %2.5f %2.5f %2.5f %2.5f \n'%(inputmotion[j],inputmotion[j+1],inputmotion[j+2],inputmotion[j+3],
inputmotion[j+4],inputmotion[j+5],inputmotion[j+6],inputmotion[j+7]))
"""
"""
# creating ricker signal for paolucci
from scipy import signal
points = 2000
a = 100.0
inputmotion = signal.ricker(points,a)
inputtime = np.linspace(0.,20.,points)
with open('rickerpaolucci.dat','w+') as f:
for i in range(len(inputtime)/8):
j=i*8
f.write('%2.5f %2.5f %2.5f %2.5f %2.5f %2.5f %2.5f %2.5f \n'%(inputmotion[j],inputmotion[j+1],inputmotion[j+2],inputmotion[j+3],
inputmotion[j+4],inputmotion[j+5],inputmotion[j+6],inputmotion[j+7]))
"""
"""
# read output from paolucci and plot it
from TSCalculator import TSCalculator
fname = 'sampleinput_linear_elastic_1layer_halfspace.dat'
datash = IOfile.parsing_input_file(fname)
theclass2 = TFC(datash)
theclass2.tf_knopoff_sh()
TSclass01 = TSCalculator(theclass2)
TSclass01.linear_TF2TS()
points = 4000
inputmotion = np.zeros(points/2)
inputmotion[512] = 1.
data = []
with open('psvq.out','r') as f:
next(f)
for line in f:
tmp2= line.split()
for i in range(8):
data.append(tmp2[i])
fig = plt.figure(figsize=(12,12))
a = fig.add_subplot(311)
a.plot(np.linspace(0.,20.,points),data,label='paolucci code')
a.plot(np.linspace(0.,20.,points),TSclass01.time_series[0],lw=2,label='knopoff SH')
a.plot(np.linspace(0.,10.,points/2),inputmotion,label='input motion')
a.grid(True)
a.legend(loc='best',fancybox=True,framealpha=0.5)
a.set_xlim(1,4)
a = fig.add_subplot(312)
tmp = np.fft.fftfreq(points,d=0.01)
a.plot(tmp[:2000],np.abs(np.fft.fft(data))[:2000])
a.plot(theclass2.freq,np.abs(theclass2.tf[0]))
a.set_xlim(0,50)
a.grid(True)
a = fig.add_subplot(313)
tmp = np.fft.fftfreq(points,d=0.01)
a.plot(tmp[:2000],np.angle(np.fft.fft(data))[:2000])
a.plot(theclass2.freq,np.angle(theclass2.tf[0]))
a.set_xlim(0,50)
a.grid(True)
"""
"""
# additional calculations
fname3 = 'sampleinput_linear_elastic_2layer_halfspace.dat'
datash2 = IOfile.parsing_input_file(fname3)
theclass6 = TFC(datash2)
theclass6.tf_knopoff_sh_adv()
theclass7 = TFC(datash2)
theclass7.tf_kennet_sh()
fname4 = 'sampleinput_linear_elastic_6layer_halfspace_400vs30.dat'
datash3 = IOfile.parsing_input_file(fname4)
theclass8 = TFC(datash3)
theclass8.tf_knopoff_sh_adv()
theclass9 = TFC(datash3)
theclass9.tf_kennet_sh()
TFDisplayTools.TFPlot(theclass3,theclass5, \
label=['1 layer - Knopoff SH','1 layer - Kennet SH'])
TFDisplayTools.PhasePlot(theclass3,theclass5, \
label=['1 layer - Knopoff SH','1 layer - Kennet SH'])
TFDisplayTools.TFPlot(theclass6,theclass7, \
label=['2 layers- Knopoff SH','2 layers- Kennet SH'])
TFDisplayTools.PhasePlot(theclass6,theclass7, \
label=['2 layers- Knopoff SH','2 layers- Kennet SH'])
TFDisplayTools.TFPlot(theclass8,theclass9, \
label=['6 layers- Knopoff SH','6 layers- Kennet SH'])
TFDisplayTools.PhasePlot(theclass8,theclass9, \
label=['6 layers- Knopoff SH','6 layers- Kennet SH'])
TFDisplayTools.TFPlot(theclass3,theclass5,theclass6,theclass7,theclass8,theclass9, \
label=['1 layer - Knopoff SH','1 layer - Kennet SH','2 layers- Knopoff SH','2 layers- Kennet SH','6 layers- Knopoff SH','6 layers- Kennet SH'])
TFDisplayTools.PhasePlot(theclass3,theclass5,theclass6,theclass7,theclass8,theclass9, \
label=['1 layer - Knopoff SH','1 layer - Kennet SH','2 layers- Knopoff SH','2 layers- Kennet SH','6 layers- Knopoff SH','6 layers- Kennet SH'])
TFDisplayTools.TFPlot(theclass1,theclass2,theclass3,theclass4,theclass5,theclass10, \
label=['Kramer SH','Knopoff Simple SH','Knopoff Complete SH','Knopoff PSV','Kennet SH','Kennet PSV'])
TFDisplayTools.PhasePlot(theclass1,theclass2,theclass3,theclass4,theclass5,theclass10, \
label=['Kramer SH','Knopoff Simple SH','Knopoff Complete SH','Knopoff PSV','Kennet SH','Kennet PSV'])
TFDisplayTools.TFPlot(theclass4,theclass10, \
label=['Knopoff PSV','Kennet PSV'])
TFDisplayTools.PhasePlot(theclass4,theclass10, \
label=['Knopoff PSV','Kennet PSV'])
TFDisplayTools.TFPlot(theclass3,theclass6,theclass8, \
label=['1 layer','2 layers','6 layers'])
"""
"""
# kennet sh
print 'TF calculation using kennet sh method'
datash['inputtype'][0]='outcrop'
theclass11 = TFC(datash)
theclass11.tf_kennet_sh()
print 'calculation has been finished!'
TFDisplayTools.TFPlot(theclass1,theclass2,theclass3,theclass4,theclass5,theclass11, \
label=['Kramer SH - Borehole','Knopoff Simple SH - Borehole','Knopoff Complete SH - Borehole', \
'Knopoff PSV - Borehole','Kennet SH - Borehole','Kennet SH - Outcrop'])
TFDisplayTools.PhasePlot(theclass1,theclass2,theclass3,theclass4,theclass5,theclass11, \
label=['Kramer SH - Borehole','Knopoff Simple SH - Borehole','Knopoff Complete SH - Borehole', \
'Knopoff PSV - Borehole','Kennet SH - Borehole','Kennet SH - Outcrop'])
"""
"""
TFDisplayTools.TFPlot(theclass4, \
label=['Knopoff PSV-S'],tfid=0)
TFDisplayTools.PhasePlot(theclass4, \
label=['Knopoff PSV-S'],tfid=0)
TFDisplayTools.TFPlot(theclass4, \
label=['Knopoff PSV-S'],tfid=1)
TFDisplayTools.PhasePlot(theclass4, \
label=['Knopoff PSV-S'],tfid=1)
"""
"""
# test knopoff
# filename
fname = 'sampleinput_linear_elastic_1layer_halfspace.dat'
# input file reading
datash = IOfile.parsing_input_file(fname)
# knopoff sh
print 'TF calculation using simple knopoff approach'
theclass2 = TFC(datash)
#theclass2.tf_knopoff_sh()
print 'calculation has been finished!'
"""
"""
fname = 'sampleinput_linear_elastic_1layer_halfspace.dat'
fname2 = 'sampleinput_psv_s_linear_elastic_1layer_halfspace.dat'
# kramer
print 'TS calculatoin using kramer approach'
TS1 = TSC(fname,method='kramer286_sh')
print 'calculation has been finished!'
# knopoff sh
print 'TS calculation using simple knopoff approach'
TS2 = TSC(fname,method='knopoff_sh')
print 'calculation has been finished!'
# knopoff sh complete
print 'TS calculation using complete knopoff sh approach'
TS3 = TSC(fname,method='knopoff_sh_adv')
print 'calculation has been finished!'
# knopoff psv-s
print 'TS calculation using complete knopoff psv-s approach'
TS4 = TSC(fname2,method='knopoff_psv_adv')
print 'calculation has been finished!'
# kennet sh
print 'TS calculation using kennet sh method'
TS5 = TSC(fname,method='kennet_sh')
print 'calculation has been finished!'
"""