def CO2nWind(file,outputdir):
"""
Outputs plots of CO2 in the lowest level and 10m winds
"""
import matplotlib
matplotlib.use('Agg')
import numpy as np
import sys
from netCDF4 import Dataset
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
# read in file and vars
f = Dataset(file,'r')
wrfeta = f.variables['ZNU'][0][:]
times = f.variables['Times'][:]
wrflats = f.variables['XLAT'][0][:]
wrflons = f.variables['XLONG'][0][:]
var = f.variables['CO2_ANT'][:,0,:,:]
u = f.variables['U'][:,0,:,:]
v = f.variables['V'][:,0,:,:]
# destagger u/v
u = (u[:,:,:-1] + u[:,:,1:])/2.
v = (v[:,:-1,:] + v[:,1:,:])/2.
# four corners of domain
wrflat_s = wrflats[0,len(wrflats)-1]
wrflat_n = wrflats[len(wrflats)-1,len(wrflons[0])-1]
wrflon_w = wrflons[0,0]
wrflon_e = wrflons[len(wrflats)-1,len(wrflons[0])-1]
z = 0 # assuming lowest level of model
# set up map
map = Basemap(projection='merc',llcrnrlon=wrflon_w,urcrnrlon=wrflon_e,llcrnrlat=wrflat_s,urcrnrlat=wrflat_n,resolution='i')
map.drawstates()
map.drawcounties()
map.drawcoastlines()
x,y = map(wrflons,wrflats)
# loop through times
for t in range(len(times)):
timestr = ''.join(times[t,:])
map.drawstates(color='gray',linewidth=1)
map.drawcounties(color='white')
map.drawcoastlines(color='gray',linewidth=1)
plt1 = map.pcolormesh(x,y,var[t,:,:],vmin=380,vmax=450)
#plt1 = map.pcolormesh(x,y,var[t,:,:],vmin=np.amin(var),vmax=np.amax(var))
winds = map.barbs(x[::20,::20],y[::20,::20],u[t,::20,::20]*1.94,v[t,::20,::20]*1.94,length=6,color='white') # *1.94 to convert m/s to knots (barb convention)
colorbar = map.colorbar(plt1,"right", size="5%",pad="2%")
colorbar.set_label(f.variables['CO2_ANT'].description+' '+f.variables['CO2_ANT'].units)
plt.title('WRF output valid: '+timestr)
plt.savefig(outputdir+'/%03d_' % (t) +timestr+'_CO2_wind.png')
plt.clf()
评论列表
文章目录