-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgmt6_bgplot6.py
More file actions
executable file
·294 lines (238 loc) · 7.81 KB
/
gmt6_bgplot6.py
File metadata and controls
executable file
·294 lines (238 loc) · 7.81 KB
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
#!/usr/bin/env python
import sys, os
import numpy as np
import flac
import flac_interpolate as fi
import gravity as fg
# domain bounds
left = -200
right = 250
up = 10
down = -200
dx = 1.5
dz = 0.6
def find_trench_index(z):
'''Returns the i index of trench location.'''
zz = z[:,0]
# the highest point defines the forearc
imax = zz.argmax()
# the trench is the lowest point west of forearc
i = zz[:imax].argmin()
return i
def interpolate_phase(frame, xtrench):
# domain bounds in km
fi.xmin = xtrench + left
fi.xmax = xtrench + right
fi.zmin = down
fi.zmax = up
# resolution in km
fi.dx = dx
fi.dz = dz
xx, zz, ph = fi.interpolate(frame, 'phase')
return xx, zz, ph
def interpolate_srII(frame, xtrench):
# domain bounds in km
fi.xmin = xtrench + left
fi.xmax = xtrench + right
fi.zmin = down
fi.zmax = up
# resolution in km
fi.dx = dx
fi.dz = dz
srx, srz, sr = fi.interpolate(frame, 'srII')
return srx, srz, sr
def interpolate_sII(frame, xtrench):
# domain bounds in km
fi.xmin = xtrench + left
fi.xmax = xtrench + right
fi.zmin = down
fi.zmax = up
# resolution in km
fi.dx = dx
fi.dz = dz
sx, sz, s = fi.interpolate(frame, 'sII')
return sx, sz, s
###############################################
frame = int(sys.argv[1])
fl = flac.Flac()
x, z = fl.read_mesh(frame)
itrench = find_trench_index(z)
xtrench = x[itrench,0]
# get interpolated phase either from previous run or from original data
phasefile = 'intp3-phase.%d' % frame
if not os.path.exists(phasefile):
xx, zz, ph = interpolate_phase(frame, xtrench)
f = open(phasefile, 'w')
f.write('%d %d\n' % xx.shape)
flac.printing(xx, zz, ph, stream=f)
f.close()
else:
f = open(phasefile)
nx, nz = np.fromfile(f, sep=' ', count=2)
tmp = np.fromfile(f, sep=' ')
tmp.shape = (nx, nz, 3)
xx = tmp[:,:,0]
zz = tmp[:,:,1]
ph = tmp[:,:,2]
f.close()
# get interpolated strain_rate either from previous run or from original data
strain_ratefile = 'intp3-srII.%d' % frame
if not os.path.exists(strain_ratefile):
srx, srz, sr = interpolate_srII(frame, xtrench)
f = open(strain_ratefile, 'w')
f.write('%d %d\n' % srx.shape)
flac.printing(srx, srz, sr, stream=f)
f.close()
else:
f = open(strain_ratefile)
nx, nz = np.fromfile(f, sep=' ', count=2)
strr = np.fromfile(f, sep=' ')
strr.shape = (nx, nz, 3)
srx = strr[:,:,0]
srz = strr[:,:,1]
sr = strr[:,:,2]
f.close()
# get interpolated phase either from previous run or from original data
stressfile = 'intp3-sII.%d' % frame
if not os.path.exists(stressfile):
sx, sz, s = interpolate_sII(frame, xtrench)
f = open(stressfile, 'w')
f.write('%d %d\n' % xx.shape)
flac.printing(sx, sz, s, stream=f)
f.close()
else:
f = open(stressfile)
nx, nz = np.fromfile(f, sep=' ', count=2)
str = np.fromfile(f, sep=' ')
str.shape = (nx, nz, 3)
sx = str[:,:,0]
sz = str[:,:,1]
s = str[:,:,2]
f.close()
# get interpolated T either from previous run or from original data
tfile = 'intp3-T.%d' % frame
if not os.path.exists(tfile):
T = fl.read_temperature(frame)
f = open(tfile, 'w')
f.write('%d %d\n' % x.shape)
flac.printing(x, z, T, stream=f)
f.close()
else:
f = open(tfile)
nx, nz = np.fromfile(f, sep=' ', count=2)
tmp = np.fromfile(f, sep=' ')
tmp.shape = (nx, nz, 3)
T = tmp[:,:,2]
f.close()
# get topography and gravity at uniform spacing
px, topo, topomod, fagravity, bggravity = fg.compute_gravity2(frame)
# convert to km and mGal before saving
px *= 1e-3
topo *= 1e-3
topomod *= 1e-3
fagravity *= 1e5
bggravity *= 1e5
gfile = 'topo-grav.%d' % frame
f = open(gfile, 'w')
flac.printing(px, topo, fagravity, bggravity, topomod, stream=f)
f.close()
###############
model = os.path.split(os.getcwd())[-1]
psfile = 'result3.%d' % frame
pngfile = 'result3.%d.png' % frame
phgrd = 'phase3.%d.grd' % frame
strrgrd = 'strain_rate3.%d.grd' %frame
strgrd = 'stress3.%d.grd' %frame
tgrd = 'temperature3.%d.grd' % frame
phcpt = '/home/jiching/geoflac/util/phase15.cpt'
strrcpt= '/home/jiching/geoflac/util/strain_rate.cpt'
strcpt= '/home/jiching/geoflac/util/stress.cpt'
xmin = xtrench + left
xmax = xtrench + right
zmin = down
zmax = up
aspect_ratio = float(up - down) / (right - left)
width = 6.5
height = width * aspect_ratio
shiftz = height + 1
# height of gravity plot
height2 = 1.0
# gravity grid
gravgridsize = 100
#gmin = int(gravity.min() / gravgridsize - 1) * gravgridsize
#gmax = int(gravity.max() / gravgridsize + 1) * gravgridsize
gmin = int(bggravity.min() / gravgridsize - 1) * gravgridsize
gmax = int(bggravity.max() / gravgridsize + 1) * gravgridsize
gravann = max(abs(gmin), abs(gmax))
# topography grid
topogridsize = 2
tpmin = int(topo.min() / topogridsize - 1) * topogridsize
tpmax = int(topo.max() / topogridsize + 1) * topogridsize
topoann = max(abs(tpmin), abs(tpmax))
# interval of temperature contours
cint = 200
if not os.path.exists(phgrd):
cmd = 'tail -n +2 %(phasefile)s | xyz2grd -G%(phgrd)s -I%(dx)f/%(dz)f -R%(xmin)f/%(xmax)f/%(zmin)f/%(zmax)f' % locals()
#print cmd
os.system(cmd)
if not os.path.exists(strrgrd):
cmd = 'tail -n +2 %(strain_ratefile)s | xyz2grd -G%(strrgrd)s -I%(dx)f/%(dz)f -R%(xmin)f/%(xmax)f/%(zmin)f/%(zmax)f' % locals()
#print cmd
os.system(cmd)
if not os.path.exists(strgrd):
cmd = 'tail -n +2 %(stressfile)s | xyz2grd -G%(strgrd)s -I%(dx)f/%(dz)f -R%(xmin)f/%(xmax)f/%(zmin)f/%(zmax)f' % locals()
#print cmd
os.system(cmd)
if not os.path.exists(tgrd):
cmd = 'tail -n +2 %(tfile)s | surface -G%(tgrd)s -Ll0 -I%(dx)f/%(dz)f -R%(xmin)f/%(xmax)f/%(zmin)f/%(zmax)f' % locals()
#print cmd
os.system(cmd)
cmd = '''
rm -f .gmtcommands* .gmtdefaults*
gmtset PROJ_LENGTH_UNIT = inch
gmtset FONT_LABEL=14 FONT_ANNOT_PRIMARY=10
gmtset PS_MEDIA A3
gmt begin %(psfile)s jpg
# axis annotation
gmt basemap -JX%(width)f/%(height)f -R%(xmin)f/%(xmax)f/%(zmin)f/%(zmax)f -BWSne -Bxa100f10+l"stress" -Bya20f5 -X0.9
# stress plot
gmt grdimage %(strgrd)s -C%(strcpt)s -R%(xmin)f/%(xmax)f/%(zmin)f/%(zmax)f
# axis annotation
gmt basemap -JX%(width)f/%(height)f -BWSne -Bxa100f10+l"strain rate" -Bya20f5 -R%(left)f/%(right)f/%(zmin)f/%(zmax)f -Y4.5
# strain_rate plot
gmt grdimage %(strrgrd)s -C%(strrcpt)s -R%(xmin)f/%(xmax)f/%(zmin)f/%(zmax)f
# axis annotation
gmt basemap -JX%(width)f/%(height)f -BWSne -Bxa100f10+l"phase" -Bya20f5 -R%(left)f/%(right)f/%(zmin)f/%(zmax)f -Y4.5
# phase plot
gmt grdimage %(phgrd)s -C%(phcpt)s -R%(xmin)f/%(xmax)f/%(zmin)f/%(zmax)f
# temperature contours
gmt grdcontour %(tgrd)s -C%(cint)f -A200 -W1p
# baseline plot
gmt basemap -B+t"Model=%(model)s Frame=%(frame)d Trench location=%(xtrench).3f km" -JX%(width)f/%(height2)f -R%(xmin)f/%(xmax)f/-1/1 -Y%(shiftz)f
gmt plot -A -Wthin,0,. <<END
%(xmin)f 0
%(xmax)f 0
END
# gravity plot
color=red
cut -f1,3 %(gfile)s | \
gmt plot -JX%(width)f/%(height2)f -R%(xmin)f/%(xmax)f/-%(gravann)f/%(gravann)f -Bya%(gravann)ff%(gravgridsize)f+l"@;$color;mGal@;;" -BE -A -Wthin,$color
cut -f1,4 %(gfile)s | \
gmt plot -Wthin,0/102/0,--
# topography plot
color=blue
cut -f1,2 %(gfile)s | \
gmt plot -JX%(width)f/%(height2)f -R%(xmin)f/%(xmax)f/-%(topoann)f/%(topoann)f -Bya%(topoann)ff%(topogridsize)f+l"@;$color;km@;;" -BW -A -Wthin,$color
cut -f1,5 %(gfile)s | \
gmt plot -Wthin,$color,--
# colorbar
gmt colorbar -C%(phcpt)s -DjMR+w2.5i/0.3i+o-0.5i/-2.7i+m -Ba1f0.5 -V
gmt colorbar -C%(strrcpt)s -DjMR+w2.5i/0.3i+o-0.5i/-7.5i+m -Ba1f0.5 -V
gmt colorbar -C%(strcpt)s -DjMR+w2.5i/0.3i+o-0.5i/-12i+m -Ba2f0.5 -V
#echo %(xmin)f %(topogridsize)d 14 0 1 LB "Model=%(model)s Frame=%(frame)d Trench location=%(xtrench).3f km" | \
#gmt text -D0/1 -N -J -R -P -O >> %(psfile)s
gmt end
#convert -flatten -density 150 -rotate 90 -trim +repage %(psfile)s %(pngfile)s
''' % locals()
#print cmd
os.system(cmd)