1 from netCDF4
import Dataset
5 import matplotlib.pyplot
as plt
15 file_tplt_befr1 =
'20180415.000000.3DVar.fv_core.res.tile' 16 file_tplt_aftr =
'.nc' 20 path2 =
'../INPUTS/GEOS_c48/' 21 file_tplt_befr2 =
'20180415.000000.fv_core.res.tile' 22 elif (model ==
'gfs'):
23 path2 =
'../INPUTS/GFS_c48/ENSEMBLE/mem001/RESTART/' 24 file_tplt_befr2 =
'20180415.000000.fv_core.res.tile' 27 file_tplt_befr2 =
'fv_core.res.tile' 36 readvarlat =
'grid_lat' 37 readvarlon =
'grid_lon' 40 fh1 = Dataset(path1 + file_tplt_befr1 +
str(1) + file_tplt_aftr, mode=
'r') 41 fh2 = Dataset(path2 + file_tplt_befr2 + str(1) + file_tplt_aftr, mode='r') 44 npx =
len(fh1.dimensions[xdimvar])
45 npy =
len(fh1.dimensions[ydimvar])
57 npz =
len(fh1.dimensions[zdimvar])
58 fr = np.zeros(6*npz*npyr*npxr).reshape(6,npz,npyr,npxr)
60 fr = np.zeros(6*npyr*npxr).reshape(6,npyr,npxr)
62 flat = np.zeros(6*npy*npx).reshape(6,npy,npx)
63 flon = np.zeros(6*npy*npx).reshape(6,npy,npx)
67 file_tile1 = file_tplt_befr1 +
str(tile+1) + file_tplt_aftr
68 file_tile2 = file_tplt_befr2 +
str(tile+1) + file_tplt_aftr
69 pathfile1 = path1 + file_tile1
70 pathfile2 = path2 + file_tile2
74 fh1 = Dataset(pathfile1, mode=
'r') 75 fh2 = Dataset(pathfile2, mode='r') 77 fr[tile,:,:,:] = fh1.variables[readvar][:] - fh2.variables[readvar][:]
79 fr[tile,:,:,:] = fh1.variables[readvar][:]
83 f = np.zeros(6*npy*npx).reshape(6,npy,npx)
85 f[:,:,:] = fr[:,plot_level,0:npy,0:npx]
90 f12 = np.zeros(12*npy*npx).reshape(12,npy,npx)
91 fp = np.zeros(12*npy*npx).reshape(4*npy,3*npx)
93 f12[0,:,:] = np.rot90(f[2,:,:],2)
94 f12[1,:,:] = np.rot90(f[2,:,:],3)
96 f12[3,:,:] = np.rot90(f[2,:,:],1)
97 f12[4,:,:] = np.fliplr(np.transpose(f[0,:,:]))
98 f12[5,:,:] = np.fliplr(np.transpose(f[1,:,:]))
100 f12[7,:,:] = f[4,:,:]
101 f12[8,:,:] = np.rot90(f[5,:,:],3)
102 f12[9,:,:] = np.rot90(f[5,:,:],2)
103 f12[10,:,:] = np.rot90(f[5,:,:],1)
104 f12[11,:,:] = f[5,:,:]
107 fp[:,0*npx+0:npx] = np.concatenate([f12[0,:,:], f12[1,:,:], f12[2 ,:,:], f12[3 ,:,:]])
108 fp[:,1*npx:2*npx] = np.concatenate([f12[4,:,:], f12[5,:,:], f12[6 ,:,:], f12[7 ,:,:]])
109 fp[:,2*npx:3*npx] = np.concatenate([f12[8,:,:], f12[9,:,:], f12[10,:,:], f12[11,:,:]])
110 fp = np.flipud(np.transpose(fp))
113 maxf = np.nanmax(np.abs(fp))
118 incf = (maxf - minf)/101
119 clev = np.arange(minf,maxf+incf,incf)
121 incf = (maxf - minf)/10
122 ctic = np.arange(minf,maxf+incf,incf)
125 cmap = plt.cm.seismic
263 for tile
in range(4):
267 f12[tile,j,i] = np.nan
269 f12[tile,j,i] = np.nan
271 f12[tile+8,j,i] = np.nan
273 f12[tile+8,j,i] = np.nan
276 fp = np.zeros(12*npy*npx).reshape(4*npy,3*npx)
277 fp[:,0*npx+0:npx] = np.concatenate([f12[0,:,:], f12[1,:,:], f12[2 ,:,:], f12[3 ,:,:]])
278 fp[:,1*npx:2*npx] = np.concatenate([f12[4,:,:], f12[5,:,:], f12[6 ,:,:], f12[7 ,:,:]])
279 fp[:,2*npx:3*npx] = np.concatenate([f12[8,:,:], f12[9,:,:], f12[10,:,:], f12[11,:,:]])
280 fp = np.flipud(np.transpose(fp))
284 fig = plt.figure(figsize=(14,8))
285 cp = plt.contourf(fp,clev,cmap=cmap)
286 cbar = plt.colorbar(cp,ticks=ctic)
287 if Dim2dor3d ==
'3D':
288 plt.title(
'Cubed sphere plot of ' + readvar + itit +
'at level: ' +
str(plot_level))
290 plt.title(
'Cubed sphere plot of ' + readvar)
294 fig.patch.set_facecolor(
'grey')
296 plt.savefig(
'CubedSpherePlot_Field-'+readvar+
'_Level-'+
str(plot_level)+
'.'+filetype, bbox_inches=
'tight',facecolor=fig.get_facecolor())