SABER
contour_centered.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.cm as cm
7 import matplotlib.pyplot as plt
8 import matplotlib.tri as tri
9 import numpy as np
10 import numpy.ma as ma
11 import os
12 
13 def contour_centered(testdata, test, mpi, omp, suffix, testfig):
14  # Open file
15  f = Dataset(testdata + "/" + test + "/test_" + mpi + "-" + omp + "_" + suffix + ".nc", "r", format="NETCDF4")
16 
17  # Get _FillValue
18  _FillValue = f.__dict__["_FillValue"]
19 
20  # Get lon/lat
21  lon = f["lon"][:]
22  lat = f["lat"][:]
23 
24  # Get vertical unit
25  vunit = f["vunit"][:,:]
26 
27  # Get number of levels
28  nl0 = vunit.shape[0]
29 
30  for group in f.groups:
31  for var in f.groups[group].variables:
32  # Read variable
33  field = f.groups[group][var][:,:]
34 
35  # Set masked values and levels
36  field = ma.masked_invalid(field)
37  vmax = np.max(np.abs(field))
38  if (vmax > 0.0):
39  levels = np.linspace(-vmax, vmax, 21)
40  else:
41  levels = np.linspace(-1.0, 1.0, 3)
42  field = field.filled(fill_value=-1.0e38)
43 
44  # Plots
45  fig, ax = plt.subplots(nrows=nl0)
46  fig.subplots_adjust(hspace=0.4, right=0.8)
47  for il0 in range(0, nl0):
48  ax[il0].set_title(group + " - " + var + " @ " + str(il0))
49  im = ax[il0].tricontourf(lon, lat, field[il0,:], levels=levels, cmap="bwr")
50 
51  # Colorbar
52  cbar_ax = fig.add_axes([0.85, 0.15, 0.05, 0.7])
53  fig.colorbar(im, cax=cbar_ax)
54 
55  # Save and close figure
56  plt.savefig(testfig + "/test_" + mpi + "-" + omp + "_" + suffix + "_" + group + "_" + var + ".jpg", format="jpg", dpi=300)
57  plt.close()
58 
59  for subgroup in f.groups[group].groups:
60  for var in f.groups[group].groups[subgroup].variables:
61  # Read variable
62  field = f.groups[group].groups[subgroup][var][:,:]
63 
64  # Set masked values and levels
65  field = ma.masked_invalid(field)
66  vmax = np.max(np.abs(field))
67 
68  levels = np.linspace(-vmax, vmax, 21)
69  field = field.filled(fill_value=-1.0e38)
70 
71  # Plots
72  fig, ax = plt.subplots(nrows=nl0)
73  fig.subplots_adjust(hspace=0.4, right=0.8)
74  for il0 in range(0, nl0):
75  ax[il0].set_title(group + " - " + subgroup + " - " + var + " @ " + str(il0))
76  im = ax[il0].tricontourf(lon, lat, field[il0,:], levels=levels, cmap="bwr")
77 
78  # Colorbar
79  cbar_ax = fig.add_axes([0.85, 0.15, 0.05, 0.7])
80  fig.colorbar(im, cax=cbar_ax)
81 
82  # Save and close figure
83  plt.savefig(testfig + "/test_" + mpi + "-" + omp + "_" + suffix + "_" + group + "_" + subgroup + "_" + var + ".jpg", format="jpg", dpi=300)
84  plt.close()
contour_centered.contour_centered
def contour_centered(testdata, test, mpi, omp, suffix, testfig)
Definition: contour_centered.py:13