Skip to content

Commit

Permalink
metaplotter_pl_timescale: Import read_data() from metaplotter instead
Browse files Browse the repository at this point in the history
  • Loading branch information
rht committed Dec 5, 2018
1 parent cb35483 commit 135ee2a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 138 deletions.
53 changes: 27 additions & 26 deletions metaplotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
57 changes: 1 addition & 56 deletions metaplotter_pl_timescale.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
57 changes: 1 addition & 56 deletions metaplotter_pl_timescale_additional_measures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 135ee2a

Please sign in to comment.