MPAS-JEDI
plot_modelspace_ci.py
Go to the documentation of this file.
1 import os
2 import sys
3 import numpy
4 import numpy as np
5 from netCDF4 import Dataset
6 import matplotlib
7 matplotlib.use('pdf')
8 import matplotlib.cm as cm
9 import matplotlib.pyplot as plt
10 from mpl_toolkits.basemap import Basemap
11 from copy import deepcopy
12 import datetime as dt
13 from datetime import datetime, timedelta
14 import numpy.random as npr
15 import var_utils as vu
16 import modelsp_utils as mu
17 
18 expStats = 'expmgfsci.nc'
19 allmetrics = ['RMS'] #['MS']
20 
21 def readdata():
22 
23  varNamesListAll = []
24  varName = []
25  for metrics in allmetrics:
26  #only for 3dim variables
27  for varName in mu.varNames3d:
28  for latBand in mu.latBands:
29  for fcTDelta in np.arange(0, mu.fcRange+mu.interval,mu.interval):
30  varNamesList = ['expmgfs_day'+str(fcTDelta)+'_'+ latBand +'_'+ varName + '_' + metrics]
31  varNamesListAll.append(varNamesList)
32  for metrics in allmetrics:
33  #for 2dim and 3dim variables:
34  for varName in mu.varNames:
35  for latBand in mu.latBands:
36  #for all levels:
37  varNamesList2 = ['expmgfs_'+ latBand +'_'+ varName + '_' + metrics]
38  varNamesListAll.append(varNamesList2)
39 
40  for i in range(0,len(varNamesListAll)):
41  nc_file = mu.EXP_DIR2+'/'+mu.endDate+'/diagnostic_stats/expmgfsci.nc'
42  nc_fid = Dataset(nc_file, "r", format="NETCDF4")
43 
44  data = np.array( nc_fid.variables[''.join(varNamesListAll[i])][:] )
45  x, y = data.shape
46  t = list(np.arange(0,x,1))
47  varName = ''.join(varNamesListAll[i])
48  if (x == 55 or x == 56):
49  region = ''.join(varName.split("_")[2:][:-2])
50  var = '_'.join(varName.split("_")[3:][:-1])
51  stats = ''.join(varName.split("_")[4:])
52  plt.title(stats+' variable:'+vu.varDictModel[var][1]+'('+ vu.varDictModel[var][0]+') '+region, fontsize = 12)
53  plt.plot(data[:,0],t)
54  plt.fill_betweenx( t, data[:,1],data[:,2],alpha=0.3, linestyle='-.')
55  plt.plot([0,0],[0, x], ls="--", c=".3") # zero line
56  plt.xlabel('RMS('+mu.exp2Name+')-RMS('+mu.exp1Name+')',fontsize=15)
57  plt.ylabel('Levels',fontsize=15)
58  else:
59  region = ''.join(varName.split("_")[1:][:-2])
60  var = '_'.join(varName.split("_")[2:][:-1])
61  stats = ''.join(varName.split("_")[3:])
62  plt.title(stats+' variable:'+vu.varDictModel[var][1]+'('+ vu.varDictModel[var][0]+') '+region, fontsize = 12)
63  plt.plot(t,data[:,0])
64  plt.fill_between( t,data[:,1],data[:,2],alpha=0.3, linestyle='-.')
65  plt.plot([0, x],[0,0], ls="--", c=".3") # zero line
66  plt.ylabel('RMS('+mu.exp2Name+')-RMS('+mu.exp1Name+')',fontsize=15)
67  plt.xlabel('Lead Time (day)',fontsize=15)
68 
69  plt.grid(True)
70  plt.savefig(''.join(varNamesListAll[i])+'_ci.png',dpi=200,bbox_inches='tight')
71  plt.close()
72 
73 def main():
74  readdata()
75 
76 if __name__ == '__main__': main()