MPAS-JEDI
plot_modelspace_ts_1d_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 # http://code.google.com/p/netcdf4-python/
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 import plot_utils as pu
14 import var_utils as vu
15 import modelsp_utils as mu
16 
17 def readdata():
18  for metrics in mu.allFileStats:
19  for varName in mu.varNames2d:
20  for latBand in mu.latBands:
21  arraylist = []
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  # data1: exp1-GFSANA
32  data = np.array( nc_fid.variables[''.join(varNamesList)][:])
33  alldata = np.append(alldata, data)
34  xlabeltime = np.append(xlabeltime,fcTDelta)
35  varNamesListUse = 'expmgfs_fc_'+ latBand +'_'+ varName + '_' + metrics
36  if (iexp == 0):
37  arraylist = [alldata]
38  else:
39  arraylist= arraylist + [alldata]
40  plotTimeSerial(arraylist,xlabeltime,varNamesListUse)
41 #TODO: move this part to basic_plot_functions.py
42 def plotTimeSerial(linesVals,xlabeltime,VarName):
43 
44  fig,ax1 = plt.subplots(1,sharex=True)
45  plt.grid(True)
46  xarray = range(len(xlabeltime))
47  major_ticks = np.arange(0, len(xlabeltime), 1)
48 
49  if (VarName == 'qv' or VarName == 'rho' or VarName == 'q2'):
50  ax1.ticklabel_format(style='sci', axis='y', scilimits=(0,0))
51  nx = mu.nExp
52  for iexp in range(0,mu.nExp):
53  ax1.plot(xarray,linesVals[iexp],pu.plotSpecs[iexp],markersize=5)
54 
55  ax1.set_xticks(major_ticks[::4])
56  # upper right
57  ax1.legend(mu.expNames, loc='upper left',fontsize=12,frameon=False)
58 
59  FCDay = VarName.split("_")[1]
60  if (FCDay == 'day0.0'):
61  ax1.set_xlabel('Analysis Time',fontsize=15)
62  ax1.set_xticks(xarray[::4])
63  ax1.set_xticklabels(xlabeltime[::4],rotation=90)
64  elif (FCDay == 'day0.25'):
65  ax1.set_xlabel( '6h Forecast',fontsize=15)
66  ax1.set_xticks(xarray[::4])
67  ax1.set_xticklabels(xlabeltime[::4],rotation=90)
68  else:
69  ax1.set_xlabel( 'Lead Time (day)',fontsize=15)
70  ax1.set_xticks(major_ticks[::1])
71  ax1.set_xticks(xarray[::1])
72  ax1.set_xticklabels(xlabeltime[::1],rotation=0)
73 
74  ax1.grid()
75  #ax1.set_xticklabels(xlabeltime[::4])
76  plt.xticks(rotation=90)
77  plt.grid(True)
78  region = VarName.split("_")[2]
79  var = '_'.join(VarName.split("_")[3:][:-1]) # surface_pressure
80  stats = ''.join(VarName.split("_")[-1:])
81  ax1.set_ylabel(stats,fontsize=15)
82  plt.title(stats+' variable:'+vu.varDictModel[var][1]+'('+ vu.varDictModel[var][0]+') '+region, fontsize = 12)
83  plt.savefig(VarName+'.png',dpi=300,bbox_inches='tight')
84  plt.close()
85 def main():
86  readdata()
87 
88 if __name__ == '__main__': main()
def plotTimeSerial(linesVals, xlabeltime, VarName)