MPAS-JEDI
plot_modelspace_ts_1d.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 plot_utils as pu
15 import var_utils as vu
16 import modelsp_utils as mu
17 
18 def readdata():
19 
20  varNamesListAll1 = []
21  varNamesListAll2 = []
22  varNamesListAll = []
23  for metrics in mu.allFileStats:
24  for varName in mu.varNames2d:
25  for latBand in mu.latBands:
26  for fcTDelta in np.arange(0, mu.fcRange+mu.interval,mu.interval):
27  varNamesList = ['expmgfs_day'+str(fcTDelta)+'_'+ latBand +'_'+ varName + '_' + metrics]
28  varNamesListAll.append(varNamesList)
29 
30  #print(varNamesListAll)
31  for i in range(0,len(varNamesListAll)):
32  alldiffdata = []
33  alldiffdata_rmsdiv = []
34  arraylist = []
35 
36  for iexp, expName in enumerate(mu.expNames):
37  alldata = []
38  TDATE = mu.SDATE
39  xlabeltime = []
40  while TDATE <= mu.EDATE:
41  diffdata = []
42  diffdata_rmsdiv = []
43  date = TDATE.strftime('%Y%m%d%H')
44  xlabeltime = np.append(xlabeltime,date[4:][:-2])
45  nc_file = mu.expDirectory+'/'+mu.expLongNames[iexp]+'/FC1DIAG/'+date+'/diagnostic_stats/expmgfs.nc'
46  nc_fid = Dataset(nc_file, "r", format="NETCDF4")
47  # data1: exp1-GFSANA
48  data = np.array( nc_fid.variables[''.join(varNamesListAll[i])][:] )
49  alldata = np.append(alldata, data)
50  TDATE += mu.DATEINC
51  if (iexp == 0):
52  arraylist = [alldata]
53  else:
54  arraylist= arraylist + [alldata]
55 
56  plotTimeSerial(arraylist,xlabeltime,''.join(varNamesListAll[i]))
57 ##TODO: move this part to basic_plot_functions.py
58 def plotTimeSerial(linesVals,xlabeltime,VarName):
59 
60  fig,ax1 = plt.subplots(1,sharex=True)
61  plt.grid(True)
62  xarray = range(len(xlabeltime))
63  major_ticks = np.arange(0, len(xlabeltime), 1)
64 
65  if (VarName == 'qv' or VarName == 'rho' or VarName == 'q2'):
66  ax1.ticklabel_format(style='sci', axis='y', scilimits=(0,0))
67  nx = mu.nExp
68  for iexp in range(0,mu.nExp):
69  ax1.plot(xarray,linesVals[iexp],pu.plotSpecs[iexp],markersize=5)
70 
71  ax1.set_xticks(major_ticks[::4])
72  # upper right
73  ax1.legend(mu.expNames, loc='upper left',fontsize=12,frameon=False)
74 
75  FCDay = VarName.split("_")[1]
76  if (FCDay == 'day0.0'):
77  ax1.set_xlabel('Analysis Time',fontsize=15)
78  ax1.set_xticks(xarray[::4])
79  ax1.set_xticklabels(xlabeltime[::4],rotation=90)
80  elif (FCDay == 'day0.25'):
81  ax1.set_xlabel( '6h Forecast',fontsize=15)
82  ax1.set_xticks(xarray[::4])
83  ax1.set_xticklabels(xlabeltime[::4],rotation=90)
84  else:
85  ax1.set_xlabel( 'Lead Time (day)',fontsize=15)
86 
87  ax1.grid()
88  ax1.set_xticklabels(xlabeltime[::4])
89  plt.xticks(rotation=90)
90  plt.grid(True)
91  region = VarName.split("_")[2]
92  var = '_'.join(VarName.split("_")[3:][:-1]) # surface_pressure
93  stats = ''.join(VarName.split("_")[-1:])
94  ax1.set_ylabel(stats,fontsize=15)
95  plt.title(stats+' variable:'+vu.varDictModel[var][1]+'('+ vu.varDictModel[var][0]+') '+region, fontsize = 12)
96  plt.savefig(VarName+'.png',dpi=300,bbox_inches='tight')
97  plt.close()
98 def main():
99  readdata()
100 
101 if __name__ == '__main__': main()
def plotTimeSerial(linesVals, xlabeltime, VarName)
TODO: move this part to basic_plot_functions.py.