6 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 copy
import deepcopy
11 from datetime
import datetime, timedelta
12 import modelsp_utils
as mu
15 if os.path.exists(mu.expStats+
'.nc'):
16 os.remove(mu.expStats+
'.nc')
18 date = path.split(
'/')[-2]
19 initDate = datetime.strptime(date,
"%Y%m%d%H")
20 lats, lons = mu.readGrid()
22 for varName
in mu.varNames:
23 for latBand
in range(0, len(mu.latBands)):
29 for fcTDelta
in np.arange(0, mu.fcRange+mu.interval,mu.interval):
30 fcDate = initDate + timedelta(days=fcTDelta)
31 fileDate= fcDate.strftime(
"%Y-%m-%d_%H.%M.%S")
32 ncFile1 = mu.GFSANA_DIR+
'/x1.40962.init.'+fileDate+
'.nc'
33 ncFile2 =
'../restart.'+fileDate+
'.nc'
34 tmp = mu.varDiff(varName,ncFile1,ncFile2)
38 tmpbin = deepcopy(tmp)
39 tmpbin[np.logical_or(lats < mu.latBandsBounds [latBand+1], lats > mu.latBandsBounds [latBand])] = np.NaN
41 newfile =
write_stats(tmpbin,varName,mu.latBands[latBand],str(fcTDelta))
43 meannc = np.nanmean(tmpbin.flatten(),axis=0)
44 rmsnc = np.sqrt(np.nanmean(tmpbin.flatten()**2,axis=0))
45 msnc = np.nanmean(tmpbin.flatten()**2,axis=0)
47 meanncs = np.append(meanncs,meannc)
48 rmsncs = np.append(rmsncs,rmsnc)
49 msncs = np.append(msncs,msnc)
57 STATS[
'Mean'] = np.nanmean(array_f,axis=0)
58 STATS[
'MS'] = np.nanmean(array_f**2,axis=0)
59 STATS[
'RMS'] = np.sqrt(np.nanmean(array_f**2,axis=0))
60 STATS[
'STD'] = np.nanstd(array_f,axis=0)
61 STATS[
'Min'] = np.nanmin(array_f,axis=0)
62 STATS[
'Max'] = np.nanmax(array_f,axis=0)
63 if os.path.exists(mu.expStats+
'.nc'):
64 w_nc_fid = Dataset(mu.expStats+
'.nc',
'a', format=
'NETCDF4')
66 w_nc_fid = Dataset(mu.expStats+
'.nc',
'w', format=
'NETCDF4')
67 w_nc_fid.description =
"MPAS diagnostics/statistics"
68 w_nc_fid.createDimension(
'level', 55)
69 w_nc_fid.createDimension(
'fcnums', int(mu.fcNums))
70 w_nc_fid.createDimension(
'levelP1', 56)
71 w_nc_fid.createDimension(
'levelSurface', 1)
72 for statName
in mu.allFileStats:
73 if varNames
in mu.varNames3d:
75 bias2exp = w_nc_fid.createVariable(mu.expStats+
"_day"+fcTDelta+
"_"+band+
"_"+varNames+
"_"+statName,
'f4',
"levelP1")
77 bias2exp = w_nc_fid.createVariable(mu.expStats+
"_day"+fcTDelta+
"_"+band+
"_"+varNames+
"_"+statName,
'f4',
"level")
79 bias2exp = w_nc_fid.createVariable(mu.expStats+
"_day"+fcTDelta+
"_"+band+
"_"+varNames+
"_"+statName,
'f4',
"levelSurface")
80 w_nc_fid.variables[mu.expStats+
"_day"+fcTDelta+
'_'+band+
'_'+varNames+
'_'+statName][:] = STATS[statName]
85 if os.path.exists(mu.expStats+
'.nc'):
86 w_nc_fid = Dataset(mu.expStats+
'.nc',
'a', format=
'NETCDF4')
88 w_nc_fid = Dataset(mu.expStats+
'.nc',
'w', format=
'NETCDF4')
89 w_nc_fid.description =
"MPAS diagnostics/statistics"
91 bias2exp = w_nc_fid.createVariable(mu.expStats+
"_"+band+
"_"+varNames+
"_"+statName,
'f4',
"fcnums")
92 w_nc_fid.variables[mu.expStats+
'_'+band+
'_'+varNames+
'_'+statName][:] = array_f
99 if __name__ ==
'__main__':
main()
def write_stats_levall(array_f, varNames, band, statName)
def write_stats(array_f, varNames, band, fcTDelta)