1 from netCDF4
import Dataset
5 import matplotlib.pyplot
as plt
13 fields_geos = [
'ua',
'va',
't',
'delp',
'q',
'qi',
'ql',
'o3mr']
14 fields_gfs = [
'ua',
'va',
'T',
'Ps',
'sphum',
'ice_wat',
'liq_wat',
'o3mr']
16 kind_gfs = [
'fv_core',
'fv_core',
'fv_core',
'fv_core',
'fv_tracer',
'fv_tracer',
'fv_tracer',
'fv_tracer']
21 nl1 =
'../INPUTS/GEOS_c180/H21/GEOS.traj.c180.eta.'+date+
'_'+time[0:4]+
'z.nc4' 22 nl2 =
'../INPUTS/GEOS_c180/H15/GEOS.traj.c180.eta.'+date+
'_'+time[0:4]+
'z.nc4' 25 tlm = date+
'.'+time+
'.linearforecast.final.KIND.res.tileXX.nc' 28 if (nl_type ==
'gfs'):
29 tmp = re.sub(
"XX",
str(1), nl1)
30 fh_nl1 = Dataset(tmp, mode=
'r') 31 elif (nl_type ==
'geos'):
32 fh_nl1 = Dataset(nl1, mode=
'r') 38 if (nl_type ==
'gfs'):
42 elif (nl_type ==
'geos'):
47 im =
len(fh_nl1.dimensions[nl_xid])
48 jm =
len(fh_nl1.dimensions[nl_yid])
49 lm =
len(fh_nl1.dimensions[nl_zid])
51 if (nl_type ==
'gfs'):
56 print(
'Reading variables')
58 x_nlm = np.zeros(im*jm*lm*nm).reshape(nm,lm,jm,im)
59 x_tlm = np.zeros(im*jm*lm*nm).reshape(nm,lm,jm,im)
61 if (nl_type ==
'gfs'):
68 fh_nl2 = Dataset(nl2, mode=
'r') 71 if (fields[i] !=
'Ps'):
72 x_nlm[i,:,:,:] = fh_nl2.variables[fields[i]][:] - fh_nl1.variables[fields[i]][:]
73 if (fields[i] ==
'delp'):
74 tmp = np.sum(x_nlm[i,:,:,:],axis=0)
77 elif (fields[i] ==
'Ps'):
79 x_nlm[i,l,:,:] = fh_nl2.variables[fields[i]][:] - fh_nl1.variables[fields[i]][:]
82 if (tlm_type ==
'gfs'):
90 filetile1 = re.sub(
"XX",
str(tile+1), tlm)
91 filetile = re.sub(
"KIND", kind_gfs[i], filetile1)
93 fh_tlm = Dataset(filetile, mode =
'r') 98 if (fields[i] !=
'Ps'):
99 x_tlm[i,:,js:je,:] = fh_tlm.variables[fields[i]][:]
100 if (fields[i] ==
'delp'):
101 tmp = np.sum(x_nlm[i,:,js:je,:],axis=0)
103 x_tlm[i,l,js:je,:] = tmp
104 elif (fields[i] ==
'Ps'):
106 x_tlm[i,l,js:je,:] = fh_tlm.variables[fields[i]][:]
111 print(
'Computing Correlations')
112 f, ax = plt.subplots(1, 8, figsize=(18, 6))
114 corr_tlm = np.zeros(lm*nm).reshape(nm,lm)
117 c1 = np.corrcoef(np.reshape(x_tlm[i,j,:,:],(im*jm,)),np.reshape(x_nlm[i,j,:,:],(im*jm,)))
119 corr_tlm[i,j] = c1[0,1]
123 for j
in range(lm-1,-1,-1):
124 if np.isnan(corr_tlm[i,j]) ==
True:
128 ax[i].plot(corr_tlm[i,rangeup1:lm],range(rangeup1+1,lm+1),color=
'b')
130 ax[i].set_ylim(1, 72)
132 ax[i].set_title(fields_geos[i])
134 ax[i].set_ylabel(
'Model Level')
136 print(
'Corelation:',fields_geos[i],np.mean(corr_tlm[i,rangeup1:lm]) )
139 plt.savefig(
'Correlation.png')