1 | import numpy as np |
---|
2 | import netCDF4 |
---|
3 | |
---|
4 | import matplotlib.pyplot as plt |
---|
5 | import matplotlib |
---|
6 | from matplotlib.patches import Polygon |
---|
7 | from matplotlib.collections import PatchCollection |
---|
8 | from netCDF4 import Dataset |
---|
9 | import sys |
---|
10 | |
---|
11 | print sys.argv[1] |
---|
12 | pathin = sys.argv[1] |
---|
13 | |
---|
14 | nx = 34 |
---|
15 | ny = 1 |
---|
16 | nt = 24 |
---|
17 | print nx |
---|
18 | print ny |
---|
19 | |
---|
20 | |
---|
21 | fw = Dataset(pathin) |
---|
22 | ssh = fw.variables['sossheig'][:,:,:] |
---|
23 | bat = fw.variables['gdepw_0'][0,0,:,:] |
---|
24 | #bat = fw.variables['ht_wd'][0,:,:] |
---|
25 | #vot = fw.variables['votemper'][:,0,:,:] |
---|
26 | vot = fw.variables['sosaline'][:,:,:] |
---|
27 | print ssh.shape |
---|
28 | print "bat" |
---|
29 | print bat.shape |
---|
30 | print "vot" |
---|
31 | print vot.shape |
---|
32 | nt = ssh.shape[0] |
---|
33 | nx = ssh.shape[2] |
---|
34 | print nx,nt |
---|
35 | fw.close() |
---|
36 | |
---|
37 | bat = -1.*bat |
---|
38 | batmin = np.amin(bat) |
---|
39 | batmax = np.amax(bat) |
---|
40 | brange = batmax - batmin |
---|
41 | tol = 0.1*brange |
---|
42 | print batmin,batmax,' ho' |
---|
43 | |
---|
44 | #for t in range(300,313): |
---|
45 | |
---|
46 | for t in range(0,nt,3): |
---|
47 | wadfr = "wadfr{:0>4d}.png".format(t) |
---|
48 | t24 = np.mod(t,24) |
---|
49 | dy = np.int(t/24.0) |
---|
50 | |
---|
51 | tfac = 18.0/3600.0 |
---|
52 | t24 = np.int(np.mod(t*tfac,24)) |
---|
53 | dy = np.int(t*tfac/24.0) |
---|
54 | mn = np.int(np.rint((np.mod(t*tfac,24) - t24 )*60)) |
---|
55 | hour = "t={:0>2d}:{:0>2d}:{:0>2d} ".format(dy,t24,mn) |
---|
56 | hour2 = " (days:hrs:mins)" |
---|
57 | batpts = np.zeros((nx+4,2)) |
---|
58 | sshpts = np.zeros((2*nx,2)) |
---|
59 | votpts = np.zeros((nx,2)) |
---|
60 | #codes = np.ones(nx,int) |
---|
61 | #codes[0] = path.Path.MOVETO |
---|
62 | #codes[1:] = path.Path.LINETO |
---|
63 | for pt in range(nx): |
---|
64 | batpts[pt+2,0] = pt |
---|
65 | batpts[pt+2,1] = bat[0,pt] |
---|
66 | sshpts[pt,0] = pt |
---|
67 | sshpts[pt,1] = ssh[t,0,pt] |
---|
68 | votpts[pt,0] = pt |
---|
69 | votpts[pt,1] = np.minimum(36.,vot[t,0,pt]) |
---|
70 | votpts[pt,1] = np.maximum(30.0,votpts[pt,1]) |
---|
71 | votpts[pt,1] = batmin +0.2*brange + (votpts[pt,1]-30.)*brange/6.0 |
---|
72 | batpts[nx+1,1] = batmax |
---|
73 | batpts[nx+2,0] = nx-1 |
---|
74 | batpts[nx+2,1] = batmax |
---|
75 | batpts[nx+3,0] = nx-1 |
---|
76 | batpts[nx+3,1] = batmin |
---|
77 | batpts[0,0] = 0.0 |
---|
78 | batpts[0,1] = batmin |
---|
79 | batpts[1,0] = 0.0 |
---|
80 | batpts[1,1] = batmax |
---|
81 | batpts[2,1] = batmax |
---|
82 | sshpts[nx-1,0] = nx-1 |
---|
83 | sshpts[nx-1,1] = sshpts[nx-2,1] |
---|
84 | sshpts[0,0] = 0.0 |
---|
85 | #sshpts[0,1] = batmin |
---|
86 | votpts[nx-2,0] = nx-1 |
---|
87 | votpts[nx-1,0] = nx-1 |
---|
88 | votpts[0,0] = 0.0 |
---|
89 | votpts[nx-1,1] = batmax + tol |
---|
90 | votpts[0,1] = batmax + tol |
---|
91 | sshpts[0,1] = sshpts[1,1] |
---|
92 | #for pt in range(nx): |
---|
93 | # print pt,votpts[pt,0],votpts[pt,1] |
---|
94 | for pt in range(nx): |
---|
95 | sshpts[pt+nx,0]=batpts[nx+1-pt,0] |
---|
96 | sshpts[pt+nx,1]=batpts[nx+1-pt,1] |
---|
97 | |
---|
98 | |
---|
99 | xs, ys = zip(*votpts) |
---|
100 | fig, ax = plt.subplots() |
---|
101 | patches = [] |
---|
102 | |
---|
103 | polygon = Polygon(batpts, True) |
---|
104 | patches.append(polygon) |
---|
105 | polygon2 = Polygon(sshpts, True) |
---|
106 | patches.append(polygon2) |
---|
107 | |
---|
108 | p = PatchCollection(patches, cmap=matplotlib.cm.jet, alpha=0.4) |
---|
109 | |
---|
110 | #colors = 100*np.random.rand(len(patches)) |
---|
111 | colors = (4,3) |
---|
112 | p.set_array(np.array(colors)) |
---|
113 | |
---|
114 | ax.set_ylim([-10., 4.0]) |
---|
115 | ax.set_xlim([0., 50.0]) |
---|
116 | ax.add_collection(p) |
---|
117 | ax.plot(xs,ys, '--', color='black', ms=10) |
---|
118 | |
---|
119 | plt.annotate(hour,xy=(2,batmin+0.1*brange)) |
---|
120 | plt.annotate(hour2,xy=(2,batmin+0.05*brange)) |
---|
121 | plt.savefig(wadfr) |
---|