SABER
diag.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 
3 import argparse
4 from netCDF4 import Dataset
5 import matplotlib
6 import matplotlib.pyplot as plt
7 import numpy as np
8 import numpy.ma as ma
9 import os
10 
11 def diag(testdata, test, mpi, omp, suffix, testfig):
12  # Open file
13  f = Dataset(testdata + "/" + test + "/test_" + mpi + "-" + omp + "_" + suffix + ".nc", "r", format="NETCDF4")
14 
15  # Get _FillValue
16  _FillValue = f.__dict__["_FillValue"]
17 
18  # Get vertical unit
19  vunit = f["vunit"][:]
20  vunitmin = np.min(vunit)
21  vunitmax = np.max(vunit)
22 
23  # Get number of levels
24  nl0 = vunit.shape[0]
25 
26  # Profiles only
27  if nl0 == 1:
28  return
29 
30  # Diagnostics list
31  diag_list = ["coef_ens","fit_rh","fit_rv"]
32 
33  # Plots
34  for diag in diag_list:
35  fig, ax = plt.subplots()
36  fig.subplots_adjust(right=0.8)
37  cmap = matplotlib.cm.get_cmap('Spectral')
38  ax.set_title(diag)
39  ax.set_ylim([vunitmin,vunitmax])
40  valid = False
41  for group in f.groups:
42  for subgroup in f.groups[group].groups:
43  if (diag in f.groups[group].groups[subgroup].variables):
44  ax.plot(f.groups[group].groups[subgroup][diag][:], vunit, label=group + " - " + subgroup)
45  valid = True
46 
47  if (valid):
48  # Single legend
49  handles, labels = ax.get_legend_handles_labels()
50  fig.legend(handles, labels, loc='center right')
51 
52  # Save and close figure
53  plt.savefig(testfig + "/test_" + mpi + "-" + omp + "_" + suffix + "_" + diag + ".jpg", format="jpg", dpi=300)
54  plt.close()
55  else:
56  # Just close the figure
57  plt.close()
diag.diag
def diag(testdata, test, mpi, omp, suffix, testfig)
Definition: diag.py:11