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 *
23 ├── mpas.3denvar_bump.2018-04-15_00.00.00.nc
24 ├── restart.2018-04-15_00.00.00.nc
30 DATE = str(sys.argv[1])
31 DA_METHOD1 = str(sys.argv[2])
32 VAR_NAME = str(sys.argv[3])
33 INTERVAL = str(sys.argv[4])
35 USE_GFSANA = ast.literal_eval(str(sys.argv[5]))
37 GFSANA_DIR = str(sys.argv[6])
40 datein = datetime.strptime(DATE+
'00',
'%Y%m%d%H%M%S')
41 print(
'datein=',datein)
42 datefile = datein.strftime(
'%Y-%m-%d_%H.%M.%S')
44 bakfile =
'../restart.'+datefile+
'.nc'
45 baknc = Dataset(bakfile,
"r")
47 anafile =
'../mpas.'+DA_METHOD1+
'.'+datefile+
'.nc'
48 ananc = Dataset(anafile,
"r")
52 gfsfile = GFSANA_DIR+
'/x1.40962.init.'+datefile+
'.nc'
53 gfsnc = Dataset(gfsfile,
"r")
55 lats = np.array( baknc.variables[
'latCell'][:] ) * 180.0 / np.pi
56 lons = np.array( baknc.variables[
'lonCell'][:] ) * 180.0 / np.pi
57 xtime = np.array( baknc.variables[
'xtime'][:] )
58 nVertL = baknc.dimensions[
'nVertLevels']
60 for lvl
in range(0,nVertL.size,int(INTERVAL)):
62 bakmpas = np.array( baknc.variables[VAR_NAME][0,:,lvl] )
63 anampas = np.array( ananc.variables[VAR_NAME][0,:,lvl] )
64 ambmpas = anampas - bakmpas
65 plot(lats,lons,anampas,DATE,lvl+1,
'MPASANA')
66 plot(lats,lons,bakmpas,DATE,lvl+1,
'MPASBAK')
67 plot(lats,lons,ambmpas,DATE,lvl+1,
'MPASAMB')
70 gfs = np.array( gfsnc.variables[VAR_NAME][0,:,lvl] )
71 anamgfs = anampas - gfs
72 bakmgfs = bakmpas - gfs
75 plot(lats,lons,anamgfs,DATE,lvl+1,
'MPASANA-GFSANA')
76 plot(lats,lons,bakmgfs,DATE,lvl+1,
'MPASBAK-GFSANA')
78 def plot(lats,lons,data,yyyymmddhh,lvl,source):
79 fig,ax=plt.subplots(figsize=(8,8))
80 map=Basemap(projection=
'cyl',llcrnrlat=-90,urcrnrlat=90,llcrnrlon=-180,urcrnrlon=180,resolution=
'c')
83 map.drawparallels(np.arange(-90,90,30),labels=[1,1,0,1])
84 map.drawmeridians(np.arange(-180,180,60),labels=[1,1,0,1])
86 plt.title( source+
' '+VAR_NAME+
', lvl=' + str(lvl)+
", "+yyyymmddhh)
88 cont=plt.tricontourf(lons,lats,data,30,cmap=cm.bwr)
90 divider = make_axes_locatable(ax)
91 cax = divider.append_axes(
"bottom",
94 plt.colorbar(cont,cax=cax,ax=ax,orientation=
'horizontal')
95 cax.xaxis.set_ticks_position(
'bottom')
98 plt.savefig(
'distr_%s_%s_%s_%s.png'%(VAR_NAME,lvl,yyyymmddhh,source),dpi=200,bbox_inches=
'tight')
104 if __name__ ==
'__main__':
main()
def plot(lats, lons, data, yyyymmddhh, lvl, source)