diff --git a/BayesValidRox/tests/PA-A/util/postDist_visualization.py b/BayesValidRox/tests/PA-A/util/postDist_visualization.py index 752757c11770ba913839844e07a754ec56f84c00..e5843e284c0dbcc94dee6ec995add1bfeb0cb33f 100755 --- a/BayesValidRox/tests/PA-A/util/postDist_visualization.py +++ b/BayesValidRox/tests/PA-A/util/postDist_visualization.py @@ -5,27 +5,25 @@ Created on Thu Aug 13 09:53:11 2020 @author: farid """ -import sys, os, joblib +import sys +import os +import joblib import numpy as np import pandas as pd import h5py import corner -try: - import cPickle as pickle -except ModuleNotFoundError: - import _pickle as pickle # Local -sys.path.insert(0,'./../../../../BayesValidRox/') +sys.path.insert(0, './../../../../BayesValidRox/') -inletLoc = 'top' # top or left -inclusion = 'squared' # squared or circular +inletLoc = 'top' # top or left +inclusion = 'squared' # squared or circular -Name = 'stokesdarcyER' #stokesdarcyER stokesdarcyBJ stokespnm stokespnmNA -modelName = 'ffpm-{}_{}_inclusion_{}Inflow'.format(Name,inclusion,inletLoc) +name = 'stokespnmNA' # stokesdarcyER stokesdarcyBJ stokespnm stokespnmNA +modelName = f'ffpm-{name}_{inclusion}_inclusion_{inletLoc}Inflow' # Load the pickle objects -data_dir = '../Results_15_12_2021_topInflow/outputs_{}/'.format(modelName) +data_dir = '../Results_19_01_2022_topInflow/outputs_{}/'.format(modelName) # data_dir = '../outputs_{}/'.format(modelName) # with open(data_dir+'PCEModel_ffpm-{}.pkl'.format(modelName), 'rb') as input: @@ -44,10 +42,9 @@ lw = 3 alpha = 0.45 plt.rc('figure', figsize = (24, 16)) plt.rc('font', family='serif', serif='Arial') -plt.rc('axes', grid = True) # plt.rc('text', usetex=True) plt.rc('axes', linewidth=lw) -plt.rc('axes', grid=True) +plt.rc('axes', grid=False) plt.rc('grid', linestyle="-") plt.rc('font', size=BIGGER_SIZE) # controls default text sizes plt.rc('axes', titlesize=BIGGER_SIZE) # fontsize of the axes title @@ -58,9 +55,9 @@ plt.rc('legend', fontsize=BIGGER_SIZE) # legend fontsize plt.rc('figure', titlesize=BIGGER_SIZE) # fontsize of the figure title -#===================================================== -#========== DEFINITION OF THE METAMODEL ============ -#===================================================== +# ===================================================== +# ========== DEFINITION OF THE METAMODEL ============ +# ===================================================== PCEModel = Bayes.PCEModel # Update slicing index # Extract the experimental design @@ -72,12 +69,16 @@ EDY = PCEModel.ExpDesign.Y Outputs = ['velocity [m/s]', 'p'] # labels = [PCEModel.Inputs.Marginals[i].Name for i in range(PCEModel.NofPa)] labels = list(Bayes.Posterior_df.keys()) -#===================================================== -#================= Visualization =================== -#===================================================== +if '$K$' in labels: + index = labels.index('$K$') + labels[index] = r"$\mathsf{K}$" +# ===================================================== +# ================= Visualization =================== +# ===================================================== # Make directory outDir = './posteriorPlot' -if not os.path.exists(outDir): os.makedirs(outDir) +if not os.path.exists(outDir): + os.makedirs(outDir) # ----- Posterior plot --------- # import emcee @@ -126,11 +127,16 @@ goodpostSamples = postSamples#[goodIndices] figPosterior = corner.corner(goodpostSamples, labels=labels, # range=PCEModel.ExpDesign.BoundTuples, # color='grey', - use_math_text = True, + use_math_text=True, quantiles=[0.15, 0.5, 0.85], show_titles=True, labelpad=0.2, title_fmt='.2e', + plot_datapoints=False, + plot_density=False, + fill_contours=True, + smooth=0.5, + smooth1d=0.5, title_kwargs={"fontsize": SMALL_SIZE}) # Loop over axes and set x limits diff --git a/BayesValidRox/tests/PA-A/util/post_plot_PAPER_v2.py b/BayesValidRox/tests/PA-A/util/post_plot_PAPER_v2.py index 83c172bf98993843467501d716dc973b52b9f764..c4fe87c30bca48c0072916383cf2a5865abd45cc 100644 --- a/BayesValidRox/tests/PA-A/util/post_plot_PAPER_v2.py +++ b/BayesValidRox/tests/PA-A/util/post_plot_PAPER_v2.py @@ -9,7 +9,6 @@ import numpy as np import os import sys import joblib -import seaborn as sns import h5py import pandas as pd import matplotlib.pylab as plt @@ -18,7 +17,8 @@ import matplotlib.pylab as plt sys.path.insert(0, "./../../../../BayesValidRox/") plt.rcParams.update({'lines.markeredgewidth': 1}) -def postPredictiveplot(modelNames, result_folder= ".", case="Calib", + +def postPredictiveplot(modelNames, result_folder=".", case="Calib", inclusion="squared", inletLoc="top", bins="auto"): OutputDir = f"../{result_folder}/postPredPlots_{case}" @@ -35,15 +35,19 @@ def postPredictiveplot(modelNames, result_folder= ".", case="Calib", modelName = f'ffpm-{name}_{inclusion}_inclusion_{inletLoc}Inflow' if case == 'calib': - directory = f"../{result_folder}/outputs_{modelName}/Outputs_Bayes_{modelName}_{case}" + directory = f"../{result_folder}/outputs_{modelName}/Outputs_"\ + f"Bayes_{modelName}_{case}" else: - directory = f"../{result_folder}/outputs_{modelName}/Outputs_Bayes_{modelName}-valid_{case}" + directory = f"../{result_folder}/outputs_{modelName}/Outputs_"\ + f"Bayes_{modelName}-valid_{case}" # Load Post pred file f = h5py.File(f"{directory}/postPredictive.hdf5", "r+") # Load PCEModel - with open(f"../{result_folder}/outputs_{modelName}/PCEModel_{modelName}.pkl", "rb") as input: + file_name = f"../{result_folder}/outputs_{modelName}/PCEModel_"\ + f"{modelName}.pkl" + with open(file_name, "rb") as input: PCEModel = joblib.load(input) if case == "Calib": @@ -111,12 +115,12 @@ def postPredictiveplot(modelNames, result_folder= ".", case="Calib", modelNames = ['stokesdarcyBJ', 'stokesdarcyER', 'stokespnm'] -inletLoc = 'top' # top or left -inclusion = 'squared' # squared or circular -path = "Results_09_01_2022_topInflow" +inletLoc = 'top' # top or left +inclusion = 'squared' # squared or circular +path = "Results_19_01_2022_topInflow" case = 'Valid' -allMeanPred, allStdPred = postPredictiveplot(modelNames, inclusion=inclusion, +allMeanPred, allStdPred = postPredictiveplot(modelNames, inclusion=inclusion, inletLoc=inletLoc, result_folder=path, case='Valid') diff --git a/BayesValidRox/tests/PA-A/util/sobol_indices.py b/BayesValidRox/tests/PA-A/util/sobol_indices.py index 120f6067922fc731a3cd066d8c2d57e1869ffc87..20387ed483c6bcb7308ac73c55a79ee085a9c269 100644 --- a/BayesValidRox/tests/PA-A/util/sobol_indices.py +++ b/BayesValidRox/tests/PA-A/util/sobol_indices.py @@ -10,10 +10,10 @@ import numpy as np import pandas as pd import matplotlib.pyplot as plt SIZE = 60 -plt.rc('figure', figsize = (24, 16)) +plt.rc('figure', figsize=(24,16)) plt.rc('font', family='serif', serif='Arial') plt.rc('font', size=SIZE) -plt.rc('axes', grid = True) +plt.rc('axes', grid=True) plt.rc('text', usetex=True) plt.rc('axes', linewidth=3) plt.rc('axes', grid=True) @@ -25,36 +25,45 @@ plt.rc('ytick', labelsize=SIZE) # fontsize of the tick labels plt.rc('legend', fontsize=SIZE) # legend fontsize plt.rc('figure', titlesize=SIZE) # fontsize of the figure title -result_dir = '../Results_20_09_2021/' -modelName = 'stokesdarcyER' #stokesdarcyBJ stokesdarcyER stokespnm +result_dir = '../Results_09_01_2022_topInflow/' + +inletLoc = "top" # top or left +inclusion = "squared" # squared or circular +Name = "stokesdarcyBJ" # stokesdarcyER stokesdarcyBJ stokespnm stokespnmNA +modelName = "ffpm-{}_{}_inclusion_{}Inflow".format(Name, inclusion, inletLoc) fig = plt.figure() xlabel = 'Point ID' -x_values = {'velocity [m_s]':[1,2,3,4,5,6,7,8,9,10], 'p': [1,2,3]} -outNames = ['velocity [m_s]','p'] +x_values = {'velocity [m_s]': np.arange(1, 11), 'p': np.arange(1, 4)} +outNames = ['velocity [m_s]', 'p'] for outIdx, Output in enumerate(outNames): - - delimiter = ';' if 'pnm' in modelName else ',' - - total_sobols = pd.read_csv(result_dir+'outputs_ffpm-{}/Outputs_PostProcessing_calib/totalsobol_{}.csv'.format(modelName,Output) - ,delimiter=delimiter) + + total_sobols = pd.read_csv(f'{result_dir}outputs_{modelName}/'\ + f'Outputs_PostProcessing_calib/totalsobol_'\ + f'{Output}.csv', + delimiter=',') total_sobol = total_sobols.to_numpy() - parNames = list(total_sobols.keys()) - - ax = fig.add_axes([0,0,1,1]) + parNames = list(total_sobols.keys()) + if '$K$' in parNames: + index = parNames.index('$K$') + parNames[index] = r"$\mathsf{K}$" + + ax = fig.add_axes([0, 0, 1, 1]) dict1 = {xlabel: x_values[Output]} - dict2 = {param: sobolIndices for param, sobolIndices in zip(parNames,total_sobol.T)} - + dict2 = {param: sobolIndices for param, sobolIndices in zip(parNames, + total_sobol.T)} + df = pd.DataFrame({**dict1, **dict2}) - df.plot(x=xlabel, y=parNames, kind="bar", ax=ax , rot=0, colormap='Dark2') + df.plot(x=xlabel, y=parNames, kind="bar", ax=ax, rot=0, colormap='Dark2', + edgecolor="black", lw=1) ax.set_ylabel('Total Sobol indices, $S^T$') # save the current figure - fig.savefig('Sobol_indices_{}_{}.pdf'.format(Output,modelName), bbox_inches='tight') - + fig.savefig(f'Sobol_indices_{Output}_{modelName}.pdf', bbox_inches='tight') + # Destroy the current plot plt.clf() diff --git a/configure.sh b/configure.sh index 3300074ea449907c2d3ab89d9087c6cdb75a6186..f482ea2289144316876f0082ebe6519a7175370a 100755 --- a/configure.sh +++ b/configure.sh @@ -14,5 +14,8 @@ python3 -m pip install tables==3.6.1 --upgrade --user python3 -m pip install corner==2.2.1 --user python3 -m pip install h5py==3.2.1 --user # python3 -m pip install vtk --user -sudo apt-get install python3-vtk7 python3 -m pip install meshio==5.0.0 --user + +# Here you need super user rights +sudo apt-get install python3-vtk7 +sudo apt-get install dvipng texlive-latex-extra texlive-fonts-recommended cm-super