-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiemic_grid.py
executable file
·65 lines (39 loc) · 1.35 KB
/
iemic_grid.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
from omuse.units import units
import numpy
# note that i-emic defines depth levels as negative numbers!
def depth_levels(N, stretch_factor=1.8): #1.8
z=numpy.arange(N)/(1.*(N-1))
if stretch_factor==0:
return z
else:
return 1 - numpy.tanh(stretch_factor*(1-z))/numpy.tanh(stretch_factor)
#~ print h
def read_global_mask(Nx,Ny,Nz, filename=None):
if filename is None:
filename="mask_global_{0}x{1}x{2}".format(Nx, Ny, Nz)
mask=numpy.zeros((Nx+1,Ny+2,Nz+2), dtype='int')
f=open(filename,'r')
for k in range(Nz+2):
line=f.readline() # ignored
for j in range(Ny+2):
line=f.readline()
mask[:,j,k]=numpy.array([int(d) for d in line[:-2]]) # ignore last colum + newline
return mask
def depth_array(Nx,Ny,Nz):
mask=read_global_mask(Nx,Ny,Nz)
depth=mask[:,:,:].argmin(axis=2)
a=depth>0
depth[a]=Nz-(depth[a])+1
#~ print(Nz,depth[a].max(), depth[a].min())
depth=depth[::,::-1]
#~ print(Nz,depth.max(), depth.min())
#~ exit(0)
return depth
if __name__=="__main__":
d=depth_array(96, 38,12)
import matplotlib
matplotlib.use('TkAgg')
from matplotlib import pyplot
pyplot.imshow(d.T,origin="lower", cmap='jet')
pyplot.show()
#~ print read_global_mask(96,38,12)