SABER
lct_cor.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 lct_cor(testdata, test, mpi, omp, suffix, testfig):
14  # Processor, index and level to plot
15  iproc_plot = 1
16  ic1a_plot = 1
17  il0_plot = 1
18 
19  # Open file
20  f = Dataset(testdata + "/" + test + "/test_" + mpi + "-" + omp + "_" + suffix + "_" + mpi.zfill(6) + "-" + format(iproc_plot, '06d') + ".nc", "r", format="NETCDF4")
21 
22  # Get _FillValue
23  _FillValue = f.__dict__["_FillValue"]
24 
25  # Get vertical unit
26  vunit = f["vunit"][:]
27 
28  # Get number of levels
29  nl0 = vunit.shape[0]
30 
31  for group in f.groups:
32  # Get lon/lat/levels
33  lon = f.groups[group]["lon"][:,:]
34  lat = f.groups[group]["lat"][:,:]
35  l0rl0_to_l0 = f.groups[group]["l0rl0_to_l0"][:,:]
36 
37  for fieldname in ["raw", "fit", "fit_filt"]:
38  if fieldname in f.groups[group].variables:
39  # Get field
40  field = f.groups[group][fieldname][:,:,:,:]
41 
42  # Get dimensions
43  nl0r = field.shape[2]
44  nc3 = field.shape[3]
45 
46  # Set masked values and levels
47  field = ma.masked_invalid(field)
48  vmax = np.max(np.abs(field))
49  if (vmax > 0.0):
50  levels = np.linspace(-vmax, vmax, 21)
51  else:
52  levels = np.linspace(-1.0, 1.0, 3)
53  field = field.filled(fill_value=-1.0e38)
54 
55  # Plots
56  fig, ax = plt.subplots(nrows=nl0r)
57  fig.subplots_adjust(hspace=0.4, right=0.8)
58  for il0r in range(0, nl0r):
59  ax[il0r].set_title(group + " - " + fieldname + " @ " + str(l0rl0_to_l0[il0_plot,il0r]))
60  im = ax[il0r].tricontourf(lon[ic1a_plot,:], lat[ic1a_plot,:], field[il0_plot,ic1a_plot,il0r,:], levels=levels, cmap="bwr")
61 
62  # Colorbar
63  cbar_ax = fig.add_axes([0.85, 0.15, 0.05, 0.7])
64  fig.colorbar(im, cax=cbar_ax)
65 
66  # Save and close figure
67  plt.savefig(testfig + "/test_" + mpi + "-" + omp + "_" + suffix + "_" + group + "_" + fieldname + ".jpg", format="jpg", dpi=300)
68  plt.close()
lct_cor.lct_cor
def lct_cor(testdata, test, mpi, omp, suffix, testfig)
Definition: lct_cor.py:13