1.0 MiB
1.0 MiB
In [511]:
import numpy as np
import pandas as pd
import os as os
import scipy.optimize as optimization
import glob as glob
import h5py as h5py
from scipy.signal import argrelextrema
pd.options.mode.chained_assignment = None In [530]:
import matplotlib
matplotlib.use('TkAgg')
%matplotlib inline
import matplotlib.pyplot as plt
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' : 150,
'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 [513]:
%run "../../mcelectron-analysis/functions/particles/plot_df_part.py"
%run "../../mcelectron-analysis/functions/populations/plot_df_pop.py"In [514]:
plot_dir = "/Users/ChristianReiling/Documents/Masterarbeit/docs/LaTeX/pics/results/"
dpi = 150
cs = sns.color_palette()In [515]:
# Load Histograms from Analysis
df_part_e = pd.read_csv("csv_data/1e5_run_1/df_part_e.csv")
df_part_all = pd.read_csv("csv_data/1e5_run_1/df_part_all.csv")
df_part_rw = pd.read_csv("csv_data/1e5_run_1/df_part_rw.csv")
df_part_rw_zoom = pd.read_csv("csv_data/1e5_run_1/df_part_rw_zoom.csv")
df_pop = pd.read_csv("csv_data/1e5_run_1/df_pop.csv")
df_part_e = pd.read_csv("sim_data/sim1/df_part_e.csv")
df_part_all = pd.read_csv("sim_data/sim1/df_part_all.csv")
df_part_rw = pd.read_csv("sim_data/sim1/df_part_rw.csv")
df_part_rw_zoom = pd.read_csv("sim_data/sim1/df_part_rw_zoom.csv")
df_pop = pd.read_csv("sim_data/sim1/df_pop.csv")
In [516]:
df_temp = df_part_e[['z','Emid', 'dndE']].groupby(['z', 'Emid'], as_index = False).mean()
z = np.unique(df_temp.z)
z = np.concatenate([[z[0]], (z[1:] + z[:-1])/2, [z[-1]]])
E = np.unique(np.concatenate([df_part_e.Emin, df_part_e.Emax]))
E = np.sort(E)[::-1]
df_temp = df_temp.pivot(index='Emid', columns='z', values='dndE')
df_temp = df_temp.replace(-np.inf, 0)
df_temp = df_temp.sort_index(ascending = False)
dndE = np.array(df_temp)
In [517]:
fig, ax = plt.subplots(figsize=[15/2.54, 5/2.54])
hm = ax.pcolor(z, E, dndE,
norm=colors.LogNorm(vmin=1e0, vmax=1e16),
cmap='viridis')
cbar = fig.colorbar(hm, ax=ax)
cbar.outline.set_visible(False)
cbar.set_label(r'Diff. e$^-$ density (m$^{-3}$ eV$^{-1}$)')
fig.patch.set_visible(False)
ax.set_xscale('linear')
ax.set_yscale('log')
ax.set_xlabel('Longitudinal position (m)')
ax.set_ylabel('Energy (eV)')
ax.spines['top'].set_visible(False)
ax.spines['bottom'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_visible(False)
fig.savefig(plot_dir + 'dndE_3D.png', dpi = dpi, bbox_inches='tight')
#fig.savefig(plot_dir + 'dndE3D.pdf', dpi = 300, bbox_inches='tight')In [518]:
from scipy.optimize import curve_fit
from scipy.stats import chisquare
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])
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])
def pl(E, C, pot):
return C * pow(E, pot)
pl = np.vectorize(pl, otypes=[np.float])In [519]:
df_temp = df_part_e[df_part_e.z == 5]
df_temp = df_temp.groupby(['Emin', 'Emax', 'Emid'], as_index = False).mean()
df_temp = df_temp.drop(['z', 'rmin', 'rmid', 'rmax', 'Unnamed: 0'], axis = 1)
df_temp = df_temp.drop(['Emin', 'Emax', 'N', 'djzabsdE', 'djzdE'], axis = 1)
df_temp['set'] = 'data'In [520]:
# Maxwell Boltzmann
df_fit = df_temp[df_temp.Emid < 1e-2]
E = df_fit.Emid
N = df_fit.dndE
popt, pcov = curve_fit(MB, E, N, p0 = [30, 5e10, -0.5])
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))
Enew = df_temp[df_temp.Emid < 7e-2].Emid
df_MB = pd.DataFrame({'Emid':Enew, 'dndE':MB(Enew, *popt), 'set': 'MB'})/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 dn/dE to MB Temperature: 29.82832539657092 Normation: 248155743486.45496 E_power: -0.6405429787718983 Power_divergenceResult(statistic=2492300081782.2744, pvalue=0.0)
In [521]:
# Maxwell Boltzmann
df_fit = df_temp[df_temp.Emid < 1e-2]
E = df_fit.Emid
N = df_fit.dndE
popt, pcov = curve_fit(lambda E, C: MB(E, 30, C, -0.5), E, N, p0 = [5e10])
fig, ax = plt.subplots()
ax.plot(E, N, 'x', label = 'data')
ax.plot(E, MB(E, 30, *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")
print("Normation:\t" + str(popt[0]))
print("E_power:\t")
print (chisquare(N, f_exp=MB(E, 30, *popt, -0.5), ddof = 2))
Enew = df_temp[df_temp.Emid < 7e-2].Emid
df_MB = pd.DataFrame({'Emid':Enew, 'dndE':MB(Enew, 30, *popt, -0.5), 'set': 'MB'})Fit of dn/dE to MB Temperature: Normation: 928523024363.2037 E_power: Power_divergenceResult(statistic=8876567252232085.0, pvalue=0.0)
In [522]:
# Beta Spectrum
df_fit = df_temp[df_temp.Emid > 1e2]
E = df_fit.Emid
N = df_fit.dndE
popt, pcov = curve_fit(beta, E, N, p0 = [1e3, -0.5])
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))
Enew = df_temp[df_temp.Emid > 1e0].Emid
df_beta = pd.DataFrame({'Emid':Enew, 'dndE':beta(Enew, *popt), 'set': 'Beta'})Fit of djz/dE to beta spectrum Normation: 3363234.601182366 E_power: -0.11032888419310591 Power_divergenceResult(statistic=456.02946189969424, pvalue=1.0320794882703975e-82)
In [523]:
# Powerlaw 1
df_fit = df_temp[(df_temp.Emid > 5e-2) & (df_temp.Emid < 5e-1)]
E = df_fit.Emid
N = df_fit.dndE
popt, pcov = curve_fit(pl, E, N, p0 = [1e3, -0.5])
fig, ax = plt.subplots()
ax.plot(E, N, 'x', label = 'data')
ax.plot(E, pl(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=pl(E, *popt), ddof = 2))
Enew = df_temp[(df_temp.Emid > 1e-2) & (df_temp.Emid < 5e-0)].Emid
df_pl1 = pd.DataFrame({'Emid':Enew, 'dndE':pl(Enew, *popt), 'set': 'pl1'})Fit of djz/dE to beta spectrum Normation: 222131193.32458222 E_power: -2.0284650403778226 Power_divergenceResult(statistic=252773640.60421586, pvalue=0.0)
In [524]:
# Powerlaw 1
df_fit = df_temp[(df_temp.Emid > 5e-2) & (df_temp.Emid < 5e-1)]
E = df_fit.Emid
N = df_fit.dndE
popt, pcov = curve_fit(pl, E, N, p0 = [1e3, -0.5])
fig, ax = plt.subplots()
ax.plot(E, N, 'x', label = 'data')
ax.plot(E, pl(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=pl(E, *popt), ddof = 2))
Enew = df_temp[(df_temp.Emid > 1e-2) & (df_temp.Emid < 5e-0)].Emid
df_pl1 = pd.DataFrame({'Emid':Enew, 'dndE':pl(Enew, *popt), 'set': 'pl1'})Fit of djz/dE to beta spectrum Normation: 222131193.32458222 E_power: -2.0284650403778226 Power_divergenceResult(statistic=252773640.60421586, pvalue=0.0)
In [525]:
# Powerlaw 2
df_fit = df_temp[(df_temp.Emid > 5e-1) & (df_temp.Emid < 5e1)]
E = df_fit.Emid
N = df_fit.dndE
popt, pcov = curve_fit(pl, E, N, p0 = [1e3, -0.5])
fig, ax = plt.subplots()
ax.plot(E, N, 'x', label = 'data')
ax.plot(E, pl(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=pl(E, *popt), ddof = 2))
Enew = df_temp[(df_temp.Emid > 5e-1) & (df_temp.Emid < 1e2)].Emid
df_pl2 = pd.DataFrame({'Emid':Enew, 'dndE':pl(Enew, *popt), 'set': 'pl2'})Fit of djz/dE to beta spectrum Normation: 32206741.85503974 E_power: -4.965785481080664 Power_divergenceResult(statistic=27426157.81572678, pvalue=0.0)
In [526]:
df_plot = df_temp
df_plot = df_plot.append(df_MB)
df_plot = df_plot.append(df_beta)
#df_plot = df_plot.append(df_pl1)
#df_plot = df_plot.append(df_pl2)In [533]:
fig, ax = plt.subplots(figsize=[15/2.54, 8/2.54])
sns.lineplot(ax = ax, x="Emid", y="dndE", data=df_plot,
style = 'set',
hue = 'set',
err_style=None, legend = False)
ax.set_xscale('log')
ax.set_yscale('log')
ax.set_xlabel ('Energy (eV)')
ax.set_ylabel (r'Diff. e$^-$ density (m$^{-3}$ eV$^{-1}$)')
#handles, labels = ax.get_legend_handles_labels()
#ax.legend(handles=handles[1:], labels=labels[1:])
ax.text(3e-1, 1e10, 'KARL', color = cs[0])
ax.text(5e-5, 1e7, '$f_\mathrm{MB}(E,\, 30\,\mathrm{K}) \cdot E^{-0.5}$', color = cs[1])
ax.text(1e-1, 1e1, '$f_{beta}(E) \cdot E^{-0.5}$', color = cs[2])
fig.savefig(plot_dir + '/dndE_analysis.pgf', bbox_inches='tight')
fig.savefig(plot_dir + '/dndE_analysis.pdf', bbox_inches='tight')In [534]:
import scipy.integrate as integrate
integrate.quad(lambda x: beta_dist_mass(x,0), 1e2, 19600)Out [534]:
(0.9917570415492385, 1.127819464771399e-08)
In [535]:
df_temp = df_part_e[df_part_e.Emid>1e2]
df_temp = df_temp.groupby('z', as_index = False).sum()
df_temp = pd.DataFrame({
'z':df_temp.z,
'N':df_temp.N,
'set': 'sim'
})
df_temp = df_temp.append(pd.DataFrame(
{'z':df_temp.z,
'N':1e4,
'set': 'beta'}))In [536]:
fig, ax = plt.subplots(figsize=[15/2.54, 5/2.54])
sns.lineplot(ax = ax, x="z", y="N", data=df_temp,
style = 'set',
hue = 'set',
legend = False)
ax.set_xlabel ('Longituidinal position (m)')
ax.set_ylabel ('Number $>$100\,eV - e$^-$')
ax.text(2, 1.1e4, 'KARL', color = cs[0])
ax.text(3.7, 1.03e4, 'Beta decay', color = cs[1])
#ax.text(3e-1, 2e1, '$f_{beta}(E) \cdot E^{-0.5}$', color = cs[2])
fig.savefig(plot_dir + '/../appendix/dndE_beta_long.pgf', bbox_inches='tight')
fig.savefig(plot_dir + '/../appendix/dndE_beta_long.pdf', bbox_inches='tight')In [537]:
df_plot = pd.DataFrame()
df_temp = df_part_all[df_part_all.species == 'e-'].groupby(['z'], as_index = False).mean()
df_plot = df_plot.append(pd.DataFrame({'z':df_temp.z, 'jz':df_temp.jz, 'species':'e-'}))
df_temp = df_part_all[df_part_all.species != 'e-'].groupby(['z', 'species'], as_index = False).mean()
df_temp = df_temp.groupby('z', as_index = False).sum()
df_plot = df_plot.append(pd.DataFrame({'z':df_temp.z, 'jz':df_temp.jz, 'species':'ions'}))In [538]:
fig, ax = plt.subplots(figsize=[15/2.54, 5/2.54])
sns.lineplot(ax = ax, x="z", y="jz", data=df_plot,
style = 'species',
hue = 'species',
legend = False)
ax.set_xscale('linear')
ax.set_yscale('linear')
ax.set_xlabel ('Longituidinal position (m)')
ax.set_ylabel (r'Particle flux (m$^{-2}$ s$^{-1}$)')
handles, labels = ax.get_legend_handles_labels()
#ax.legend(handles=handles[1:], labels=labels[1:])
ax.axhline(0, color = 'k', linewidth = 0.1)
ax.text(-2.5, -15e13, 'e$^-$', color = cs[0])
ax.text(-2.5, -6e13, 'ions', color = cs[1])
fig.savefig(plot_dir + '/djzdE.pgf', bbox_inches='tight')
fig.savefig(plot_dir + '/djzdE.pdf', bbox_inches='tight')In [628]:
# Load Data from Ferenc
df_fer = pd.read_csv('data/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']
df_fer = df_fer.drop(99, axis = 0)
df_fer = df_fer.drop(0, axis = 0)In [629]:
# Load averaged beta spectrum
df_temp = df_part_e
df_temp = df_temp.groupby(['Emin', 'Emax', 'Emid'], as_index = False).mean()
df_temp = df_temp.drop(['z', 'rmin', 'rmid', 'rmax', 'Unnamed: 0'], axis = 1)
df_temp = df_temp.drop(['Emin', 'Emax', 'N', 'djzabsdE', 'djzdE'], axis = 1)
df_temp['set'] = 'data'In [630]:
# Get scale of my beta spectrum
df_fit = df_temp[df_temp.Emid > 10**3.5]
popt, pcov = curve_fit(lambda x, C: beta(x, C, -0.5), df_fit.Emid, df_fit.dndE)
fig, ax = plt.subplots()
sns.lineplot(ax = ax, x="Emid", y="dndE", data=df_fit, legend = 'brief')
ax.plot(df_fit.Emid, beta(df_fit.Emid, popt[0], -0.5))
ax.set_xscale('log')
ax.set_yscale('log')
ax.set_xlabel ('Electron energy (eV)')
ax.set_ylabel (r'Diff. e$^-$ density dn/dE (m$^{-3}$ eV$^{-1}$)')
my_scale = popt[0]In [631]:
# Get scale of ferenc spectrum
df_fit = df_fer[df_fer.E > 1e3]
E_fit = df_fit.E
N_fit = df_fit.N
popt, pcov = curve_fit(lambda E, N: N*beta(E, my_scale, -0.5), E_fit, N_fit)
fig, ax = plt.subplots()
ax.plot(E_fit, N_fit, 'x', label = 'data')
ax.plot(E_fit, popt[0]*beta(E_fit, my_scale, -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()
fer_scale = 1/popt[0]
print("Scale:\t" + str(fer_scale))
#print (chisquare(N, f_exp=beta(E, *popt), ddof = 2))
df_fer_plot = pd.DataFrame({'Emid':df_fer.E, 'dndE':df_fer.N*fer_scale, 'set':'fer'})Scale: 3246884719911.551
In [632]:
df_temp = df_part_e
df_temp = df_temp.groupby(['Emin', 'Emax', 'Emid', 'z'], as_index = False).mean()
df_temp = df_temp.drop(['z', 'rmin', 'rmid', 'rmax', 'Unnamed: 0'], axis = 1)
df_temp = df_temp.drop(['Emin', 'Emax', 'N', 'djzabsdE', 'djzdE'], axis = 1)
df_temp['set'] = 'data'
df_plot = df_temp
df_plot = df_plot.append(df_fer_plot)In [633]:
fig, ax = plt.subplots(figsize=[15/2.54, 8/2.54])
sns.lineplot(ax = ax, x="Emid", y="dndE", data=df_plot,
style = 'set',
hue = 'set',
#err_style=None,
legend = False)
ax.set_xscale('log')
ax.set_yscale('log')
ax.set_xlabel ('Energy (eV)')
ax.set_ylabel (r'Diff. e$^-$ density (m$^{-3}$ eV$^{-1}$)')
#handles, labels = ax.get_legend_handles_labels()
#ax.legend(handles=handles[1:], labels=labels[1:])
ax.text(1e-1, 1e4, 'KARL (SIM1)', color = cs[0])
ax.text(5, 5e7, 'COMP1', color = cs[1])
fig.savefig(plot_dir + '/dndE_comp_fer.pgf', bbox_inches='tight')
fig.savefig(plot_dir + '/dndE_comp_fer.pdf', bbox_inches='tight')In [634]:
fig, ax = plt.subplots(figsize=[15/2.54, 8/2.54])
sns.lineplot(ax = ax, x="Emid", y="dndE", data=df_plot,
style = 'set',
hue = 'set',
#err_style=None,
legend = False)
ax.set_xscale('log')
ax.set_yscale('log')
ax.set_xlabel ('Energy (eV)')
ax.set_ylabel (r'Diff. e$^-$ density (m$^{-3}$ eV$^{-1}$)')
#handles, labels = ax.get_legend_handles_labels()
#ax.legend(handles=handles[1:], labels=labels[1:])
ax.text(10**-0.8, 1e4, 'KARL (SIM1)', color = cs[0])
ax.text(10, 5e7, 'COMP1', color = cs[1])
ax.axvline(10**-1.6, color = 'k', linewidth = 0.3)
ax.axvline(10**-0.2, color = 'k', linewidth = 0.3)
ax.axvline(10**0.9, color = 'k', linewidth = 0.3)
ax.axvline(10**2.4, color = 'k', linewidth = 0.3)
ax.text(10**-3.6, 1e7, 'I', color = 'k', size = 15)
ax.text(10**-1, 1e13, 'II', color = 'k', size = 15)
ax.text(10**0.2, 1e13, 'III', color = 'k', size = 15)
ax.text(10**1.5, 1e13, 'IV', color = 'k', size = 15)
ax.text(10**3.5, 1e13, 'V', color = 'k', size = 15)
fig.savefig(plot_dir + '/dndE_comp_fer.pgf', bbox_inches='tight')
fig.savefig(plot_dir + '/dndE_comp_fer.pdf', bbox_inches='tight')In [545]:
# Spectra Comp
df_plot = pd.DataFrame()
df_temp = df_part_e#[df_part_e.Emid > 1e2]
df_temp = df_temp.groupby(['Emid', 'z'], as_index = False).sum()
df_temp = pd.DataFrame({'E':df_temp.Emid, 'dndE':df_temp.dndE, 'z':df_temp.z, 'mod':'Barrier'})
df_plot = df_plot.append(df_temp)
t_max = np.sort(df_pop.t.unique())[-1]
df_temp = df_pop[df_pop.Emin >= 9e-6]
df_temp = df_temp[(df_temp.species == 'e-') & (df_temp.t == t_max)]
df_temp['zmid'] = (df_temp['zmin']+df_temp['zmax'])/2
df_temp['Emid'] = (df_temp['Emin']+df_temp['Emax'])/2
df_temp['dndE'] = df_temp['n']/(df_temp['Emax'] - df_temp['Emin'])
df_temp = df_temp.groupby(['zmid','Emid'], as_index = False).mean()
df_temp = pd.DataFrame({'E':df_temp.Emid, 'dndE':df_temp.dndE, 'z':df_temp.zmid, 'mod':'Runtime'})
df_plot = df_plot.append(df_temp)
fig, ax = plt.subplots(figsize=[15/2.54, 8/2.54])
sns.lineplot(ax = ax, x="E", y="dndE", data=df_plot,
style = 'mod',
hue = 'mod',
legend = False)
ax.set_xscale('log')
ax.set_yscale('log')
ax.set_xlabel ('Energy (eV)')
ax.set_ylabel (r'Diff. e$^-$ density (m$^{-3}$ eV$^{-1}$)')
ax.text(4, 2e6, 'Logging Barrier', color = cs[0])
ax.text(2, 5e3, 'RDF', color = cs[1])
fig.savefig(plot_dir + '/dndE_comp_rdf.pgf', dpi = dpi, bbox_inches='tight')
fig.savefig(plot_dir + '/dndE_comp_rdf.pdf', dpi = dpi, bbox_inches='tight')In [551]:
df_part_e1 = pd.read_csv("sim_data/sim1/df_part_e.csv")
df_part_e2 = pd.read_csv("sim_data/sim2/df_part_e.csv")
df_part_e3 = pd.read_csv("sim_data/sim3/df_part_e.csv")In [552]:
df_plot = pd.DataFrame()
df_temp = df_part_e1
df_temp = df_temp.groupby(['Emin', 'Emax', 'Emid'], as_index = False).mean()
df_temp = df_temp.drop(['z', 'rmin', 'rmid', 'rmax', 'Unnamed: 0'], axis = 1)
df_temp = df_temp.drop(['Emin', 'Emax', 'N', 'djzabsdE', 'djzdE'], axis = 1)
df_temp['set'] = 'SIM1'
df_plot = df_plot.append(df_temp)
df_temp = df_part_e2
df_temp = df_temp.groupby(['Emin', 'Emax', 'Emid'], as_index = False).mean()
df_temp = df_temp.drop(['z', 'rmin', 'rmid', 'rmax', 'Unnamed: 0'], axis = 1)
df_temp = df_temp.drop(['Emin', 'Emax', 'N', 'djzabsdE', 'djzdE'], axis = 1)
df_temp['set'] = 'SIM2'
df_plot = df_plot.append(df_temp)
df_temp = df_part_e3
df_temp = df_temp.groupby(['Emin', 'Emax', 'Emid'], as_index = False).mean()
df_temp = df_temp.drop(['z', 'rmin', 'rmid', 'rmax', 'Unnamed: 0'], axis = 1)
df_temp = df_temp.drop(['Emin', 'Emax', 'N', 'djzabsdE', 'djzdE'], axis = 1)
df_temp['set'] = 'SIM3'
df_plot = df_plot.append(df_temp)In [553]:
fig, ax = plt.subplots(figsize=[15/2.54, 8/2.54])
sns.lineplot(ax = ax, x="Emid", y="dndE", data=df_plot,
style = 'set',
hue = 'set',
err_style = None,
legend = 'full')
ax.set_xscale('log')
ax.set_yscale('log')
ax.set_xlabel ('Energy (eV)')
ax.set_ylabel (r'Diff. e$^-$ density (m$^{-3}$ eV$^{-1}$)')
handles, labels = ax.get_legend_handles_labels()
ax.legend(handles=handles[1:], labels=labels[1:])
fig.savefig(plot_dir + '/../appendix/dndE_rec_comp.pgf', dpi = dpi, bbox_inches='tight')
fig.savefig(plot_dir + '/../appendix/dndE_rec_comp.pdf', dpi = dpi, bbox_inches='tight')In [554]:
df_plot2 = df_plot[df_plot.Emid < 1e-2]
fig, ax = plt.subplots(figsize=[15/2.54, 8/2.54])
sns.lineplot(ax = ax, x="Emid", y="dndE", data=df_plot2,
style = 'set',
hue = 'set',
err_style = None,
legend = False)
ax.set_xscale('log')
ax.set_yscale('log')
ax.set_xlabel ('Energy (eV)')
ax.set_ylabel (r'Diff. e$^-$ density (m$^{-3}$ eV$^{-1}$)')
ax.text(5e-4, 3e15, 'SIM1', color = cs[0])
ax.text(1e-3, 2.5e13, 'SIM2', color = cs[1])
ax.text(5e-5, 7e14, 'SIM3', color = cs[2])
#fig.savefig(plot_dir + '/dndE_rec_comp_zoom.pgf', dpi = dpi, bbox_inches='tight')
#fig.savefig(plot_dir + '/dndE_rec_comp_zoom.pdf', dpi = dpi, bbox_inches='tight')Out [554]:
Text(5e-05, 700000000000000.0, 'SIM3')
In [555]:
df_calc = df_plot2
df_SIM1 = df_calc[df_calc.set == 'SIM1'].groupby('Emid', as_index = False).mean()
df_SIM2 = df_calc[df_calc.set == 'SIM2'].groupby('Emid', as_index = False).mean()
df_SIM3 = df_calc[df_calc.set == 'SIM3'].groupby('Emid', as_index = False).mean()
df_ratio = pd.DataFrame()
df_ratio = df_ratio.append(pd.DataFrame({
'Emid': df_SIM1.Emid,
'ratio' : 100, # dummy
'set' : 'SIM1'
}))
df_ratio = df_ratio.append(pd.DataFrame({
'Emid': df_SIM1.Emid,
'ratio' : df_SIM2.dndE/df_SIM1.dndE,
'set' : 'SIM2'
}))
df_ratio = df_ratio.append(pd.DataFrame({
'Emid': df_SIM1.Emid,
'ratio' : df_SIM3.dndE/df_SIM1.dndE,
'set' : 'SIM3'
}))In [557]:
fig, ax = plt.subplots(2, 1, sharex=True, figsize=[15/2.54, 10/2.54], gridspec_kw={'height_ratios': [3, 2]})
fig.subplots_adjust(hspace=0.01)
sns.lineplot(ax = ax[0], x="Emid", y="dndE", data=df_plot2,
style = 'set',
hue = 'set',
err_style = None,
legend = False)
ax[0].set_xscale('log')
ax[0].set_yscale('log')
ax[0].set_ylim([10**12.5, 1e16])
ax[0].set_ylabel (r'Diff. e$^-$ density (m$^{-3}$ eV$^{-1}$)')
ax[0].text(5e-4, 3e15, 'SIM1', color = cs[0])
ax[0].text(1e-3, 2.5e13, 'SIM2', color = cs[1])
ax[0].text(5e-5, 7e14, 'SIM3', color = cs[2])
sns.lineplot(ax = ax[1], x="Emid", y="ratio", data=df_ratio,
style = 'set',
hue = 'set',
err_style = None,
legend = False)
ax[1].set_yscale('log')
ax[1].set_ylim([10**-2, 10**0.5])
ax[1].set_xlabel ('Energy (eV)')
ax[1].set_ylabel (r'Ratio to SIM1')
ax[1].text(1e-4, 4.5e-2, 'SIM2', color = cs[1])
ax[1].text(1e-4, 2e-1, 'SIM3', color = cs[2])
fig.savefig(plot_dir + '/dndE_rec_comp_zoom.pgf', dpi = dpi, bbox_inches='tight')
fig.savefig(plot_dir + '/dndE_rec_comp_zoom.pdf', dpi = dpi, bbox_inches='tight')In [656]:
df_plot = pd.DataFrame()
df_temp = df_part_e1
df_temp = df_temp.groupby(['Emin', 'Emax', 'Emid'], as_index = False).mean()
df_temp = df_temp.drop(['z', 'rmin', 'rmid', 'rmax', 'Unnamed: 0'], axis = 1)
df_temp = df_temp.drop(['Emin', 'Emax', 'N', 'djzabsdE', 'djzdE'], axis = 1)
df_temp['set'] = 'SIM1'
df_plot = df_plot.append(df_temp)
df_temp = df_part_e2
df_temp = df_temp.groupby(['Emin', 'Emax', 'Emid'], as_index = False).mean()
df_temp = df_temp.drop(['z', 'rmin', 'rmid', 'rmax', 'Unnamed: 0'], axis = 1)
df_temp = df_temp.drop(['Emin', 'Emax', 'N', 'djzabsdE', 'djzdE'], axis = 1)
df_temp['set'] = 'SIM2'
df_plot = df_plot.append(df_temp)
df_temp = df_part_e3
df_temp = df_temp.groupby(['Emin', 'Emax', 'Emid'], as_index = False).mean()
df_temp = df_temp.drop(['z', 'rmin', 'rmid', 'rmax', 'Unnamed: 0'], axis = 1)
df_temp = df_temp.drop(['Emin', 'Emax', 'N', 'djzabsdE', 'djzdE'], axis = 1)
df_temp['set'] = 'SIM3'
df_plot = df_plot.append(df_temp)
df_plot = df_plot.append(pd.DataFrame({
'Emid': df_fer.E,
'dndE': df_fer.N *fer_scale ,
'set' : 'COMP1'
}))In [657]:
fig, ax = plt.subplots(figsize=[15/2.54, 8/2.54])
sns.lineplot(ax = ax, x="Emid", y="dndE", data=df_plot,
style = 'set',
hue = 'set',
err_style = None,
legend = 'full')
ax.set_xscale('log')
ax.set_yscale('log')
ax.set_xlabel ('Energy (eV)')
ax.set_ylabel (r'Diff. e$^-$ density (m$^{-3}$ eV$^{-1}$)')
handles, labels = ax.get_legend_handles_labels()
ax.legend(handles=handles[1:], labels=labels[1:])
#fig.savefig(plot_dir + '/../appendix/dndE_rec_comp.pgf', dpi = dpi, bbox_inches='tight')
#fig.savefig(plot_dir + '/../appendix/dndE_rec_comp.pdf', dpi = dpi, bbox_inches='tight')Out [657]:
<matplotlib.legend.Legend at 0x13bff9a90>
In [658]:
# interpolate fernence results at my points to calculate fractions
from scipy import interpolate
df_plot2 = df_plot[df_plot.set != 'SIM1']
minE = df_plot2[df_plot2.set == 'COMP1'].Emid.min()
maxE = df_plot2[df_plot2.set == 'COMP1'].Emid.max()
df_plot2 = df_plot2[df_plot2.Emid >= minE]
df_plot2 = df_plot2[df_plot2.Emid <= maxE]
f = interpolate.interp1d(df_plot2[df_plot2.set == 'COMP1'].Emid, df_plot2[df_plot2.set == 'COMP1'].dndE)
df_plot2 = df_plot2[df_plot2.set != 'COMP1']
newE = df_plot2.Emid.unique()
df_plot2 = df_plot2.append(pd.DataFrame({
'Emid' : newE,
'dndE' : f(newE),
'set' : 'COMP1'
}))
df_plot2 = pd.concat([pd.DataFrame({'Emid': [1e-3, 1e-4], 'dndE': 1e1, 'set': 'SIM1'}), df_plot2], ignore_index=True) # DummyIn [659]:
df_plot2 = df_plot2[df_plot2.Emid < 10**-2]
fig, ax = plt.subplots(figsize=[15/2.54, 8/2.54])
sns.lineplot(ax = ax, x="Emid", y="dndE", data=df_plot2,
style = 'set',
hue = 'set',
err_style = None,
legend = False)
ax.set_xscale('log')
ax.set_yscale('log')
ax.set_xlabel ('Energy (eV)')
ax.set_ylabel (r'Diff. e$^-$ density (m$^{-3}$ eV$^{-1}$)')
ax.set_ylim([1e11, 1e15])
ax.text(1e-3, 3e13, 'SIM2', color = cs[1])
ax.text(1e-3, 4e14, 'SIM3', color = cs[2])
ax.text(2e-4, 2e14, 'COMP1', color = cs[3])
#fig.savefig(plot_dir + '/dndE_rec_comp_zoom.pgf', dpi = dpi, bbox_inches='tight')
#fig.savefig(plot_dir + '/dndE_rec_comp_zoom.pdf', dpi = dpi, bbox_inches='tight')Out [659]:
Text(0.0002, 200000000000000.0, 'COMP1')
In [668]:
df_calc = df_plot2
df_SIM1 = df_calc[df_calc.set == 'SIM1'].groupby('Emid', as_index = False).mean()
df_SIM2 = df_calc[df_calc.set == 'SIM2'].groupby('Emid', as_index = False).mean()
df_SIM3 = df_calc[df_calc.set == 'SIM3'].groupby('Emid', as_index = False).mean()
df_SIMG = df_calc[df_calc.set == 'COMP1'].groupby('Emid', as_index = False).mean()
df_ratio = pd.DataFrame()
df_ratio = df_ratio.append(pd.DataFrame({
'Emid': df_SIMG.Emid,
'ratio' : 100, # dummy
'set' : 'SIM1'
}))
df_ratio = df_ratio.append(pd.DataFrame({
'Emid': df_SIMG.Emid,
'ratio' : df_SIM2.dndE/df_SIMG.dndE,
'set' : 'SIM2'
}))
df_ratio = df_ratio.append(pd.DataFrame({
'Emid': df_SIMG.Emid,
'ratio' : df_SIM3.dndE/df_SIMG.dndE,
'set' : 'SIM3'
}))
In [669]:
fig, ax = plt.subplots(2, 1, sharex=True, figsize=[15/2.54, 10/2.54], gridspec_kw={'height_ratios': [3, 2]})
fig.subplots_adjust(hspace=0.01)
sns.lineplot(ax = ax[0], x="Emid", y="dndE", data=df_plot2,
style = 'set',
hue = 'set',
err_style = None,
legend = False)
ax[0].set_xscale('log')
ax[0].set_yscale('log')
ax[0].set_ylim([10**12.5, 1e15])
ax[0].set_ylabel (r'Diff. e$^-$ density (m$^{-3}$ eV$^{-1}$)')
ax[0].text(1e-3, 3e13, 'SIM2', color = cs[1])
ax[0].text(1e-3, 4e14, 'SIM3', color = cs[2])
ax[0].text(2e-4, 2e14, 'COMP1', color = cs[3])
sns.lineplot(ax = ax[1], x="Emid", y="ratio", data=df_ratio,
style = 'set',
hue = 'set',
err_style = None,
legend = False)
ax[1].set_yscale('log')
ax[1].set_ylim([10**-1, 10**1.5])
ax[1].set_xlabel ('Energy (eV)')
ax[1].set_ylabel (r'Ratio to COMP1')
ax[1].axhline(1, color = 'k', linewidth = 0.1)
ax[1].text(5e-4, 3e-1, 'SIM2', color = cs[1])
ax[1].text(5e-4, 4e0, 'SIM3', color = cs[2])
fig.savefig(plot_dir + '/dndE_rec_comp_fer_zoom.pgf', dpi = dpi, bbox_inches='tight')
fig.savefig(plot_dir + '/dndE_rec_comp_fer_zoom.pdf', dpi = dpi, bbox_inches='tight')In [654]:
# Maxwell Boltzmann
df_fit = df_part_e1.groupby('Emid', as_index = False).mean()
df_fit = df_fit[df_fit.Emid < 1e-2]
E = df_fit.Emid
N = df_fit.dndE
popt, pcov = curve_fit(MB, E, N, p0 = [30, 5e10, -0.5])
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 ('Energy (eV)')
ax.set_ylabel (r'SIM1 Differential density (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: 31.19133401893666 Normation: 87479490837.16768 E_power: -0.6655533286110755 Power_divergenceResult(statistic=3013101218978.843, pvalue=0.0)
In [642]:
# Maxwell Boltzmann
df_fit = df_part_e2.groupby('Emid', as_index = False).mean()
df_fit = df_fit[df_fit.Emid < 1e-2]
E = df_fit.Emid
N = df_fit.dndE
popt, pcov = curve_fit(MB, E, N, p0 = [30, 5e10, -0.5])
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 ('Energy (eV)')
ax.set_ylabel (r'SIM1 Differential density (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: 36.728963257613785 Normation: 8508739847.704955 E_power: -0.578999026328307 Power_divergenceResult(statistic=1626211187812.963, pvalue=0.0)
In [643]:
# Maxwell Boltzmann
df_fit = df_part_e3.groupby('Emid', as_index = False).mean()
df_fit = df_fit[df_fit.Emid < 1e-2]
E = df_fit.Emid
N = df_fit.dndE
popt, pcov = curve_fit(MB, E, N, p0 = [30, 5e10, -0.5])
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 ('Energy (eV)')
ax.set_ylabel (r'SIM1 Differential density (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: 31.99775338024598 Normation: 19552098076.77436 E_power: -0.637566048762181 Power_divergenceResult(statistic=934061635233.1525, pvalue=0.0)
In [647]:
# Maxwell Boltzmann
df_fit = df_fer
df_fit = df_fit[df_fit.E < 1e-2]
E = df_fit.E
N = df_fit.N
popt, pcov = curve_fit(MB, E, N, p0 = [30, 5e10, -0.5])
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 ('Energy (eV)')
ax.set_ylabel (r'SIM1 Differential density (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: 31.588724558400717 Normation: 0.021502240337461478 E_power: -0.3575306652812476 Power_divergenceResult(statistic=0.11038324668402137, pvalue=1.0)
In [674]:
df_ratio[df_ratio.set=='SIM3']Out [674]:
| Emid | ratio | set | |
|---|---|---|---|
| 0 | 0.000145 | 3.284210 | SIM3 |
| 1 | 0.000180 | 3.117921 | SIM3 |
| 2 | 0.000223 | 2.900595 | SIM3 |
| 3 | 0.000276 | 2.753572 | SIM3 |
| 4 | 0.000343 | 2.549449 | SIM3 |
| 5 | 0.000424 | 2.406120 | SIM3 |
| 6 | 0.000526 | 2.298474 | SIM3 |
| 7 | 0.000651 | 2.150075 | SIM3 |
| 8 | 0.000807 | 2.033620 | SIM3 |
| 9 | 0.000999 | 1.934803 | SIM3 |
| 10 | 0.001238 | 1.827058 | SIM3 |
| 11 | 0.001534 | 1.706567 | SIM3 |
| 12 | 0.001900 | 1.620006 | SIM3 |
| 13 | 0.002354 | 1.514669 | SIM3 |
| 14 | 0.002916 | 1.399295 | SIM3 |
| 15 | 0.003612 | 1.308774 | SIM3 |
| 16 | 0.004475 | 1.217258 | SIM3 |
| 17 | 0.005544 | 1.124171 | SIM3 |
| 18 | 0.006868 | 1.024994 | SIM3 |
| 19 | 0.008508 | 0.925734 | SIM3 |
In [ ]: