SABER
umf.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 umf(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 lon/lat
19  lon = f["lon"][:]
20  lat = f["lat"][:]
21 
22  # Variables
23  var_list = ["m2","m4","kurt"]
24 
25  # Get number of levels
26  nl0 = f[var_list[0]][:,:].shape[0]
27 
28  for var in var_list:
29  # Read variable
30  field = f[var][:,:]
31 
32  # Set masked values and levels
33  field = ma.masked_invalid(field)
34  vmax = np.max(field)
35  levels = np.linspace(0, vmax, 21)
36  field = field.filled(fill_value=-1.0e38)
37 
38  # Plots
39  fig, ax = plt.subplots(nrows=nl0)
40  fig.subplots_adjust(hspace=0.4, right=0.8)
41  for il0 in range(0, nl0):
42  ax[il0].set_title(var + " @ " + str(il0))
43  im = ax[il0].tricontourf(lon, lat, field[il0,:], levels=levels, cmap="YlOrRd")
44 
45  # Colorbar
46  cbar_ax = fig.add_axes([0.85, 0.15, 0.05, 0.7])
47  fig.colorbar(im, cax=cbar_ax)
48 
49  # Save and close figure
50  plt.savefig(testfig + "/test_" + mpi + "-" + omp + "_" + suffix + "_" + var + ".jpg", format="jpg", dpi=300)
51  plt.close()
umf.umf
def umf(testdata, test, mpi, omp, suffix, testfig)
Definition: umf.py:11