New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
matpoly2.py in branches/2016/dev_merge_2016/NEMOGCM/CONFIG/WAD_TEST_CASES/EXP00 – NEMO

source: branches/2016/dev_merge_2016/NEMOGCM/CONFIG/WAD_TEST_CASES/EXP00/matpoly2.py @ 7514

Last change on this file since 7514 was 7514, checked in by acc, 7 years ago

Branch dev_merge_2016. Tidying up wetting and drying test cases. Only usrdef routines are now required in the MY_SRC directory and all test cases will run. Still some robustness issues to resolve with test case 6

File size: 2.8 KB
Line 
1import numpy as np
2import netCDF4
3
4import matplotlib.pyplot as plt
5import matplotlib
6from matplotlib.patches import Polygon
7from matplotlib.collections import PatchCollection
8from netCDF4 import Dataset
9import sys
10
11print sys.argv[1]
12pathin =  sys.argv[1]
13
14nx = 34 
15ny = 1
16nt = 24
17print nx
18print ny
19
20
21fw = Dataset(pathin)
22ssh = fw.variables['sossheig'][:,:,:]
23bat = fw.variables['gdepw_0'][0,0,:,:]
24#bat = fw.variables['ht_wd'][0,:,:]
25#vot = fw.variables['votemper'][:,0,:,:]
26vot = fw.variables['sosaline'][:,:,:]
27print ssh.shape
28print "bat"
29print bat.shape
30print "vot"
31print vot.shape
32nt = ssh.shape[0]
33nx = ssh.shape[2]
34print nx,nt
35fw.close()
36
37bat = -1.*bat
38batmin = np.amin(bat)
39batmax = np.amax(bat)
40brange = batmax - batmin
41tol = 0.1*brange
42print batmin,batmax,' ho'
43
44#for t in range(300,313):
45
46for 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)
Note: See TracBrowser for help on using the repository browser.