480 KiB
480 KiB
In [13]:
import numpy as np
import pandas as pdIn [14]:
import matplotlib.pyplot as plt
%matplotlib inline
import seaborn as sns
NEJM = sns.color_palette(palette = ['#bc3c29',
'#0072bf',
'#e18727',
'#20854e',
'#7876b1',
'#6f99ad',
'#ffdc91',
'#ee4c97'])
sns.set(
context='paper',
style='white',
palette=NEJM,
font='sans-serif',
font_scale=1,
color_codes=False,
rc = {'figure.dpi' : 100,
'text.usetex' : True,
'axes.labelsize' : 10,
'xtick.labelsize' : 10,
'ytick.labelsize' : 10,
'legend.fontsize' : 10,
'xtick.bottom' : True,
'xtick.minor.bottom' : False,
'ytick.left' : True,
'ytick.minor.left' : False
})In [15]:
me_eV = 0.511e6
decay_constant = 1.2072343416696292e-47
end_point_eV = 18.574e3
Z = 2
normation = 1.2077979152375112e-24
Ue1 = 0.82
Ue2 = 0.55
Ue3 = 0.145
def beta_dist_mass(E_eV, mnue_eV):
if E_eV > (end_point_eV-mnue_eV):
return 0.
if E_eV <= 0:
return 0.
gamma = 1+E_eV/me_eV
beta = np.sqrt(1 - pow(gamma,-2))
eta =Z/beta/137.
fermi_function = 2*np.pi*eta/(1-np.exp(-2*np.pi*eta));
p_eV = np.sqrt(E_eV*E_eV + 2 * E_eV * me_eV)
sqrtterm = np.sqrt(pow(end_point_eV-E_eV,2) - mnue_eV**2)
return decay_constant*fermi_function*p_eV*(E_eV+me_eV)*(end_point_eV-E_eV)*sqrtterm/normation
beta_dist_mass = np.vectorize(beta_dist_mass, otypes=[np.float])In [16]:
import scipy.integrate as integrate
integrate.quad(lambda x: beta_dist_mass(x,0), 0, 18600)Out [16]:
(0.9999953594383194, 4.5886555080029095e-09)
In [17]:
from scipy.optimize import curve_fit
from scipy.stats import chisquare
def beta(E, C, pot):
return C*beta_dist_mass(E, 0)*pow(E, pot)
beta = np.vectorize(beta, otypes=[np.float])
kb = 8.6173303e-5
def MB(E, T, C, pot):
return C*2*np.sqrt(E/np.pi) * pow(kb*T, -3/2) * np.exp(-E/kb/T) * pow(E, pot)
MB = np.vectorize(MB, otypes=[np.float])In [18]:
df = pd.read_csv('df_export.csv') # Spectrum from Simulation
zref = 5In [19]:
fig, ax = plt.subplots()
df_plot = df[(df['z']== -1) | (df['z']== 5) | (df['z']== 10)]
sns.lineplot(ax = ax, x="Emid", y="dndE", style = 'z', hue = 'z', data=df_plot, err_style=None, legend = 'full')
ax.set_xscale('log')
ax.set_yscale('log')
ax.set_xlabel ('electron energy (eV)')
ax.set_ylabel (r'differential density dn/dE (m$^{-3}$ eV$^{-1}$)')
ax.plot()Out [19]:
[]
In [20]:
fig, ax = plt.subplots()
df_plot = df[(df['z']== -1) | (df['z']== 5) | (df['z']== 10)]
sns.lineplot(ax = ax, x="Emid", y="djzdE", style = 'z', hue = 'z', data=df_plot, err_style=None, legend = 'full')
ax.set_xscale('log')
ax.set_yscale('log')
ax.set_xlabel ('electron energy (eV)')
ax.set_ylabel (r'differential z-current dj$_z$/dE (m$^{-2}$s$^{-1}$ eV$^{-1}$)')
ax.plot()Out [20]:
[]
In [21]:
df_temp = df[df.Emid > 1e3]
df_temp = df_temp[df_temp.z == zref]
E = df_temp.Emid
N = df_temp.dndE
popt, pcov = curve_fit(beta, E, N, p0 = [1e3, 1])
fig, ax = plt.subplots()
ax.plot(E, N, 'x', label = 'data')
ax.plot(E, beta(E, *popt), label = 'fit')
ax.set_xscale('log')
ax.set_yscale('log')
ax.set_xlabel ('electron energy (eV)')
ax.set_ylabel (r'differential density dn/dE (m$^{-3}$ eV$^{-1}$)')
ax.legend()
ax.plot()
print("Fit of dn/dE to beta spectrum")
print("Normation:\t" + str(popt[0]))
print("E_power:\t" + str(popt[1]))
print (chisquare(N, f_exp=beta(E, *popt), ddof = 2))Fit of dn/dE to beta spectrum Normation: 20154720.782272294 E_power: -0.41528740723102 Power_divergenceResult(statistic=10.7059835723772, pvalue=0.4682136431084959)
In [33]:
df_temp = df[df.Emid > 1e3]
df_temp = df_temp[df_temp.z == zref]
E = df_temp.Emid
N = df_temp.dndE
popt, pcov = curve_fit(lambda E, C: beta(E, C, -0.5), E, N, p0 = [1e3])
fig, ax = plt.subplots()
ax.plot(E, N, 'x', label = 'data')
ax.plot(E, beta(E, *popt, -0.5), label = 'fit')
ax.set_xscale('log')
ax.set_yscale('log')
ax.set_xlabel ('electron energy (eV)')
ax.set_ylabel (r'differential density dn/dE (m$^{-3}$ eV$^{-1}$)')
ax.legend()
ax.plot()
print("Fit of dn/dE to beta spectrum with fixed E power")
print("Normation:\t" + str(popt[0]))
print("E_power:\t-0.5(fixed)")
print (chisquare(N, f_exp=beta(E, *popt, -0.5), ddof = 1))Fit of dn/dE to beta spectrum Normation: 38435378.76392215 E_power: -0.5(fixed) Power_divergenceResult(statistic=11.815419509822563, pvalue=0.4606152069365941)
In [22]:
df_temp = df[df.Emid < 1e-2]
df_temp = df_temp[df_temp.z == zref]
E = df_temp.Emid
N = df_temp.dndE
popt, pcov = curve_fit(MB, E, N, p0 = [30, 1e15, -1])
fig, ax = plt.subplots()
ax.plot(E, N, 'x', label = 'data')
ax.plot(E, MB(E, *popt), label = 'fit')
ax.set_xscale('log')
ax.set_yscale('log')
ax.set_xlabel ('electron energy (eV)')
ax.set_ylabel (r'differential density dn/dE (m$^{-3}$ eV$^{-1}$)')
ax.legend()
#ax.title('dndE to beta-spektrum')
ax.plot()
print("Fit of dn/dE to MB")
print("Temperature:\t" + str(popt[0]))
print("Normation:\t" + str(popt[1]))
print("E_power:\t" + str(popt[2]))
print (chisquare(N, f_exp=MB(E, *popt), ddof = 3))Fit of dn/dE to MB Temperature: 28.98547538917832 Normation: 92153838826.18001 E_power: -0.6298872861537869 Power_divergenceResult(statistic=4184827864608.701, pvalue=0.0)
In [36]:
df_temp = df[df.Emid < 1e-2]
df_temp = df_temp[df_temp.z == zref]
E = df_temp.Emid
N = df_temp.dndE
popt, pcov = curve_fit(lambda E, T, C: MB(E, T, C, -0.5), E, N, p0 = [30, 1e15])
fig, ax = plt.subplots()
ax.plot(E, N, 'x', label = 'data')
ax.plot(E, MB(E, *popt, -0.5), label = 'fit')
ax.set_xscale('log')
ax.set_yscale('log')
ax.set_xlabel ('electron energy (eV)')
ax.set_ylabel (r'differential density dn/dE (m$^{-3}$ eV$^{-1}$)')
ax.legend()
#ax.title('dndE to beta-spektrum')
ax.plot()
print("Fit of dn/dE to MB")
print("Temperature:\t" + str(popt[0]))
print("Normation:\t" + str(popt[1]))
print("E_power:\t-0.5 (fixed)")
print (chisquare(N, f_exp=MB(E, *popt, -0.5), ddof = 2))Fit of dn/dE to MB Temperature: 13.510795772133825 Normation: 109828736080.87285 E_power: -0.5 (fixed) Power_divergenceResult(statistic=5963595967273500.0, pvalue=0.0)
In [ ]:
df_temp = df[df.Emid < 1e-2]
df_temp = df_temp[df_temp.z == zref]
E = df_temp.Emid
N = df_temp.dndE
popt, pcov = curve_fit(lambda E, T, C: MB(E, T, C, 0), E, N, p0 = [30, 1e15])
fig, ax = plt.subplots()
ax.plot(E, N, 'x', label = 'data')
ax.plot(E, MB(E, *popt, 0), label = 'fit')
ax.set_xscale('log')
ax.set_yscale('log')
ax.set_xlabel ('electron energy (eV)')
ax.set_ylabel (r'differential density dn/dE (m$^{-3}$ eV$^{-1}$)')
ax.legend()
#ax.title('dndE to beta-spektrum')
ax.plot()
print("Fit of dn/dE to MB")
print("Temperature:\t" + str(popt[0]))
print("Normation:\t" + str(popt[1]))
print("E_power:\t0 (fixed)")
print (chisquare(N, f_exp=MB(E, *popt, 0), ddof = 2))In [23]:
df_temp = df[df.Emid > 1e3]
df_temp = df_temp[df_temp.z == zref]
E = df_temp.Emid
N = df_temp.djzdE
popt, pcov = curve_fit(beta, E, N, p0 = [1e3, 1])
fig, ax = plt.subplots()
ax.plot(E, N, 'x', label = 'data')
ax.plot(E, beta(E, *popt), label = 'fit')
ax.set_xscale('log')
ax.set_yscale('log')
ax.set_xlabel ('electron energy (eV)')
ax.set_ylabel (r'differential z-current dj$_z$/dE (m$^{-2}$s$^{-1}$ eV$^{-1}$)')
ax.legend()
ax.plot()
print("Fit of djz/dE to beta spectrum")
print("Normation:\t" + str(popt[0]))
print("E_power:\t" + str(popt[1]))
print (chisquare(N, f_exp=beta(E, *popt), ddof = 2))Fit of djz/dE to beta spectrum Normation: 0.32089465069604106 E_power: 0.00681951085898797 Power_divergenceResult(statistic=1.193217000063417e-06, pvalue=1.0)
In [35]:
df_temp = df[df.Emid > 1e3]
df_temp = df_temp[df_temp.z == zref]
E = df_temp.Emid
N = df_temp.djzdE
popt, pcov = curve_fit(lambda E, C: beta(E, C, 0), E, N, p0 = [1e3])
fig, ax = plt.subplots()
ax.plot(E, N, 'x', label = 'data')
ax.plot(E, beta(E, *popt, 0), label = 'fit')
ax.set_xscale('log')
ax.set_yscale('log')
ax.set_xlabel ('electron energy (eV)')
ax.set_ylabel (r'differential density dn/dE (m$^{-3}$ eV$^{-1}$)')
ax.legend()
ax.plot()
print("Fit of dn/dE to beta spectrum with fixed E power")
print("Normation:\t" + str(popt[0]))
print("E_power:\t0(fixed)")
print (chisquare(N, f_exp=beta(E, *popt, 0), ddof = 1))Fit of dn/dE to beta spectrum with fixed E power Normation: 0.33877960828511666 E_power: 0(fixed) Power_divergenceResult(statistic=1.1914996763581592e-06, pvalue=1.0)
In [24]:
df_temp = df[df.Emid < 1e-2]
df_temp = df_temp[df_temp.z == zref]
E = df_temp.Emid
N = df_temp.djzdE
popt, pcov = curve_fit(MB, E, N, p0 = [30, 1e14, -1])
fig, ax = plt.subplots()
ax.plot(E, N, 'x', label = 'data')
ax.plot(E, MB(E, *popt), label = 'fit')
ax.set_xscale('log')
ax.set_yscale('log')
ax.set_xlabel ('electron energy (eV)')
ax.set_ylabel (r'differential z-current dj$_z$/dE (m$^{-2}$s$^{-1}$ eV$^{-1}$)')
ax.legend()
ax.plot()
print("Fit of djz/dE to MB")
print("Temperature:\t" + str(popt[0]))
print("Normation:\t" + str(popt[1]))
print("E_power:\t" + str(popt[2]))
print (chisquare(N, f_exp=MB(E, *popt), ddof = 3))Fit of djz/dE to MB Temperature: 29.434200618182242 Normation: 839.7009624153503 E_power: -0.13391935102392205 Power_divergenceResult(statistic=352.1128563884243, pvalue=9.374829123871076e-58)
In [40]:
df_temp = df[df.Emid < 1e-2]
df_temp = df_temp[df_temp.z == zref]
E = df_temp.Emid
N = df_temp.djzdE
popt, pcov = curve_fit(lambda E, T, C: MB(E, T, C, 0), E, N, p0 = [30, 1e14])
fig, ax = plt.subplots()
ax.plot(E, N, 'x', label = 'data')
ax.plot(E, MB(E, *popt, 0), label = 'fit')
ax.set_xscale('log')
ax.set_yscale('log')
ax.set_xlabel ('electron energy (eV)')
ax.set_ylabel (r'differential z-current dj$_z$/dE (m$^{-2}$s$^{-1}$ eV$^{-1}$)')
ax.legend()
ax.plot()
print("Fit of djz/dE to MB")
print("Temperature:\t" + str(popt[0]))
print("Normation:\t" + str(popt[1]))
print("E_power:\t0 (fixed)")
print (chisquare(N, f_exp=MB(E, *popt, 0), ddof = 2))Fit of djz/dE to MB Temperature: 21.887669754061047 Normation: 1678.7558592328005 E_power: 0 (fixed) Power_divergenceResult(statistic=194534.14787687804, pvalue=0.0)
In [25]:
df_fer = pd.read_csv('reseedfrecomb.txt', header=None, delim_whitespace=True)
df_fer.columns = ['E_pot', 'N_pot']
df_fer['E'] = pow(10, df_fer.E_pot[:-1])
df_fer['N'] = pow(10, df_fer.N_pot[:-1])/df_fer['E']In [26]:
fig, ax = plt.subplots()
ax.plot(df_fer['E'], df_fer['N'])
ax.set_xscale('log')
ax.set_yscale('log')
ax.plot()Out [26]:
[]
In [27]:
df_temp = df_fer[df_fer.E < 1e-2]
E = df_temp['E'][1:]
N = df_temp['N'][1:]
popt, pcov = curve_fit(MB, E, N, p0 = [30, 1e0, -1])
fig, ax = plt.subplots()
ax.plot(E, N, 'x', label = 'data')
ax.plot(E, MB(E, *popt), label = 'fit')
ax.set_xscale('log')
ax.set_yscale('log')
ax.set_xlabel ('electron energy (eV)')
ax.set_ylabel (r'differential density djz/dE (s$^{-1}$ m$^{-2}$ eV$^{-1}$)')
ax.legend()
ax.plot()
print("Fit of MB to data from Ferenc, 3 degrees of freedom")
print("Temperature:\t" + str(popt[0]))
print("Normation:\t" + str(popt[1]))
print("E_power:\t" + str(popt[2]))
print (chisquare(N, f_exp=MB(E, *popt), ddof = 3))Fit of MB to data from Ferenc, 3 degrees of freedom Temperature: 31.58872622189486 Normation: 0.021502239795322436 E_power: -0.3575306769913827 Power_divergenceResult(statistic=0.11038308663579258, pvalue=1.0)
In [28]:
df_temp = df_fer[df_fer.E < 1e-2]
E = df_temp['E'][1:]
N = df_temp['N'][1:]
popt, pcov = curve_fit((lambda E, T, n: MB(E, T, n, 0)), E, N, p0 = [30, 1e-8])
fig, ax = plt.subplots()
ax.plot(E, N, 'x', label = 'data')
ax.plot(E, MB(E, *popt, 0), label = 'fit')
ax.set_xscale('log')
ax.set_yscale('log')
ax.set_xlabel ('electron energy (eV)')
ax.set_ylabel (r'differential density djz/dE (s$^{-1}$ m$^{-2}$ eV$^{-1}$)')
ax.legend()
ax.plot()
print("Fit of MB to data from Ferenc, 2 degrees of freedom")
print("Temperature:\t" + str(popt[0]))
print("Normation:\t" + str(popt[1]))
print("E_power:\t0(fixed)")
print (chisquare(N, f_exp=MB(E, *popt, 0), ddof = 2))/usr/local/lib/python3.7/site-packages/numpy/lib/function_base.py:2170: ComplexWarning: Casting complex values to real discards the imaginary part res = array(outputs, copy=False, subok=True, dtype=otypes[0])
Fit of MB to data from Ferenc, 2 degrees of freedom Temperature: 15.766044987384202 Normation: 0.1470484035417699 E_power: 0(fixed) Power_divergenceResult(statistic=80.47584678147248, pvalue=3.2591439052264704e-09)
In [41]:
df_temp = df_fer[df_fer.E < 1e-2]
E = df_temp['E'][1:]
N = df_temp['N'][1:]
popt, pcov = curve_fit((lambda E, T, n: MB(E, T, n, -0.5)), E, N, p0 = [30, 1e-8])
fig, ax = plt.subplots()
ax.plot(E, N, 'x', label = 'data')
ax.plot(E, MB(E, *popt, -0.5), label = 'fit')
ax.set_xscale('log')
ax.set_yscale('log')
ax.set_xlabel ('electron energy (eV)')
ax.set_ylabel (r'differential density djz/dE (s$^{-1}$ m$^{-2}$ eV$^{-1}$)')
ax.legend()
ax.plot()
print("Fit of MB to data from Ferenc, 2 degrees of freedom")
print("Temperature:\t" + str(popt[0]))
print("Normation:\t" + str(popt[1]))
print("E_power:\t-0.5 (fixed)")
print (chisquare(N, f_exp=MB(E, *popt, -0.5), ddof = 2))Fit of MB to data from Ferenc, 2 degrees of freedom Temperature: 46.6619354475606 Normation: 0.011888255065024538 E_power: -0.5 (fixed) Power_divergenceResult(statistic=5.338824088613379, pvalue=0.9995403208166638)
In [29]:
df_temp = df_fer[df_fer.E < 1e-2]
E = df_temp['E'][1:]
N = df_temp['N'][1:]
popt, pcov = curve_fit((lambda E, n: MB(E, 30, n, 0)), E, N, p0 = 1e-2)
fig, ax = plt.subplots()
ax.plot(E, N, 'x', label = 'data')
ax.plot(E, MB(E, 30, *popt, 0), label = 'fit')
ax.set_xscale('log')
ax.set_yscale('log')
ax.set_xlabel ('electron energy (eV)')
ax.set_ylabel (r'differential density djz/dE (s$^{-1}$ m$^{-2}$ eV$^{-1}$)')
ax.legend()
ax.plot()
print(popt)
print("Fit of MB to data from Ferenc, 1 degrees of freedom")
print("Temperature:\t30(fixed)")
print("Normation:\t" + str(popt[0]))
print("E_power:\t0(fixed)")
print (chisquare(N, f_exp=MB(E, 30, *popt, 0), ddof = 1))[0.25794058] Fit of MB to data from Ferenc, 1 degrees of freedom Temperature: 30(fixed) Normation: 0.25794057729675135 E_power: 0(fixed) Power_divergenceResult(statistic=104.94782868330498, pvalue=3.8073314558650583e-13)
In [30]:
df_temp = df_fer[df_fer.E > 1e3]
E = df_temp['E'][:-2]
N = df_temp['N'][:-2]
popt, pcov = curve_fit(beta, E, N, p0 = [1e3, 1])
fig, ax = plt.subplots()
ax.plot(E, N, 'x', label = 'data')
ax.plot(E, beta(E, *popt), label = 'fit')
ax.set_xscale('log')
ax.set_yscale('log')
ax.set_xlabel ('electron energy (eV)')
ax.set_ylabel (r'differential density djz/dE (s$^{-1}$ m$^{-2}$ eV$^{-1}$)')
ax.legend()
ax.plot()
print("Fit of beta spectrum to data from Ferenc, 2 degrees of freedom")
print("Normation:\t" + str(popt[0]))
print("E_power:\t" + str(popt[1]))
print (chisquare(N, f_exp=beta(E, *popt), ddof = 2))Fit of beta spectrum to data from Ferenc, 2 degrees of freedom Normation: 2.3348638943611926e-06 E_power: -0.228332079579683 Power_divergenceResult(statistic=6.166512673353345e-12, pvalue=1.0)
In [31]:
df_temp = df_fer[df_fer.E > 1e3]
E = df_temp['E'][:-2]
N = df_temp['N'][:-2]
popt, pcov = curve_fit(lambda E, n: beta(E, n, 0), E, N, p0 = [1e3])
fig, ax = plt.subplots()
ax.plot(E, N, 'x', label = 'data')
ax.plot(E, beta(E, *popt, 0), label = 'fit')
ax.set_xscale('log')
ax.set_yscale('log')
ax.set_xlabel ('electron energy (eV)')
ax.set_ylabel (r'differential density djz/dE (s$^{-1}$ m$^{-2}$ eV$^{-1}$)')
ax.legend()
ax.plot()
print("Fit of beta spectrum to data from Ferenc, 1 degree of freedom")
print("Normation:\t" + str(popt[0]))
print("E_power:\t0(fixed)")
print (chisquare(N, f_exp=beta(E, *popt, 0), ddof = 1))Fit of beta spectrum to data from Ferenc, 1 degree of freedom Normation: 3.873824262029582e-07 E_power: 0(fixed) Power_divergenceResult(statistic=1.6854587497733813e-11, pvalue=1.0)
In [42]:
df_temp = df_fer[df_fer.E > 1e3]
E = df_temp['E'][:-2]
N = df_temp['N'][:-2]
popt, pcov = curve_fit(lambda E, n: beta(E, n, -0.5), E, N, p0 = [1e3])
fig, ax = plt.subplots()
ax.plot(E, N, 'x', label = 'data')
ax.plot(E, beta(E, *popt, -0.5), label = 'fit')
ax.set_xscale('log')
ax.set_yscale('log')
ax.set_xlabel ('electron energy (eV)')
ax.set_ylabel (r'differential density djz/dE (s$^{-1}$ m$^{-2}$ eV$^{-1}$)')
ax.legend()
ax.plot()
print("Fit of beta spectrum to data from Ferenc, 1 degree of freedom")
print("Normation:\t" + str(popt[0]))
print("E_power:\t-0.5 (fixed)")
print (chisquare(N, f_exp=beta(E, *popt, -0.5), ddof = 1))Fit of beta spectrum to data from Ferenc, 1 degree of freedom Normation: 1.8410467244692388e-05 E_power: -0.5 (fixed) Power_divergenceResult(statistic=2.30449471636419e-11, pvalue=1.0)
In [ ]:
In [ ]:
In [ ]:
In [ ]: