SABER
normality.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 normality(testdata, test, mpi, omp, suffix, testfig):
12  # Loop over files
13  first = True
14  for impi in range(0, int(mpi)):
15  # Open file
16  f = Dataset(testdata + "/" + test + "/test_" + mpi + "-" + omp + "_" + suffix + "_" + mpi.zfill(6) + "-" + format(impi+1, '06d') + ".nc", "r", format="NETCDF4")
17 
18  # Get data
19  if "ens_norm" in f.variables:
20  nloc = f["ens_norm"][:].shape[0]
21  if first:
22  ne = f["ens_norm"][:].shape[1]
23  ens_norm = np.zeros((0, ne))
24  ens_step = np.zeros((0, ne-1))
25  first = False
26  for iloc in range(0, nloc):
27  ens_norm = np.append(ens_norm, [f["ens_norm"][iloc,:].data], axis=0)
28  ens_step = np.append(ens_step, [f["ens_step"][iloc,:].data], axis=0)
29 
30  # X axis
31  x_norm = np.linspace(1, ne, ne)
32  x_step = np.linspace(1, ne-1, ne-1)
33 
34  # Plots
35  fig, ax = plt.subplots(nrows=2)
36  fig.subplots_adjust(hspace=0.5)
37  ax[0].set_title("Normalized perturbation amplitude")
38  ax[0].set_xlim([1.0,float(ne)])
39  ax[0].set_ylim([-0.1,1.1])
40  ax[0].set_xlabel("Ordered member")
41  ax[0].plot(x_norm, ens_norm[0,:])
42  ax[1].set_title("Normalized perturbation amplitude step")
43  ax[1].set_xlim([1.0,float(ne-1)])
44  ax[1].set_ylim([-0.1,1.1])
45  ax[1].set_xlabel("Ordered member")
46  ax[1].plot(x_step, ens_step[0,:])
47 
48  # Save and close figure
49  plt.savefig(testfig + "/test_" + mpi + "-" + omp + "_" + suffix + ".jpg", format="jpg", dpi=300)
50  plt.close()
normality.normality
def normality(testdata, test, mpi, omp, suffix, testfig)
Definition: normality.py:11