-
Notifications
You must be signed in to change notification settings - Fork 2
/
etatopres.py
71 lines (51 loc) · 1.58 KB
/
etatopres.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
#!/usr/bin/python
from netCDF4 import Dataset
from mpl_toolkits.basemap import Basemap
from matplotlib import colors
import numpy as np
import matplotlib.pyplot as plt
#setting
findpres = 70000 #in Pa
#file
wrfoutfile = 'wrfout_d01_2017-06-01_00:00:00'
#######################
#read raw data session#
#######################
dsetwrf = Dataset(wrfoutfile, mode = 'r')
lat = dsetwrf.variables['XLAT'][0]
lon = dsetwrf.variables['XLONG'][0]
pres = dsetwrf.variables['P'][0]
presbase = dsetwrf.variables['PB'][0]
mixrat = dsetwrf.variables['QVAPOR'][0]
print np.shape(presbase)
print np.shape(pres)
#####################
#calculating session#
#####################
realpres = pres + presbase
print realpres
print mixrat
Y, X = np.shape(realpres[0])
paramfind = np.zeros((Y, X))
for i in xrange(Y):
for j in xrange(X):
#find 'in between' value of our findpres
for k in xrange(len(realpres)):
if (realpres[k,i,j] < findpres):
banding = (mixrat[k-1,i,j] - mixrat[k,i,j]) / (realpres[k-1,i,j] - realpres[k,i,j])
paramfind[i,j] = mixrat[k,i,j] + (findpres - realpres[k,i,j]) * banding
print k, k-1
break
print paramfind
###############
#plotting time#
###############
m = Basemap(resolution='l', projection='merc', \
llcrnrlon=lon[0,0], llcrnrlat=lat[0,0], urcrnrlon=lon[0,-1], urcrnrlat=lat[-1,0])
cs = m.pcolormesh(lon, lat, np.squeeze(paramfind), cmap='Set3', latlon=True)
#draw map coastline, etc
m.drawcoastlines(linewidth=0.75)
m.drawcountries(linewidth=0.75)
plt.title('mixing ratio at 700 mb')
cbar = m.colorbar(cs, location='bottom', pad="10%") #add color bar
plt.show()