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