MPAS-JEDI
plot_modelspace_ts_2d.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 datetime as dt
7 from datetime import datetime, timedelta
8 import basic_plot_functions as BasicPF
9 import plot_utils as pu
10 import var_utils as vu
11 import modelsp_utils as mu
12 def readdata():
13 
14  for fcTDelta in np.arange(0,mu.fcRange+mu.interval,mu.interval):
15  varNamesListAll = []
16  for metrics in mu.allFileStats: #allmetrics:
17  for varName in mu.varNames3d:
18  for latBand in mu.latBands:
19  varNamesList = ['expmgfs_day'+str(fcTDelta)+'_'+ latBand +'_'+ varName + '_' + metrics]
20  varNamesListAll.append(varNamesList)
21  for i in range(0,len(varNamesListAll)):
22  arraylist = []
23  for iexp, expName in enumerate(mu.expNames):
24 
25  alldata = []
26  alldata2 = []
27  alldiffdata = []
28  alldiffdata_rmsdiv = []
29  xlabeltime = []
30  TDATE = mu.SDATE
31 
32  while TDATE <= mu.EDATE:
33 
34  data1 = []
35  diffdata = []
36  diffdata_rmsdiv = []
37  date = TDATE.strftime('%Y%m%d%H')
38  xlabeltime = np.append(xlabeltime,date[4:][:-2])
39 
40  nc_file = mu.expDirectory+'/'+mu.expLongNames[iexp]+'/FC1DIAG/'+date+'/diagnostic_stats/expmgfs.nc'
41  nc_fid = Dataset(nc_file, "r", format="NETCDF4")
42  #data: exp1-GFSANA
43  data = np.array( nc_fid.variables[''.join(varNamesListAll[i])][:] )
44  alldata = np.append(alldata, data)
45 
46  TDATE += mu.DATEINC
47 
48  ylevels = list(np.arange(0,len(data),1))
49  alldata = alldata.reshape(len(xlabeltime),len(data)).T
50  if (iexp == 0):
51  arraylist = [alldata]
52  else:
53  arraylist= arraylist + [alldata]
54 
55  dmin = np.amin(arraylist) #min(arraylist.all()) #np.amin(arraylist)
56  dmax = np.amax(arraylist) #max(arraylist.all()) #np.amax(arraylist)
57  nx = mu.nExp
58  ny = 1 #nVars
59  nsubplots = nx * ny
60  subplot_size = 2.4
61  aspect = 0.55
62  FULL_SUBPLOT_LABELS =True
63  interiorLabels = True
64  fig = pu.setup_fig(nx, ny, subplot_size, aspect, FULL_SUBPLOT_LABELS)
65  title_tmp = ''.join(varNamesListAll[i])
66  region = ''.join(title_tmp.split("_")[2:][:-2])
67  var = ''.join(title_tmp.split("_")[3:][:-1])
68  stats = ''.join(title_tmp.split("_")[4:])
69  FCDay = ''.join(title_tmp.split("_")[1:][:-3])
70  statDiagLabel = stats
71  if (stats == 'Mean'):
72  signDefinite = False
73  else:
74  signDefinite = True
75  #print(region,var,stats)
76  indepLabel = 'Vertical level'
77  sciTicks = False
78  invert_ind_axis = False
79  iplot = 0
80 
81  for k in arraylist:
82  valuemin = np.amin(k)
83  valuemax = np.amax(k)
84  title = mu.expNames[iplot] +' var:'+vu.varDictModel[var][1]+'('+ vu.varDictModel[var][0]+')\
85  '+region+' min=' +str(round(valuemin,3))+' max='+str(round(valuemax,3))
86 
87  BasicPF.plotTimeSeries2D( fig, \
88  xlabeltime,ylevels, k, \
89  title, statDiagLabel, \
90  sciTicks, signDefinite, \
91  indepLabel, invert_ind_axis, \
92  ny, nx, nsubplots, iplot, \
93  dmin = dmin, dmax = dmax, \
94  interiorLabels = interiorLabels )
95  iplot = iplot +1
96  filename = ''.join(varNamesListAll[i])+'_TS_2d'
97  pu.finalize_fig(fig, filename, 'png', FULL_SUBPLOT_LABELS, True)
98 
99  #plot diff between two exp for RMS:
100  if (mu.diff2exp == 'True' and ''.join(varNamesListAll[i])[-3:] == 'RMS'):
101  for iexp in range(1,mu.nExp):
102  # target_exp - control_exp
103  alldiffdata = arraylist[iexp]-arraylist[0]
104  BasicPF.plotTimeserial2D(alldiffdata,xlabeltime,ylevels,''.join(varNamesListAll[i])+mu.expNames[iexp]+'-RMS'+mu.expNames[0])
105 def main():
106  readdata()
107 
108 if __name__ == '__main__': main()