SABER
randomization.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 randomization(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 factors
16  nefac = f["nefac"][:]
17 
18  # Get number of tests
19  nfac = nefac.shape[0]
20 
21  # Get number of factors
22  nfac = nefac.shape[0]
23  x = np.linspace(1, nfac, nfac)
24 
25  # Get data, compute mean and standard deviation
26  mse_mean = np.zeros((0, nfac))
27  mse_mean = np.append(mse_mean, [np.mean(f["mse"][:,:], axis=1)], axis=0)
28  mse_mean = np.append(mse_mean, [np.mean(f["mse_th"][:,:], axis=1)], axis=0)
29  mse_std = np.zeros((0, nfac))
30  mse_std = np.append(mse_std, [np.std(f["mse"][:,:], axis=1)], axis=0)
31  mse_std = np.append(mse_std, [np.std(f["mse_th"][:,:], axis=1)], axis=0)
32 
33  # Plots
34  fig, ax = plt.subplots()
35  ax.set_xlim([0.5,float(nfac)+0.5])
36  ax.set_xlabel("Number of members")
37  ax.set_ylabel("Mean Square Error")
38  ax.plot(x, mse_mean[0,:], 'k-')
39  ax.plot(x, mse_mean[0,:]-mse_std[0,:], 'k--')
40  ax.plot(x, mse_mean[0,:]+mse_std[0,:], 'k--')
41  ax.plot(x, mse_mean[1,:], 'r-')
42  ax.plot(x, mse_mean[1,:]-mse_std[1,:], 'r--')
43  ax.plot(x, mse_mean[1,:]+mse_std[1,:], 'r--')
44 
45  # Save and close figure
46  plt.savefig(testfig + "/test_" + mpi + "-" + omp + "_" + suffix + ".jpg", format="jpg", dpi=300)
47  plt.close()
randomization.randomization
def randomization(testdata, test, mpi, omp, suffix, testfig)
Definition: randomization.py:11