-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtricontour.py
executable file
·81 lines (67 loc) · 1.89 KB
/
tricontour.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
#!/usr/bin/python
import matplotlib.pyplot as plt
import matplotlib.tri as tri
from matplotlib import cm
import csv, math, numpy, sys, os
# Required input:
WorkDir = os.getcwd()+"/"
verticesFile = WorkDir+'Opinicon/Output/vertices.csv'
facesFile = WorkDir+'Opinicon/Output/faces.csv'
# Options
#--- Scale depth
zsc = -1.0
print "<<< Reading vertices >>>"
# read vertices
x=[]; y=[]; z=[]
try:
with open(verticesFile) as csvDataFile:
csvReader = csv.reader(csvDataFile)
for row in csvReader:
x.append(float(row[0]))
y.append(float(row[1]))
z.append(float(row[2]))
except IOError:
print 'Error: file',file,'not found'
raise SystemExit
n1=len(x)
print "... Number of vertices:", n1
for i in range(n1):
z[i] *= zsc
print "<<< Reading triangles >>>"
# read triangles
triangles=[]
try:
with open(facesFile) as csvDataFile:
csvReader = csv.reader(csvDataFile)
for row in csvReader:
triangles.append([int(row[0]),int(row[1]),int(row[2])])
except IOError:
print 'Error: file',file,'not found'
raise SystemExit
n1=len(triangles)
print "... Number of triangles:", n1
plt.figure()
plt.rcParams['axes.facecolor'] = 'brown'
plt.gca().set_aspect('equal')
#plt.tricontour(x, y, triangles, z, 24, cmap=cm.ocean, linewidths=1)
plt.tricontourf(x, y, triangles, z, 80, cmap=cm.ocean)
c1=plt.colorbar()
c1.set_label('Depth, m')
plt.grid(c='y', ls='-', alpha=0.3)
plt.minorticks_on()
plt.title('L.Opinicon bathymetry')
plt.xlabel('Easting')
plt.ylabel('Northing')
# Set x,y limits or comment out to draw the whole map
#plt.xlim(394800,395800)
#plt.ylim(4934500,4935500)
#plt.xlim(391320, 395935)
#plt.ylim(4931861, 4936171)
plt.tight_layout()
plt.savefig('opinicon_bathymetry.png', dpi = 600)
plt.figure()
plt.rcParams['axes.facecolor'] = 'white'
plt.gca().set_aspect('equal')
plt.triplot(x, y, triangles, lw=0.5, color='black')
# Interactive plot
plt.show()