-
Notifications
You must be signed in to change notification settings - Fork 1
/
PlotSnapshots.py
103 lines (73 loc) · 2.44 KB
/
PlotSnapshots.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
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
import numpy as np
import os
from scipy.io import netcdf as scipy_netcdf
from matplotlib import pyplot as plt
baseDir = '/home/chris/GOLD/IsoTopo4/'
outputDirBaseString = 'output'
startYear = 50
endYear = 51
outputDirs = []
for iYear in range(startYear, endYear+1):
outputDirs.append(outputDirBaseString + "%03d" % iYear + '/')
print outputDirs
fileStartingString = 'ave_prog__'
uvFilesList = []
for iYear in range(len(outputDirs)):
#print baseDir + outputDirs[iYear]
for file in os.listdir(baseDir + outputDirs[iYear]):
if os.path.isfile(baseDir + outputDirs[iYear] + file) and file.startswith(fileStartingString):
uvFilesList.append(baseDir + outputDirs[iYear] + file)
uvFilesList = sorted(uvFilesList)
#print uvFilesList
timeVarName = 'Time'
xhName = 'xh'
xqName = 'xq'
yhName = 'yh'
yqName = 'yq'
zlName = 'zl'
ziName = 'zi'
#get number of time steps
testFile = scipy_netcdf.netcdf_file(uvFilesList[0], 'r')
xh = testFile.variables[xhName][:]
xq = testFile.variables[xqName][:]
yh = testFile.variables[yhName][:]
yq = testFile.variables[yqName][:]
zl = testFile.variables[zlName][:]
zi = testFile.variables[ziName][:]
time_singleFile = testFile.variables[timeVarName][:]
nT_singleFile = time_singleFile.shape[0]
nX_h = xh.shape[0]
nX_q = xq.shape[0]
nY_h = yh.shape[0]
nY_q = yq.shape[0]
nZ_l = zl.shape[0]
nZ_i = zi.shape[0]
deltaT = time_singleFile[1]-time_singleFile[0]
testFile.close()
nT_total = nT_singleFile * len(uvFilesList)
print nT_singleFile
print nT_total
fileObject = scipy_netcdf.netcdf_file(uvFilesList[0], 'r')
u = fileObject.variables['u'][:,:,:,:]
v = fileObject.variables['v'][:,:,:,:]
e = fileObject.variables['e'][:,:,:,:]
iTime = 0
iLayer_uv = 0
iLayer_e = 4
fig = plt.figure(1)
ax = fig.add_subplot(1,1,1)
cs = ax.contourf(xq,yh,u[iTime,iLayer_uv,:,:],15,cmap=plt.cm.RdBu_r)
fig.colorbar(cs,ax=ax)
fig = plt.figure(2)
ax = fig.add_subplot(1,1,1)
cs = ax.contourf(xh,yq,v[iTime,iLayer_uv,:,:],15,cmap=plt.cm.RdBu_r)
fig.colorbar(cs,ax=ax)
fig = plt.figure(3)
ax = fig.add_subplot(1,3,1,aspect='equal')
cs = ax.contourf(xh[nX_h/2::],yh,e[iTime,iLayer_e,:,nX_h/2::],30,cmap=plt.cm.jet)
ax = fig.add_subplot(1,3,2,aspect='equal')
cs = ax.contourf(xh[nX_h/2::],yh,e[iTime+2,iLayer_e,:,nX_h/2::],30,cmap=plt.cm.jet)
ax = fig.add_subplot(1,3,3,aspect='equal')
cs = ax.contourf(xh[nX_h/2::],yh,e[iTime+5,iLayer_e,:,nX_h/2::],30,cmap=plt.cm.jet)
plt.show()
fileObject.close()