From 135ee2ab9e26ab425ac1008c535ce51fce6f48dc Mon Sep 17 00:00:00 2001 From: rht Date: Wed, 5 Dec 2018 04:42:15 +0000 Subject: [PATCH] metaplotter_pl_timescale: Import read_data() from metaplotter instead --- metaplotter.py | 53 ++++++++--------- metaplotter_pl_timescale.py | 57 +------------------ ...lotter_pl_timescale_additional_measures.py | 57 +------------------ 3 files changed, 29 insertions(+), 138 deletions(-) diff --git a/metaplotter.py b/metaplotter.py index 775b55e..79b9cc6 100644 --- a/metaplotter.py +++ b/metaplotter.py @@ -128,32 +128,33 @@ def plotting(output_label, timeseries_dict, riskmodelsetting1, riskmodelsetting2 plt.savefig(outputfilename) plt.show() -timeseries = read_data() +if __name__ == "__main__": + timeseries = read_data() -# for just two different riskmodel settings -plotting(output_label="fig_contracts_survival_1_2", timeseries_dict=timeseries, riskmodelsetting1="one", \ - riskmodelsetting2="two", series1="contracts", series2="operational", plottype1="mean", plottype2="median") -plotting(output_label="fig_reinsurers_contracts_survival_1_2", timeseries_dict=timeseries, riskmodelsetting1="one", \ - riskmodelsetting2="two", series1="reincontracts", series2="reinoperational", plottype1="mean", plottype2="median") -plotting(output_label="fig_premium_1_2", timeseries_dict=timeseries, riskmodelsetting1="one", riskmodelsetting2="two", \ - series1="premium", series2=None, plottype1="mean", plottype2=None) + # for just two different riskmodel settings + plotting(output_label="fig_contracts_survival_1_2", timeseries_dict=timeseries, riskmodelsetting1="one", \ + riskmodelsetting2="two", series1="contracts", series2="operational", plottype1="mean", plottype2="median") + plotting(output_label="fig_reinsurers_contracts_survival_1_2", timeseries_dict=timeseries, riskmodelsetting1="one", \ + riskmodelsetting2="two", series1="reincontracts", series2="reinoperational", plottype1="mean", plottype2="median") + plotting(output_label="fig_premium_1_2", timeseries_dict=timeseries, riskmodelsetting1="one", riskmodelsetting2="two", \ + series1="premium", series2=None, plottype1="mean", plottype2=None) -raise SystemExit -# for four different riskmodel settings -plotting(output_label="fig_contracts_survival_1_2", timeseries_dict=timeseries, riskmodelsetting1="one", \ - riskmodelsetting2="two", series1="contracts", series2="operational", additionalriskmodelsetting3="three", \ - additionalriskmodelsetting4="four", plottype1="mean", plottype2="median") -plotting(output_label="fig_contracts_survival_3_4", timeseries_dict=timeseries, riskmodelsetting1="three", \ - riskmodelsetting2="four", series1="contracts", series2="operational", additionalriskmodelsetting3="one", \ - additionalriskmodelsetting4="two", plottype1="mean", plottype2="median") -plotting(output_label="fig_reinsurers_contracts_survival_1_2", timeseries_dict=timeseries, riskmodelsetting1="one", \ - riskmodelsetting2="two", series1="reincontracts", series2="reinoperational", \ - additionalriskmodelsetting3="three", additionalriskmodelsetting4="four", plottype1="mean", plottype2="median") -plotting(output_label="fig_reinsurers_contracts_survival_3_4", timeseries_dict=timeseries, riskmodelsetting1="three", \ - riskmodelsetting2="four", series1="reincontracts", series2="reinoperational", \ - additionalriskmodelsetting3="one", additionalriskmodelsetting4="two", plottype1="mean", plottype2="median") -plotting(output_label="fig_premium_1_2", timeseries_dict=timeseries, riskmodelsetting1="one", riskmodelsetting2="two", \ - series1="premium", series2=None, additionalriskmodelsetting3="three", additionalriskmodelsetting4="four", \ - plottype1="mean", plottype2=None) + raise SystemExit + # for four different riskmodel settings + plotting(output_label="fig_contracts_survival_1_2", timeseries_dict=timeseries, riskmodelsetting1="one", \ + riskmodelsetting2="two", series1="contracts", series2="operational", additionalriskmodelsetting3="three", \ + additionalriskmodelsetting4="four", plottype1="mean", plottype2="median") + plotting(output_label="fig_contracts_survival_3_4", timeseries_dict=timeseries, riskmodelsetting1="three", \ + riskmodelsetting2="four", series1="contracts", series2="operational", additionalriskmodelsetting3="one", \ + additionalriskmodelsetting4="two", plottype1="mean", plottype2="median") + plotting(output_label="fig_reinsurers_contracts_survival_1_2", timeseries_dict=timeseries, riskmodelsetting1="one", \ + riskmodelsetting2="two", series1="reincontracts", series2="reinoperational", \ + additionalriskmodelsetting3="three", additionalriskmodelsetting4="four", plottype1="mean", plottype2="median") + plotting(output_label="fig_reinsurers_contracts_survival_3_4", timeseries_dict=timeseries, riskmodelsetting1="three", \ + riskmodelsetting2="four", series1="reincontracts", series2="reinoperational", \ + additionalriskmodelsetting3="one", additionalriskmodelsetting4="two", plottype1="mean", plottype2="median") + plotting(output_label="fig_premium_1_2", timeseries_dict=timeseries, riskmodelsetting1="one", riskmodelsetting2="two", \ + series1="premium", series2=None, additionalriskmodelsetting3="three", additionalriskmodelsetting4="four", \ + plottype1="mean", plottype2=None) -#pdb.set_trace() + #pdb.set_trace() diff --git a/metaplotter_pl_timescale.py b/metaplotter_pl_timescale.py index d261d11..f76a8fa 100644 --- a/metaplotter_pl_timescale.py +++ b/metaplotter_pl_timescale.py @@ -5,63 +5,8 @@ import time import glob -def read_data(): - # do not overwrite old pdfs - #if os.path.exists("data/fig_one_and_two_rm_comp.pdf"): - # os.rename("data/fig_one_and_two_rm_comp.pdf", "data/fig_one_and_two_rm_comp_old_" + time.strftime('%Y_%b_%d_%H_%M') + ".pdf") - #if os.path.exists("data/fig_three_and_four_rm_comp.pdf"): - # os.rename("data/fig_three_and_four_rm_comp.pdf", "data/fig_three_and_four_rm_comp_old_" + time.strftime('%Y_%b_%d_%H_%M') + ".pdf") +from metaplotter import read_data - upper_bound = 75 - lower_bound = 25 - - timeseries_dict = {} - timeseries_dict["mean"] = {} - timeseries_dict["median"] = {} - timeseries_dict["quantile25"] = {} - timeseries_dict["quantile75"] = {} - - filenames_ones = glob.glob("data/one*.dat") - filenames_twos = glob.glob("data/two*.dat") - filenames_threes = glob.glob("data/three*.dat") - filenames_fours = glob.glob("data/four*.dat") - filenames_ones.sort() - filenames_twos.sort() - filenames_threes.sort() - filenames_fours.sort() - - #assert len(filenames_ones) == len(filenames_twos) == len(filenames_threes) == len(filenames_fours) - all_filenames = filenames_ones + filenames_twos + filenames_threes + filenames_fours - - for filename in all_filenames: - # read files - rfile = open(filename, "r") - data = [eval(k) for k in rfile] - rfile.close() - - # compute data series - data_means = [] - data_medians = [] - data_q25 = [] - data_q75 = [] - for i in range(len(data[0])): - data_means.append(np.mean([item[i] for item in data])) - data_q25.append(np.percentile([item[i] for item in data], lower_bound)) - data_q75.append(np.percentile([item[i] for item in data], upper_bound)) - data_medians.append(np.median([item[i] for item in data])) - data_means = np.array(data_means) - data_medians = np.array(data_medians) - data_q25 = np.array(data_q25) - data_q75 = np.array(data_q75) - - # record data series - timeseries_dict["mean"][filename] = data_means - timeseries_dict["median"][filename] = data_medians - timeseries_dict["quantile25"][filename] = data_q25 - timeseries_dict["quantile75"][filename] = data_q75 - return timeseries_dict - - def plotting(output_label, timeseries_dict, riskmodelsetting1, riskmodelsetting2, series1, series2=None, additionalriskmodelsetting3=None, additionalriskmodelsetting4=None, plottype1="mean", plottype2="mean"): # dictionaries diff --git a/metaplotter_pl_timescale_additional_measures.py b/metaplotter_pl_timescale_additional_measures.py index 5b0c449..1dcf511 100644 --- a/metaplotter_pl_timescale_additional_measures.py +++ b/metaplotter_pl_timescale_additional_measures.py @@ -5,63 +5,8 @@ import time import glob -def read_data(): - # do not overwrite old pdfs - #if os.path.exists("data/fig_one_and_two_rm_comp.pdf"): - # os.rename("data/fig_one_and_two_rm_comp.pdf", "data/fig_one_and_two_rm_comp_old_" + time.strftime('%Y_%b_%d_%H_%M') + ".pdf") - #if os.path.exists("data/fig_three_and_four_rm_comp.pdf"): - # os.rename("data/fig_three_and_four_rm_comp.pdf", "data/fig_three_and_four_rm_comp_old_" + time.strftime('%Y_%b_%d_%H_%M') + ".pdf") +from metaplotter import read_data - upper_bound = 75 - lower_bound = 25 - - timeseries_dict = {} - timeseries_dict["mean"] = {} - timeseries_dict["median"] = {} - timeseries_dict["quantile25"] = {} - timeseries_dict["quantile75"] = {} - - filenames_ones = glob.glob("data/one*.dat") - filenames_twos = glob.glob("data/two*.dat") - filenames_threes = glob.glob("data/three*.dat") - filenames_fours = glob.glob("data/four*.dat") - filenames_ones.sort() - filenames_twos.sort() - filenames_threes.sort() - filenames_fours.sort() - - #assert len(filenames_ones) == len(filenames_twos) == len(filenames_threes) == len(filenames_fours) - all_filenames = filenames_ones + filenames_twos + filenames_threes + filenames_fours - - for filename in all_filenames: - # read files - rfile = open(filename, "r") - data = [eval(k) for k in rfile] - rfile.close() - - # compute data series - data_means = [] - data_medians = [] - data_q25 = [] - data_q75 = [] - for i in range(len(data[0])): - data_means.append(np.mean([item[i] for item in data])) - data_q25.append(np.percentile([item[i] for item in data], lower_bound)) - data_q75.append(np.percentile([item[i] for item in data], upper_bound)) - data_medians.append(np.median([item[i] for item in data])) - data_means = np.array(data_means) - data_medians = np.array(data_medians) - data_q25 = np.array(data_q25) - data_q75 = np.array(data_q75) - - # record data series - timeseries_dict["mean"][filename] = data_means - timeseries_dict["median"][filename] = data_medians - timeseries_dict["quantile25"][filename] = data_q25 - timeseries_dict["quantile75"][filename] = data_q75 - return timeseries_dict - - def plotting(output_label, timeseries_dict, riskmodelsetting1, riskmodelsetting2, series1, series2=None, additionalriskmodelsetting3=None, additionalriskmodelsetting4=None, plottype1="mean", plottype2="mean"): # dictionaries