1 from frictionImports
import *
2 if(
"-confidence" in sys.argv):
3 print(
"import confidence code")
6 except ImportError
as e:
7 print(
"Error when trying to import scipy.stats: ", e)
9 sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)) +
'/File')
10 from loadFromResults
import LoadFile
11 python_path = os.path.dirname(os.path.realpath(__file__))
13 colors_diverging_short = [
'#d7191c',
'#fdae61',
'#ffffbf',
'#abd9e9',
'#2c7bb6']
14 colors_diverging_long = [
'#a50026',
'#d73027',
'#f46d43',
'#fdae61',
'#fee090',
'#ffffbf',
'#e0f3f8',
'#abd9e9',
'#74add1',
'#4575b4',
'#313695']
15 colors_qualitative_short = [
'#1b9e77',
'#d95f02',
'#7570b3',
'#e7298a',
'#66a61e']
16 colors_qualitative_long = [
'#1b9e77',
'#d95f02',
'#7570b3',
'#e7298a',
'#66a61e',
'#e6ab02',
'#a6761d']
17 linestyles = [
'-',
'--',
'-.',
':']
23 yaml_file = LoadFile.loadYamlStandAlone(
"", python_path, path)
24 path_components = [unique_path_component
for unique_path_component
in (yaml_file[
"unique_path_components"])]
25 print(path_components)
26 paths_to_amplitude_files = [yaml_file[
"general_path"] + str(unique_path_component) +
"/" + yaml_file[
"result_path"] + yaml_file[
"file_name"]
for unique_path_component
in (yaml_file[
"unique_path_components"])]
28 paths_to_amplitude_files = np.loadtxt(python_path + path, delimiter =
"\n", dtype = bytes).astype(str)
29 print(paths_to_amplitude_files)
30 return (paths_to_amplitude_files, yaml_file)
37 if(isinstance(yaml_file, dict)):
38 if(yaml_key
in yaml_file.keys()):
39 return yaml_file[yaml_key]
41 print(
"Tried to add title from yaml file, but there was no \"" + yaml_key +
"\" key.")
50 if(suptitle
is not None):
51 plt.suptitle(suptitle)
56 yaml_key="unique_path_components"
59 if(labels
is not None):
64 yaml_key="label_title"
67 if(label_title
is not None):
77 if(
"-compare" in sys.argv):
78 colors = colors_qualitative_short
79 labels = [
'BK: seed 113.',
'BK: seed 114']
81 colors = colors_qualitative_long*len(amplitude_files)
83 for i
in range(0,len(amplitude_files)):
84 if(len(amplitude_files[i]) > 3):
85 plt.plot(amplitude_files[i][0], -amplitude_files[i][3], color = colors[i])
86 plt.errorbar(amplitude_files[i][0], amplitude_files[i][1], yerr=amplitude_files[i][2], ecolor=
'red', color=colors[i], label = labels[i], linestyle=linestyles[i%4])
87 if(
"-log" in sys.argv):
90 plt.xlabel(
"\$\\nu\$")
91 if(
"-dipregion" in sys.argv):
106 number_of_runs = str(amplitude_files.shape[0])
107 label =
"avg of " + number_of_runs +
" runs" 111 amplitude_files = np.average(amplitude_files, 0)
113 if(len(amplitude_files) > 3):
115 plt.plot(amplitude_files[0], -amplitude_files[3], color = color)
117 plt.errorbar(amplitude_files[0], amplitude_files[1], yerr=amplitude_files[2], ecolor=ecolor, label = label, color = color)
119 if(
"-log" in sys.argv):
123 plt.xlabel(
"\$\\nu\$")
128 if(
not "-notsave" in sys.argv):
129 input(
"Now you are saving, press enter to continue.")
130 np.savetxt(python_path +
"/../../../results" + path_to_save_folder +
"average_" + number_of_runs +
"_runs.csv", amplitude_files, delimiter =
',')
137 print(
"Calculating the difference between the first and consecutive amplitude files.")
138 print(amplitude_files.shape)
139 if(len(amplitude_files.shape) == 3):
140 colors = colors_qualitative_short*len(amplitude_files)
141 amplitudes = amplitude_files[:,1,:]
142 if(
"-averagecompare" in sys.argv):
143 compared_to_file = np.average(amplitudes, axis = 0)
144 print(compared_to_file)
147 compared_to_file = amplitudes[0]
150 for i
in range(start_iteration, len(amplitudes)):
151 difference = abs(amplitudes[i] - compared_to_file)
152 compared_list.append(difference)
154 compared_list = np.array(compared_list)
156 if(
"-saveinterval" in sys.argv):
157 scatterbar_x_values = [1/label
for label
in labels]
158 labels = [
"1/" + str(label)
for label
in labels]
159 scatterbar_x_label =
"\$Save frequency\$" 161 scatterbar_x_values = labels
162 scatterbar_x_label =
"\$Seed\$" 164 [plt.plot(amplitude_files[i,0,:],compared, label = labels[i], color = colors[i], linestyle=linestyles[i%4])
for i, compared
in enumerate(compared_list)]
165 plt.legend(title = label_title)
166 if(
"-log" in sys.argv):
168 plt.ylabel(
"\$Error\$")
169 plt.xlabel(
"\$\\nu\$")
172 [plt.plot(amplitude_files[i,0,:],np.cumsum(compared), label = labels[i], color = colors[i], linestyle=linestyles[i%4])
for i, compared
in enumerate(compared_list)]
173 plt.ylabel(
"\$ Cumulative Error\$")
174 plt.xlabel(
"\$\\nu\$")
175 plt.legend(title = label_title)
176 if(
"-log" in sys.argv):
182 compared_sum = np.sum(compared_list, 1)
185 plt.scatter(scatterbar_x_values, compared_sum, color = colors_diverging_short[0])
186 plt.bar(scatterbar_x_values, compared_sum, color = colors_diverging_short[0])
187 plt.plot(scatterbar_x_values, compared_sum, color = colors_diverging_short[1], linestyle = linestyles[1])
188 plt.ylabel(
"\$ Cumulative Error\$")
189 plt.xlabel(scatterbar_x_label)
194 plt.bar(np.arange(len(compared_sum)),np.sort(compared_sum))
197 plt.plot(amplitude_files[0,0,:],compared_to_file, color = colors_diverging_short[4], label =
"1/1")
199 plt.xlabel(
"\$\\nu\$")
200 plt.legend(title = label_title)
202 if(
"-log" in sys.argv):
211 label =
"BK-pad: 95\% CI, 16 runs" 212 color = colors_qualitative_short[3]
213 amplitudes = amplitude_files[:,1,:]
214 mean, standard_error = np.mean(amplitudes, axis=0), scipy.stats.sem(amplitudes)
215 print(amplitudes.shape)
216 height = standard_error * scipy.stats.t.ppf((1 + confidence) / 2., len(amplitudes)-1)
217 plt.plot(amplitude_files[0,0,:],mean, color = color, label = label)
218 plt.fill_between(amplitude_files[0,0,:], mean+height, mean-height, color = color, alpha=.5)
219 if(
"-log" in sys.argv):
222 plt.xlabel(
"\$\\nu\$")
237 if(
"-individual" in sys.argv):
240 if(
not "-compare" in sys.argv):
243 if(
"-saveinterval" or "-averagecompare" in sys.argv):
245 if(
"-confidence" in sys.argv):
256 amplitude_files = np.array([np.loadtxt(python_path +
"/../../../results/" + path, delimiter =
",")
for path
in paths])
260 def run(path_to_paths, path_to_save_folder):
264 if __name__ ==
"__main__":
265 run(sys.argv[1], sys.argv[2])
def getLabelsFromYaml(yaml_file, yaml_key="unique_path_components")
def plotAverageAmplitudes(amplitude_files, path_to_save_folder, yaml_file="")
def getYamlElement(yaml_file, yaml_key)
def plotIndividualAmplitudes(amplitude_files, yaml_file="")
def getLabelTitleFromYaml(yaml_file, yaml_key="label_title")
def run(path_to_paths, path_to_save_folder)
def mean_confidence_interval(amplitude_files, yaml_file, confidence=0.95)
def addTitleFromYaml(yaml_file, yaml_key="suptitle")
def calculateIntervalError(amplitude_files, yaml_file)
def getFileWithPaths(path)
def loadAmplitudeFiles(paths, path_to_save_folder, yaml_file)
def plotAmplitudeFiles(amplitude_files, path_to_save_folder, yaml_file)