Commit acc7f9b0 authored by Pablo Iturrieta Rebolledo's avatar Pablo Iturrieta Rebolledo
Browse files

modified t-test

creates code to combine all results
modified meletti to remove negative raets
parent 4a21fd4a
......@@ -2,7 +2,7 @@
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="jdk" jdkName="Python 3.8 (venv)" jdkType="Python SDK" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TestRunnerService">
......
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8 (venv)" project-jdk-type="Python SDK" />
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7 (venv)" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
......@@ -65,7 +65,7 @@ def plot_single_results(Results, Forecasts, years, ref_model=0,savepath=False):
'linewidth': 1.5,
'capsize': 0,
'markersize': 6,
'ylims': (-12,4)}
'ylims': (-2,2)}
T_Results_per_model = Results[0][ref_model*len(Forecasts):(ref_model+1)*(len(Forecasts))]
......@@ -171,8 +171,8 @@ if __name__ =='__main__':
Models10 = get_models.get_models_10yr()
cat10 = get_catalogs.filter_10yr_01_2010(get_catalogs.buolletino())
Results5 = process_forecasts_batch(Models5, cat5, load_obj=filepaths.test_path['TW_5'])
Results10 = process_forecasts_batch(Models10, cat10, load_obj=filepaths.test_path['TW_10'])
Results5 = process_forecasts_batch(Models5, cat5, save_obj=filepaths.test_path['TW_5'])
Results10 = process_forecasts_batch(Models10, cat10, save_obj=filepaths.test_path['TW_10'])
tw_figs_path = os.path.join(filepaths.csep_figs, 'tw_tests')
......@@ -188,3 +188,5 @@ if __name__ =='__main__':
a = plot_all_results(Results10, Models10, years=10, order=True, savepath=filepaths.csep_figs)
......@@ -4,7 +4,6 @@ import pickle
import xml.etree.ElementTree as et
import numpy as np
import ntpath
import copy
from codes import filepaths
......
......@@ -2,8 +2,86 @@
from codes import get_catalogs, get_models, filepaths
import pickle
import itertools
import matplotlib.pyplot as plt
import numpy as np
def get_results(years):
results = {key : pickle.load(open(item, 'rb')) for key,item in filepaths.test_path.items()}
return results
results = get_results(5)
get_results(5)
n_results = 3
n_models = 19
### Absolute values plot
def norm(array):
return (array - array.min())/(array.max() -array.min())
## T_score
T = np.array([i.observed_statistic for i in results['TW_5'][0]]).reshape((n_models, n_models)).T
t_score = np.sum(T, axis=1) / T.shape[0]
min_val = - 1
t_score[t_score < min_val ] = min_val
## PGS
pgs = np.array([i.test_distribution[0] for i in results['PGS_5']])
## Conditional Likelihood
cl_score = np.array([i.quantile for i in results['CL_5']])
## Names and order
names = [i.sim_name for i in results['CL_5']]
order = np.flip(np.argsort(norm(cl_score)+norm(pgs)+norm(t_score)))
pgs = pgs[order]
cl_score = cl_score[order]
t_score = t_score[order]
names = [names[i] for i in order]
labels = []
for i in names:
labels.extend(['', i, ''])
## Complete array
score_total = np.vstack((norm(t_score), norm(pgs), norm(cl_score))).T.ravel()
theta = np.linspace(0.0, 2 * np.pi, n_results * n_models, endpoint=False)
## Colors
colors_t = np.array([plt.cm.colors.to_rgb('orangered') for i in range(n_models)])
colors_pgs = np.array([plt.cm.colors.to_rgb('turquoise') for i in range(n_models)])
colors_cl = [plt.cm.colors.to_rgb('steelblue') for i in range(n_models)]
colors = np.hstack((colors_t, colors_pgs, colors_cl)).reshape((n_models*n_results,3))
width = 0.115
# fig = plt.figure(figsize=(8,8))
ax = plt.subplot(111,projection='polar')
fig = ax.get_figure()
fig.set_size_inches(8, 8)
# ax.bar(np.linspace(0.0, 2 * np.pi, n_models, endpoint=False), [i%2 for i in range(n_models)], width=0.33, color='grey', alpha=0.5, tick_label=names)
# edges
ax.grid(False)
ax.get_yaxis().grid([0, 0.4, 0.7], zorder=0, label=False)
# ax.get_yaxis().set_ticks([])
for i in np.linspace(0.0, 2 * np.pi, n_models , endpoint=False):
ax.plot([i ,i - 3*width*np.pi/n_models],[0, 1.], color='grey', linewidth=0.5)
ax.bar(theta, score_total, width=width, bottom=0, color=colors, alpha=1, zorder=2)
ax.set_ylim([0,1])
ax.get_xaxis().set_ticks(np.linspace(0.0, 2 * np.pi, n_models, endpoint=False) + width)
ax.get_xaxis().set_ticklabels(names)
ax.tick_params(axis='x', which='major', pad=20)
ax.get_xticks()
#
# ax.get_xaxis().set_linewidth(2)
# ax.yaxis.grid( linewidth = 5)
# ax.yaxis.(2)
# plt.thetagrids(np.linspace(0, 360, 2))
# ax.grid( zorder=1)
plt.show()
# ref_model = 11
# t_score = T[ref_model*n_models:(ref_model+1)*n_models]
......@@ -295124,7 +295124,7 @@
<bin m='5.0'>0.37E-02</bin>
<bin m='5.1'>0.28E-02</bin>
<bin m='5.2'>0.44E-02</bin>
<bin m='5.3'>-.80E-03</bin>
<bin m='5.3'>0.80E-03</bin>
<bin m='5.4'>0.12E-02</bin>
<bin m='5.5'>0.33E-02</bin>
<bin m='5.6'>0.00E+00</bin>
......@@ -295167,7 +295167,7 @@
<bin m='5.0'>0.37E-02</bin>
<bin m='5.1'>0.28E-02</bin>
<bin m='5.2'>0.44E-02</bin>
<bin m='5.3'>-.80E-03</bin>
<bin m='5.3'>0.80E-03</bin>
<bin m='5.4'>0.12E-02</bin>
<bin m='5.5'>0.33E-02</bin>
<bin m='5.6'>0.00E+00</bin>
......@@ -299424,7 +299424,7 @@
<bin m='5.0'>0.37E-02</bin>
<bin m='5.1'>0.28E-02</bin>
<bin m='5.2'>0.44E-02</bin>
<bin m='5.3'>-.80E-03</bin>
<bin m='5.3'>0.80E-03</bin>
<bin m='5.4'>0.12E-02</bin>
<bin m='5.5'>0.33E-02</bin>
<bin m='5.6'>0.00E+00</bin>
......@@ -299467,7 +299467,7 @@
<bin m='5.0'>0.37E-02</bin>
<bin m='5.1'>0.28E-02</bin>
<bin m='5.2'>0.44E-02</bin>
<bin m='5.3'>-.80E-03</bin>
<bin m='5.3'>0.80E-03</bin>
<bin m='5.4'>0.12E-02</bin>
<bin m='5.5'>0.33E-02</bin>
<bin m='5.6'>0.00E+00</bin>
......@@ -302821,7 +302821,7 @@
<bin m='5.0'>0.37E-02</bin>
<bin m='5.1'>0.28E-02</bin>
<bin m='5.2'>0.44E-02</bin>
<bin m='5.3'>-.80E-03</bin>
<bin m='5.3'>0.80E-03</bin>
<bin m='5.4'>0.12E-02</bin>
<bin m='5.5'>0.33E-02</bin>
<bin m='5.6'>0.00E+00</bin>
......@@ -302864,7 +302864,7 @@
<bin m='5.0'>0.37E-02</bin>
<bin m='5.1'>0.28E-02</bin>
<bin m='5.2'>0.44E-02</bin>
<bin m='5.3'>-.80E-03</bin>
<bin m='5.3'>0.80E-03</bin>
<bin m='5.4'>0.12E-02</bin>
<bin m='5.5'>0.33E-02</bin>
<bin m='5.6'>0.00E+00</bin>
......@@ -295124,7 +295124,7 @@
<bin m='5.0'>0.46E-02</bin>
<bin m='5.1'>0.34E-02</bin>
<bin m='5.2'>0.54E-02</bin>
<bin m='5.3'>-.10E-02</bin>
<bin m='5.3'>0.10E-02</bin>
<bin m='5.4'>0.15E-02</bin>
<bin m='5.5'>0.41E-02</bin>
<bin m='5.6'>0.00E+00</bin>
......@@ -295167,7 +295167,7 @@
<bin m='5.0'>0.46E-02</bin>
<bin m='5.1'>0.34E-02</bin>
<bin m='5.2'>0.54E-02</bin>
<bin m='5.3'>-.99E-03</bin>
<bin m='5.3'>0.99E-03</bin>
<bin m='5.4'>0.15E-02</bin>
<bin m='5.5'>0.41E-02</bin>
<bin m='5.6'>0.00E+00</bin>
......@@ -299424,7 +299424,7 @@
<bin m='5.0'>0.46E-02</bin>
<bin m='5.1'>0.34E-02</bin>
<bin m='5.2'>0.54E-02</bin>
<bin m='5.3'>-.10E-02</bin>
<bin m='5.3'>0.10E-02</bin>
<bin m='5.4'>0.15E-02</bin>
<bin m='5.5'>0.41E-02</bin>
<bin m='5.6'>0.00E+00</bin>
......@@ -299467,7 +299467,7 @@
<bin m='5.0'>0.46E-02</bin>
<bin m='5.1'>0.34E-02</bin>
<bin m='5.2'>0.54E-02</bin>
<bin m='5.3'>-.99E-03</bin>
<bin m='5.3'>0.99E-03</bin>
<bin m='5.4'>0.15E-02</bin>
<bin m='5.5'>0.41E-02</bin>
<bin m='5.6'>0.00E+00</bin>
......@@ -302821,7 +302821,7 @@
<bin m='5.0'>0.46E-02</bin>
<bin m='5.1'>0.34E-02</bin>
<bin m='5.2'>0.54E-02</bin>
<bin m='5.3'>-.10E-02</bin>
<bin m='5.3'>0.10E-02</bin>
<bin m='5.4'>0.15E-02</bin>
<bin m='5.5'>0.41E-02</bin>
<bin m='5.6'>0.00E+00</bin>
......@@ -302864,7 +302864,7 @@
<bin m='5.0'>0.46E-02</bin>
<bin m='5.1'>0.34E-02</bin>
<bin m='5.2'>0.54E-02</bin>
<bin m='5.3'>-.99E-03</bin>
<bin m='5.3'>0.99E-03</bin>
<bin m='5.4'>0.15E-02</bin>
<bin m='5.5'>0.41E-02</bin>
<bin m='5.6'>0.00E+00</bin>
......@@ -295124,7 +295124,7 @@
<bin m='5.0'>0.74E-02</bin>
<bin m='5.1'>0.55E-02</bin>
<bin m='5.2'>0.87E-02</bin>
<bin m='5.3'>-.16E-02</bin>
<bin m='5.3'>0.16E-02</bin>
<bin m='5.4'>0.24E-02</bin>
<bin m='5.5'>0.66E-02</bin>
<bin m='5.6'>0.00E+00</bin>
......@@ -295167,7 +295167,7 @@
<bin m='5.0'>0.74E-02</bin>
<bin m='5.1'>0.55E-02</bin>
<bin m='5.2'>0.87E-02</bin>
<bin m='5.3'>-.16E-02</bin>
<bin m='5.3'>0.16E-02</bin>
<bin m='5.4'>0.24E-02</bin>
<bin m='5.5'>0.66E-02</bin>
<bin m='5.6'>0.00E+00</bin>
......@@ -299424,7 +299424,7 @@
<bin m='5.0'>0.74E-02</bin>
<bin m='5.1'>0.55E-02</bin>
<bin m='5.2'>0.87E-02</bin>
<bin m='5.3'>-.16E-02</bin>
<bin m='5.3'>0.16E-02</bin>
<bin m='5.4'>0.24E-02</bin>
<bin m='5.5'>0.66E-02</bin>
<bin m='5.6'>0.00E+00</bin>
......@@ -299467,7 +299467,7 @@
<bin m='5.0'>0.74E-02</bin>
<bin m='5.1'>0.55E-02</bin>
<bin m='5.2'>0.87E-02</bin>
<bin m='5.3'>-.16E-02</bin>
<bin m='5.3'>0.16E-02</bin>
<bin m='5.4'>0.24E-02</bin>
<bin m='5.5'>0.66E-02</bin>
<bin m='5.6'>0.00E+00</bin>
......@@ -302821,7 +302821,7 @@
<bin m='5.0'>0.74E-02</bin>
<bin m='5.1'>0.55E-02</bin>
<bin m='5.2'>0.87E-02</bin>
<bin m='5.3'>-.16E-02</bin>
<bin m='5.3'>0.16E-02</bin>
<bin m='5.4'>0.24E-02</bin>
<bin m='5.5'>0.66E-02</bin>
<bin m='5.6'>0.00E+00</bin>
......@@ -302864,7 +302864,7 @@
<bin m='5.0'>0.74E-02</bin>
<bin m='5.1'>0.55E-02</bin>
<bin m='5.2'>0.87E-02</bin>
<bin m='5.3'>-.16E-02</bin>
<bin m='5.3'>0.16E-02</bin>
<bin m='5.4'>0.24E-02</bin>
<bin m='5.5'>0.66E-02</bin>
<bin m='5.6'>0.00E+00</bin>
......@@ -295124,7 +295124,7 @@
<bin m='5.0'>0.92E-02</bin>
<bin m='5.1'>0.69E-02</bin>
<bin m='5.2'>0.11E-01</bin>
<bin m='5.3'>-.20E-02</bin>
<bin m='5.3'>0.20E-02</bin>
<bin m='5.4'>0.29E-02</bin>
<bin m='5.5'>0.82E-02</bin>
<bin m='5.6'>0.00E+00</bin>
......@@ -295167,7 +295167,7 @@
<bin m='5.0'>0.92E-02</bin>
<bin m='5.1'>0.69E-02</bin>
<bin m='5.2'>0.11E-01</bin>
<bin m='5.3'>-.20E-02</bin>
<bin m='5.3'>0.20E-02</bin>
<bin m='5.4'>0.29E-02</bin>
<bin m='5.5'>0.82E-02</bin>
<bin m='5.6'>0.00E+00</bin>
......@@ -299424,7 +299424,7 @@
<bin m='5.0'>0.92E-02</bin>
<bin m='5.1'>0.69E-02</bin>
<bin m='5.2'>0.11E-01</bin>
<bin m='5.3'>-.20E-02</bin>
<bin m='5.3'>0.20E-02</bin>
<bin m='5.4'>0.29E-02</bin>
<bin m='5.5'>0.82E-02</bin>
<bin m='5.6'>0.00E+00</bin>
......@@ -299467,7 +299467,7 @@
<bin m='5.0'>0.92E-02</bin>
<bin m='5.1'>0.69E-02</bin>
<bin m='5.2'>0.11E-01</bin>
<bin m='5.3'>-.20E-02</bin>
<bin m='5.3'>0.20E-02</bin>
<bin m='5.4'>0.29E-02</bin>
<bin m='5.5'>0.82E-02</bin>
<bin m='5.6'>0.00E+00</bin>
......@@ -302821,7 +302821,7 @@
<bin m='5.0'>0.92E-02</bin>
<bin m='5.1'>0.69E-02</bin>
<bin m='5.2'>0.11E-01</bin>
<bin m='5.3'>-.20E-02</bin>
<bin m='5.3'>0.20E-02</bin>
<bin m='5.4'>0.29E-02</bin>
<bin m='5.5'>0.82E-02</bin>
<bin m='5.6'>0.00E+00</bin>
......@@ -302864,7 +302864,7 @@
<bin m='5.0'>0.92E-02</bin>
<bin m='5.1'>0.69E-02</bin>
<bin m='5.2'>0.11E-01</bin>
<bin m='5.3'>-.20E-02</bin>
<bin m='5.3'>0.20E-02</bin>
<bin m='5.4'>0.29E-02</bin>
<bin m='5.5'>0.82E-02</bin>
<bin m='5.6'>0.00E+00</bin>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment