-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExtract_Surface_Topography.py
177 lines (112 loc) · 4.52 KB
/
Extract_Surface_Topography.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
'''
THIS IS TOO SLOW, USE THE JULIA EQUIVALENTE SCRIPT
'''
import sys
sys.path.append("/Users/josimar/Documents/Work/UnsynchFolders/Software/Geomechanics/pylith-2.1.4-darwin-10.11.6/lib/python2.7/site-packages/h5py")
import h5py
import numpy as np
import matplotlib.pyplot as plt
from Export_H5_Class import *
from scipy.interpolate import griddata
def main():
Tbegin, Tend, dt = 169000, 190000, 0.25
TimeBeginModel, TimeEndModel=155, 200
#slope_s="-0.0025"
slope_s="0"
#slope_s="0"
intercept_s="0.6"
#slope_d="-0.0025"
slope_d="0"
#slope_d="-0.0019"
intercept_d="0.4"
###For the Mac Computer use this
mainDir="/Users/josimar/Documents/Work/Projects/SlowEarthquakes/Modeling/PyLith/Runs/Calibration/2D/SensitivityTests/Linear_Friction_Coefficient/TimeWindow_"+str(Tbegin)+"_"+str(Tend)+"/dt_"+str(dt)+"/slope_s_"+str(slope_s)+"/intercept_s_"+str(intercept_s)+"/slope_d_"+str(slope_d)+"/intercept_d_"+str(intercept_d)+"/"
FileName= mainDir + "output/step01.h5"
if os.path.isfile(FileName) == False:
print "ERROR !!! File does not Exist : ", FileName
return
fid=h5py.File(FileName,'r')
###HEre are the Field from the H5 file
disp=fid["vertex_fields/displacement"]
geometry=fid["geometry/vertices"]
time=fid["time"]
#Convert time from secods to years
time=time[:]*3.171e-8
print disp.shape, geometry.shape, time.shape
tdata=np.array((time),dtype=float)
tmp = np.abs(TimeBeginModel*1e3 - tdata)
IndBeginTime=tmp.argmin()
TimeSelected = time[IndBeginTime:]
Xcoord=geometry[:,0]
Zcoord=geometry[:,1]
print "Xcoord size after size ", Xcoord.shape
ZeroInd=[]
XcoordZeros=[]
# find indexed where the Z coordinate is zero
for k in range(0,Zcoord.shape[0]):
if Zcoord[k]==0:
ZeroInd=np.append(ZeroInd, k)
XcoordZeros=np.append(XcoordZeros,Xcoord[k])
SurfaceDisplacement_X=np.zeros([TimeSelected.shape[0], XcoordZeros.shape[0] ])
SurfaceDisplacement_Z=np.zeros([TimeSelected.shape[0], XcoordZeros.shape[0] ])
print SurfaceDisplacement_X.shape, IndBeginTime
## Now get the topography for each location where the Z coordinate Z=0
count = 0
plt.figure(2)
for i in ZeroInd:
print "i =", i
ind=int(i)
SurfaceDisplacement_X[:,count]=disp[IndBeginTime:,ind,0]
SurfaceDisplacement_Z[:,count]=disp[IndBeginTime:,ind,1]
count = count + 1
#print Xcoord[i], Zcoord[i]
## Now plot the topography
plt.figure(1)
for i in range(0,SurfaceDisplacement_X.shape[0],10000):
#for i in range(0,1000):
print i
plt.plot(XcoordZeros,SurfaceDisplacement_Z[i,:])
plt.show()
return
Coord=np.array([Xcoord, Zcoord])
print Coord.T.shape
print Xcoord.shape, tmp.shape
grid_z1 = griddata(Coord.T, tmp.T , (xmesh, zmesh), method='cubic')
#grid_z1 = griddata(Coord.T, tmp.T , ( np.arange(-150000,200000,1), np.arange(-80000,0,1) ), method='cubic')
print grid_z1.shape, xmesh.shape
step=3
plt.figure()
#plt.pcolormesh(xmesh[0:-1:step,0:-1:step],zmesh[0:-1:step,0:-1:step], grid_z1[0:-1:step,0:-1:step], cmap='RdBu', shading='flat', edgecolors='face')
#plt.pcolor(xmesh,zmesh, grid_z1)
plt.pcolor(grid_z1)
plt.show()
return
print geometry.shape
print disp.shape
print time.shape
print "Mesh size", xmesh.shape, zmesh.shape
for i in range(0,xmesh.shape[0]):
for j in range(0,xmesh.shape[1]):
x, z=xmesh[i,j], zmesh[i,j]
for k in range(0, Xcoord.shape[0]):
if x == Xcoord[k] and z== Zcoord[k]:
DispMesh[i,j]=tmp[k]
break
#print tmp[k]
plt.figure()
#plt.pcolormesh(Xcoord,Zcoord, tmp, cmap='RdBu', vmin=0, vmax=1000)
plt.pcolor(xmesh,zmesh, DispMesh)
plt.show()
return
plt.figure()
plt.plot(Xcoord,Zcoord,'ks')
print tmp.shape, Xcoord.shape, Zcoord.shape
return
plt.show()
return
data=Export_H5_Class()
FileName=mainDir+"output/gps-points.h5"
data.Export_GPS_data(mainDir,FileName)
FileName=mainDir + "output/step01-fault_top.h5"
data.Export_Fault_data(mainDir,FileName)
main()