4 from netCDF4
import Dataset
7 import matplotlib.cm
as cm
8 import matplotlib.pyplot
as plt
9 from mpl_toolkits.basemap
import Basemap
10 from mpl_toolkits.axes_grid1
import make_axes_locatable
12 from datetime
import *
14 import var_utils
as vu
21 DATE = str(sys.argv[1])
22 VAR_NAME = str(sys.argv[2])
24 USE_GFSANA = ast.literal_eval(str(sys.argv[3]))
26 GFSANA_DIR = str(sys.argv[4])
35 xarray = np.arange(0,nums)
36 binsfory = np.arange(0,55)
38 datein = datetime.strptime(DATE+
'00',
'%Y%m%d%H%M%S')
39 datefile = datein.strftime(
'%Y-%m-%d_%H.%M.%S')
41 bakfile =
'../restart.'+datefile+
'.nc_orig'
42 baknc = Dataset(bakfile,
"r")
44 anafile =
'../analysis.'+datefile+
'.nc'
45 ananc = Dataset(anafile,
"r")
49 gfsfile = GFSANA_DIR+
'/x1.40962.init.'+datefile+
'.nc'
50 gfsnc = Dataset(gfsfile,
"r")
52 lats = np.array( baknc.variables[
'latCell'][:] ) * 180.0 / np.pi
53 lons = np.array( baknc.variables[
'lonCell'][:] ) * 180.0 / np.pi
54 xtime = np.array( baknc.variables[
'xtime'][:] )
55 nVertL = baknc.dimensions[
'nVertLevels']
57 bakmpas = np.array( baknc.variables[VAR_NAME][0,:,:] )
58 if (VAR_NAME ==
'pressure_p'):
59 pressure = np.array( ananc.variables[
'pressure'][0,:,:] )
60 pressure_base = np.array( ananc.variables[
'pressure_base'][0,:,:] )
61 anampas = pressure - pressure_base
63 anampas = np.array( ananc.variables[VAR_NAME][0,:,:] )
64 ambmpas = anampas - bakmpas
67 plot(xarray,binsfory,ambmpas,DATE,
'MPASAMB')
69 gfs = np.array( gfsnc.variables[VAR_NAME][0,:,:] )
70 anamgfs = anampas - gfs
71 bakmgfs = bakmpas - gfs
74 plot(xarray,binsfory,anamgfs,DATE,
'MPASANA-GFSANA')
75 plot(xarray,binsfory,bakmgfs,DATE,
'MPASBAK-GFSANA')
76 def plot(xarray,binsfory,model,yyyymmddhh,source):
77 zgrid = np.loadtxt(
"/glade/work/jban/pandac/fix_input/graphics/zgrid_v55.txt")
79 fig, ax1 = plt.subplots()
81 model = model.reshape(len(xarray),len(binsfory)).T
82 valuemin = np.amin(model)
83 valuemax = np.amax(model)
84 norm = matplotlib.colors.DivergingNorm(vmin=valuemin, vcenter=0, vmax=valuemax)
85 plt.contourf(xarray,binsfory,model,10,vmin=valuemin,vmax=valuemax,norm=norm,cmap=cmap)
86 plt.title( source+
' '+vu.varDictModel[VAR_NAME][1]+
'('+ vu.varDictModel[VAR_NAME][0]+
') max=' +str(round(valuemax,4))+
' min='+str(round(valuemin,4)))
87 major_ticks = np.arange(0, 56, 5)
88 ax1.set_yticks(major_ticks)
90 ax1.set_ylabel(
'Vertical level',fontsize=15)
93 ax2.set_yticks(major_ticks-1)
94 ax2.set_yticklabels((zgrid[::5]).astype(int))
96 ax2.set_ylabel(
'Height (m)',fontsize=13)
98 if ( VAR_NAME ==
'u'):
99 ax1.set_xlabel(
'Edge',fontsize=15)
101 ax1.set_xlabel(
'Cell',fontsize=15)
103 plt.colorbar(extend=
'both',orientation=
"horizontal")
104 plt.savefig(
'%s_%s_%s.png'%(vu.varDictModel[VAR_NAME][1],yyyymmddhh,source),dpi=200,bbox_inches=
'tight')
109 if __name__ ==
'__main__':
main()
def plot(xarray, binsfory, model, yyyymmddhh, source)