In [1]:
import yaml
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
from electronfactors import c4, pull_data, calculate_percent_prediction_differences
In [2]:
def pull_data_edit(energy=12):
if energy == 12:
with open("model_cache/12MeV_10app_100ssd.yml", 'r') as file:
cutout_data = yaml.load(file)
label = np.array([key for key in cutout_data])
book_factor = np.array([item[0] == 'P' for i, item in enumerate(label)])
custom_label = label[~book_factor]
width = np.array([cutout_data[key]['width'] for key in custom_label])
length = np.array([cutout_data[key]['length'] for key in custom_label])
factor = np.array([cutout_data[key]['factor'] for key in custom_label])
perimeter = np.pi / 2 * (3*(width + length) - np.sqrt((3*width + length)*(3*length + width)))
area = np.pi / 4 * width * length
eqPonA = perimeter / area
else:
width, length, eqPonA, factor = pull_data(energy=energy)
return width, length, eqPonA, factor
In [3]:
def print_prediction_uncertainty(energy):
width, length, eqPonA, factor = pull_data_edit(energy=energy)
percent_prediction_differences = calculate_percent_prediction_differences(width, eqPonA, factor)
prediction_uncertainty = np.std(percent_prediction_differences, ddof=1) / c4(len(percent_prediction_differences))
mean = "%0.2f" %(np.mean(percent_prediction_differences))
uncertainty = "%0.2f" %(prediction_uncertainty)
total = "%0.1f" %(prediction_uncertainty + np.abs(np.mean(percent_prediction_differences)))
print('Percent prediction difference for ' + str(energy) + ' MeV is: ' + mean + ' +/- ' + uncertainty + ' --> '+total)
max_difference = np.max(np.abs(percent_prediction_differences))
print('Maximum difference is %0.2f%%' % (max_difference))
In [4]:
for i in [6, 9, 12, 15, 18]:
print_prediction_uncertainty(i)
In [ ]: