From 0f20a5ba30a914fe587fd1bc2bffc00122585449 Mon Sep 17 00:00:00 2001 From: Joachim Rupp Date: Thu, 17 Sep 2020 15:19:19 +0200 Subject: [PATCH] added get_csv.py and added delta injection for ions --- src/mc_electron/injector.h | 6 + .../functions/particles/get_csv_part.py | 296 ++++++++++++++++++ .../functions/particles/get_df_part.py | 35 ++- .../functions/particles/plot_df_part.py | 18 +- .../functions/populations/get_df_pop.py | 4 +- .../functions/populations/plot_df_pop.py | 11 +- src/mcelectron-analysis/scripts/get_csv.py | 23 ++ src/mcelectron-analysis/scripts/merge.py | 1 + 8 files changed, 372 insertions(+), 22 deletions(-) create mode 100644 src/mcelectron-analysis/functions/particles/get_csv_part.py create mode 100644 src/mcelectron-analysis/scripts/get_csv.py diff --git a/src/mc_electron/injector.h b/src/mc_electron/injector.h index 0514ff0..aae219f 100644 --- a/src/mc_electron/injector.h +++ b/src/mc_electron/injector.h @@ -62,6 +62,12 @@ inline int Injector::inject (std::vector *particle_queue, const int &l if (ions == 0) { return 1; + } + if (ions == 2) { + vec3 vTI_ms = roll_uniform_direction(rngUni) * calc_v_ms_from_E_eV(E_eV, 2*mT_eV); + particle_queue->push_back(PartFac.create_T2I(loc_m, vTI_ms, last_ID+2, last_ID+2)); + return 2; + } else { vec3 vTI_ms = T2Population->roll_v_ms(loc_m); particle_queue->push_back(PartFac.create_T2I(loc_m, vTI_ms, last_ID+2, last_ID+2)); diff --git a/src/mcelectron-analysis/functions/particles/get_csv_part.py b/src/mcelectron-analysis/functions/particles/get_csv_part.py new file mode 100644 index 0000000..4d31f07 --- /dev/null +++ b/src/mcelectron-analysis/functions/particles/get_csv_part.py @@ -0,0 +1,296 @@ +import numpy as np +import pandas as pd +import matplotlib.pyplot as plt +import scipy.optimize as optimization +import glob +import h5py +import os +import sys +#from decimal import Decimal + +# get a list of h5 files in a directory +def get_h5list(directory, extension='h5'): + liste = [] + for f in os.listdir(directory): + if f.endswith('.' + extension): + liste.append(directory + '/' + f) + return liste + +def get_csv_part_e(inputpath, sim_time, num_E=100, num_r=1, Erange=[1e-5,2e4]): + + #set outputpath + outputpath = inputpath + '/csv' + + try: + os.mkdir(outputpath) + except: + pass + + num_E = num_E + num_r = num_r + Erange=[1e-5,2e4] + + h5list = get_h5list(inputpath) + + # def some constants + me_eV = 511e3 + c_ms = 3e8 + rrange = [0, 0.045] + + # calc bin properties + Ebins = pow(10, np.linspace(np.log10(Erange[0]), np.log10(Erange[1]), (num_E+1))) + Emids = (Ebins[1:] + Ebins[:-1]/2) + Emids = pow(10, (np.log10(Ebins[1:]) + np.log10(Ebins[:-1]))/2) + rbins = np.linspace(0, 0.045, (num_r+1)) + rmids = (rbins[1:] + rbins[:-1])/2 + As = np.pi*rbins[1:]**2 - np.pi*rbins[:-1]**2 + + # open the first h5 file to get keys + f = h5py.File(h5list[0], 'r') + g = f['Particles']['e-'] + zs = list(g.keys()) + f.close() + df = pd.DataFrame() # this will be our csv file + + zeros = np.zeros(num_E) + + for z in zs: + print(z) + # this is how our csv dataframe will look like: + a = pd.DataFrame({ + 'z' : float(z), + 'Emin' : zeros, + 'Emax' : 0, + 'Emid' : 0, + 'rmin' : 0, + 'rmax' : 0, + 'rmid' : 0, + 'N' : 0, + 'dndE' : 0, + 'djzabsdE' : 0, + 'djzdE' : 0, + 'N+' : 0, + 'N-' : 0, + }) + + for h5 in h5list[:]: + #print(h5) + f = h5py.File(h5, 'r') + g = f['Particles']['e-'] + df_z = pd.DataFrame(g[z][:]) + + # calc properties and calculate categories + df_z['E_eV'] = 0.5*me_eV*(df_z.vx_ms**2 + df_z.vy_ms**2 + df_z.vz_ms**2)/c_ms**2 + df_z['r_m'] = np.sqrt(df_z['x_m']**2 + df_z['y_m']**2) + df_z['inv_v_z'] = 1/df_z['vz_ms'].abs() + df_z['v_sign'] = np.sign(df_z['vz_ms']) + df_z['v_sign_+'] = df_z['v_sign'].apply(lambda x: 1 if x > 0 else 0) + df_z['v_sign_-'] = df_z['v_sign'].apply(lambda x: 1 if x < 0 else 0) + df_z['E_cut'] = pd.cut(df_z['E_eV'], bins=Ebins, labels = False) + df_z['r_cut'] = pd.cut(df_z['r_m'], bins=rbins, labels = False, include_lowest = True) + + # apply categories and fill empty with 0 + t = df_z.groupby([df_z['E_cut'], df_z['r_cut']])['inv_v_z'].agg([('N','size'), ('inv_v_sum','sum')]) + t['v_sign'] = df_z.groupby([df_z['E_cut'], df_z['r_cut']])['v_sign'].sum() + t['N+'] = df_z.groupby([df_z['E_cut'], df_z['r_cut']])['v_sign_+'].sum() + t['N-'] = df_z.groupby([df_z['E_cut'], df_z['r_cut']])['v_sign_-'].sum() + t = t.reindex( pd.MultiIndex.from_product([np.arange(num_E), + np.arange(num_r)], names=['E_bin', 'r_bin']) ,fill_value=0) + t = t.reset_index() + t['z'] = float(z) + + # transform to df form + a['Emin'] = Ebins[t['E_bin']] + a['Emax'] = Ebins[t['E_bin']+1] + a['Emid'] = Emids[t['E_bin']] + a['rmin'] = rbins[t['r_bin']] + a['rmax'] = rbins[t['r_bin']+1] + a['rmid'] = rmids[t['r_bin']] + a['N'] += t['N'] + a['dndE'] += t['inv_v_sum']/As[t['r_bin']]/sim_time + a['dndE'] = a['dndE'].replace(np.inf, 0) + a['djzabsdE'] += t['N']/As[t['r_bin']]/sim_time + a['djzdE'] += t['v_sign']/As[t['r_bin']]/sim_time + a['N+'] += t['N+'] + a['N-'] += t['N-'] + f.close() + + #append to final df + df = df.append(a) + + df.to_csv(inputpath + "/csv/df_part_e.csv") + print("csv saved to " + inputpath + "/csv/df_part_e.csv") + +def get_csv_part_all(inputpath, sim_time, num_r=1): + + outputpath = inputpath + '/csv' + + try: + os.mkdir(outputpath) + except: + pass + + # def some constants + c_ms = 3e8 + rrange = [0, 0.045] + + # calc bin properties + rbins = np.linspace(0, 0.045, (num_r+1)) + rmids = (rbins[1:] + rbins[:-1])/2 + As = np.pi*rbins[1:]**2 - np.pi*rbins[:-1]**2 + + h5list = get_h5list(inputpath) + + # open one h5 file to get keys + f = h5py.File(h5list[0], 'r') + g = f['Particles']['e-'] + + species = list(f['Particles'].keys()) + zs = list(g.keys()) + f.close() + + + zeros = np.zeros(num_r) + + df = pd.DataFrame() + for s in species: + print (s) + + for z in zs: + # calc properties and calculate categories + #print(z) + a = pd.DataFrame({ + 'species' : s, + 'z' : float(z), + 'rmin' : zeros, + 'rmax' : 0, + 'rmid' : 0, + 'N' : 0, + 'N+' : 0, + 'N-' : 0, + 'n' : 0, + 'jzabs' : 0, + 'jz' : 0, + }) + + + for h5 in h5list[:]: + #print(h5) + f = h5py.File(h5, 'r') + g = f['Particles'][s] + df_z = pd.DataFrame(g[z][:]) + + # calc properties and calc categories + df_z['r_m'] = np.sqrt(df_z['x_m']**2 + df_z['y_m']**2) + df_z['inv_v_z'] = 1/df_z['vz_ms'].abs() + df_z['v_sign'] = np.sign(df_z['vz_ms']) + df_z['v_sign_+'] = df_z['v_sign'].apply(lambda x: 1 if x > 0 else 0) + df_z['v_sign_-'] = df_z['v_sign'].apply(lambda x: 1 if x < 0 else 0) + df_z['r_cut'] = pd.cut(df_z['r_m'], bins=rbins, labels = False, include_lowest = True) + + # apply categories and fill empty with 0 + t = df_z.groupby(df_z['r_cut'])['inv_v_z'].agg([('N','size'), ('inv_v_sum','sum')]) + t['v_sign'] = df_z.groupby([df_z['r_cut']])['v_sign'].sum() + t['N+'] = df_z.groupby(df_z['r_cut'])['v_sign_+'].sum() + t['N-'] = df_z.groupby(df_z['r_cut'])['v_sign_-'].sum() + t = t.reindex(np.arange(num_r) ,fill_value=0) + t.index.name = 'r_bin' + t = t.reset_index() + t['z'] = float(z) + + # transform to df form + a['N'] += t['N'] + a['N+'] += t['N+'] + a['N-'] += t['N-'] + a['n'] += t['inv_v_sum']/As[t['r_bin']]/sim_time + a['n'] = a['n'].replace(np.inf, 0) + a['jzabs'] += t['N']/As[t['r_bin']]/sim_time + a['jz'] += t['v_sign']/As[t['r_bin']]/sim_time + f.close() + + #append to final + df = df.append(a) + + df.to_csv(inputpath + "/csv/df_part_all.csv") + print("csv saved to " + inputpath + "/csv/df_part_all.csv") + + +def get_csv_part_rw(inputpath, sim_time, Vmax = 5, number_points = 100): + + outputpath = inputpath + '/csv' + + try: + os.mkdir(outputpath) + except: + pass + + def get_rw_hits(f, s, sim_time): + def get_mass(s): + m_T = 2.81e9 + if s=='e-': + return 511e3 + elif s=='T+': + return m_T + elif s=='T2+': + return 2*m_T + elif s=='T3+': + return 3*m_T + elif s=='T5+': + return 5*m_T + else: + raise ('Species invalid') + def get_Z(species): + return species.count('+') - species.count('-') + + try: + df_temp = pd.DataFrame(f['Particles'][s]['-3.000000'][:]) + except: + return np.zeros(2*number_points-1) + E = get_mass(s)/2*(df_temp['vx_ms']**2 + df_temp['vy_ms']**2 + df_temp['vz_ms']**2)/3e8/3e8 + N_tot = len(E) + N_hits = N_tot - np.cumsum(np.histogram(E, E_boarders)[0]) + N_hits = np.concatenate((N_tot*np.ones(number_points), N_hits)) + if (get_Z(s) < 0): + N_hits = np.flip(N_hits, axis=0) + I = N_hits * 1.602176462e-19 * get_Z(s) / sim_time * 1e9 + return I + + E_boarders = np.linspace(0, Vmax, number_points) + + h5list = get_h5list(inputpath) + + f = h5py.File(h5list[0], 'r') + + species = list(f['Particles'].keys()) + df_rw = pd.DataFrame() + df_rw['E'] = np.concatenate((-np.flip(E_boarders, axis = 0),E_boarders[1:])) + for s in species: + I = 0 + for h5 in h5list[:]: + f = h5py.File(h5, 'r') + I += get_rw_hits(f, s, sim_time) + f.close() + df_rw[s] = I + df_rw.insert (1, 'total', df_rw.iloc[:,1:].sum(axis = 1)) + df_rw.melt(id_vars = 'E', var_name = 'species', value_name = 'I') + df_rw.to_csv(inputpath + "/csv/df_part_rw.csv") + print("csv saved to " + inputpath + "/csv/df_part_rw.csv") + + +############################################################## + +if (len(sys.argv) != 3): + print ('Error: Too many or too few number of arguments.') + sys.exit() + +print( "This is the name of the script: ", sys.argv[0]) +print( "Number of arguments: ", len(sys.argv)) +print( "The arguments are: " , str(sys.argv)) + +inputpath = sys.argv[1] +sim_time = float(sys.argv[2]) +print("inputpath = ", inputpath) +print("sim_time = ", sim_time) +get_csv_part_e(inputpath, sim_time) +get_csv_part_all(inputpath, sim_time) +get_csv_part_rw(inputpath, sim_time) \ No newline at end of file diff --git a/src/mcelectron-analysis/functions/particles/get_df_part.py b/src/mcelectron-analysis/functions/particles/get_df_part.py index e9ef315..bb86e56 100644 --- a/src/mcelectron-analysis/functions/particles/get_df_part.py +++ b/src/mcelectron-analysis/functions/particles/get_df_part.py @@ -13,6 +13,7 @@ def get_df_part_e(file_path, sim_time, num_E, num_r, Erange = [1e-5, 2e4]): Ebins = pow(10, np.linspace(np.log10(Erange[0]), np.log10(Erange[1]), (num_E+1))) Emids = (Ebins[1:] + Ebins[:-1]/2) Emids = pow(10, (np.log10(Ebins[1:]) + np.log10(Ebins[:-1]))/2) + rbins = np.linspace(0, 0.045, (num_r+1)) rmids = (rbins[1:] + rbins[:-1])/2 As = np.pi*rbins[1:]**2 - np.pi*rbins[:-1]**2 @@ -20,21 +21,28 @@ def get_df_part_e(file_path, sim_time, num_E, num_r, Erange = [1e-5, 2e4]): # open h5 file f = h5py.File(file_path, 'r') g = f['Particles']['e-'] + print(g) df = pd.DataFrame() # iterate over all zs and append to df zs = list(g.keys()) + for z in zs: print (z) # calc properties and calculate categories df_z = pd.DataFrame(g[z][:]) + df_z['E_eV'] = 0.5*me_eV*(df_z.vx_ms**2 + df_z.vy_ms**2 + df_z.vz_ms**2)/c_ms**2 + + + + df_z['r_m'] = np.sqrt(df_z['x_m']**2 + df_z['y_m']**2) df_z['inv_v_z'] = 1/df_z['vz_ms'].abs() df_z['v_sign'] = np.sign(df_z['vz_ms']) df_z['E_cut'] = pd.cut(df_z['E_eV'], bins=Ebins, labels = False) df_z['r_cut'] = pd.cut(df_z['r_m'], bins=rbins, labels = False, include_lowest = True) - + print("calc properties and calculatre categoreies fertig") # apply categories and fill empty with 0 #t = df_z['inv_v_z'].groupby([df_z['E_cut'], df_z['r_cut']]).agg(N=np.size,inv_v_sum=np.sum) t = df_z.groupby([df_z['E_cut'], df_z['r_cut']])['inv_v_z'].agg([('N','size'), ('inv_v_sum','sum')]) @@ -43,7 +51,7 @@ def get_df_part_e(file_path, sim_time, num_E, num_r, Erange = [1e-5, 2e4]): np.arange(num_r)], names=['E_bin', 'r_bin']) ,fill_value=0) t = t.reset_index() t['z'] = float(z) - + print("apply categoires and fill empty with 0 fertig") # transform to df form a = pd.DataFrame({ 'z' : t['z'], @@ -58,11 +66,16 @@ def get_df_part_e(file_path, sim_time, num_E, num_r, Erange = [1e-5, 2e4]): 'djzabsdE' : 0, 'djzdE' : 0, }) - a['dndE'] = t['inv_v_sum']/As[t['r_bin']]/sim_time/(a['Emax']-a['Emin']) + #a['dndE'] = t['inv_v_sum']/As[t['r_bin']]/sim_time/(a['Emax']-a['Emin']) + a['dndE'] = t['inv_v_sum']/As[t['r_bin']]/sim_time a['dndE'] = a['dndE'].replace(np.inf, 0) - a['djzabsdE'] = t['N']/As[t['r_bin']]/sim_time/(a['Emax']-a['Emin']) - a['djzdE'] = t['v_sign']/As[t['r_bin']]/sim_time/(a['Emax']-a['Emin']) + #a['djzabsdE'] = t['N']/As[t['r_bin']]/sim_time/(a['Emax']-a['Emin']) + a['djzabsdE'] = t['N']/As[t['r_bin']]/sim_time + #a['djzdE'] = t['v_sign']/As[t['r_bin']]/sim_time/(a['Emax']-a['Emin']) + a['djzdE'] = t['v_sign']/As[t['r_bin']]/sim_time df = df.append(a) #append to final + print("transform to df form fertig ") + print("get_df_part_e fertig") return df def get_df_part_all(file_path, sim_time, num_r): @@ -120,6 +133,7 @@ def get_df_part_all(file_path, sim_time, num_r): a['jz'] = t['v_sign']/As[t['r_bin']]/sim_time df = df.append(a) #append to final + print("get_df_part_all fertig") return df def get_df_part_rw(file_path, sim_time, Vmax = 5, number_points = 100): @@ -165,6 +179,7 @@ def get_df_part_rw(file_path, sim_time, Vmax = 5, number_points = 100): I = get_rw_hits(f, s, sim_time) df_rw[s] = I df_rw.insert (1, 'total', df_rw.iloc[:,1:].sum(axis = 1)) + print("get_df_part_rw fertig") return df_rw.melt(id_vars = 'E', var_name = 'species', value_name = 'I') @@ -223,9 +238,13 @@ def get_df_part_e_vz(file_path, sim_time, num_vz, num_r, vzrange = [1e-5, 1e9]): 'djzabsdvz' : 0, 'djzdvz' : 0, }) - a['dndE'] = t['inv_v_sum']/As[t['r_bin']]/sim_time/(a['vzmax']-a['vzmin']) + #a['dndE'] = t['inv_v_sum']/As[t['r_bin']]/sim_time/(a['vzmax']-a['vzmin']) + a['dndE'] = t['inv_v_sum']/As[t['r_bin']]/sim_time a['dndE'] = a['dndE'].replace(np.inf, 0) - a['djzabsdvz'] = t['N']/As[t['r_bin']]/sim_time/(a['vzmax']-a['vzmin']) - a['djzdvz'] = t['v_sign']/As[t['r_bin']]/sim_time/(a['vzmax']-a['vzmin']) + #a['djzabsdvz'] = t['N']/As[t['r_bin']]/sim_time/(a['vzmax']-a['vzmin']) + a['djzabsdvz'] = t['N']/As[t['r_bin']]/sim_time + #a['djzdvz'] = t['v_sign']/As[t['r_bin']]/sim_time/(a['vzmax']-a['vzmin']) + a['djzdvz'] = t['v_sign']/As[t['r_bin']]/sim_time df = df.append(a) #append to final + print("get_df_part_vz fertig") return df \ No newline at end of file diff --git a/src/mcelectron-analysis/functions/particles/plot_df_part.py b/src/mcelectron-analysis/functions/particles/plot_df_part.py index 4be9880..2793e5f 100644 --- a/src/mcelectron-analysis/functions/particles/plot_df_part.py +++ b/src/mcelectron-analysis/functions/particles/plot_df_part.py @@ -51,7 +51,7 @@ def plot_part_e_dndE_z3(df_part_e, ax): ax.set_ylabel (r'Diff. e$^-$ density dn/dE (m$^{-3}$ eV$^{-1}$)') handles, labels = ax.get_legend_handles_labels() ax.legend(handles=handles[1:], labels=labels[1:]) - + print("plot_part_e_dndE_z3 fertig") def plot_part_e_dndE_zmid(df_part_e, ax): df_plot = df_part_e[(df_part_e['z']== 5)] @@ -61,7 +61,7 @@ def plot_part_e_dndE_zmid(df_part_e, ax): ax.set_yscale('log') ax.set_xlabel ('Electron energy (eV)') ax.set_ylabel (r'Diff. e$^-$ density dn/dE (m$^{-3}$ eV$^{-1}$)') - + print("plot_part_e_dndE_zmid fertig") def plot_part_e_dndE_hm(df_part_e, fig, ax): df_temp = df_part_e[['z','Emid', 'dndE']].groupby(['z', 'Emid'], as_index = False).mean() @@ -93,7 +93,7 @@ def plot_part_e_dndE_hm(df_part_e, fig, ax): ax.spines['bottom'].set_visible(False) ax.spines['right'].set_visible(False) ax.spines['left'].set_visible(False) - + print("plot_part_e_dndE_hm fertig") def plot_part_e_djzdE_z3(df_part_e, ax): df_plot = df_part_e[(df_part_e['z']== -3) | (df_part_e['z']== 5) | (df_part_e['z']== 10)] @@ -110,7 +110,7 @@ def plot_part_e_djzdE_z3(df_part_e, ax): handles, labels = ax.get_legend_handles_labels() ax.legend(handles=handles[1:], labels=labels[1:]) - + print("plot_part_e_dndE_z3 fertig") def plot_part_n_z(df_part_all, ax): sns.lineplot(ax = ax, x="z", y="n", style = 'species', hue = 'species', data=df_part_all, err_style=None) @@ -122,7 +122,7 @@ def plot_part_n_z(df_part_all, ax): handles, labels = ax.get_legend_handles_labels() ax.legend(handles=handles[1:], labels=labels[1:]) - + print("plot_part_n_z fertig") def plot_part_jz_z(df_part_all, ax): sns.lineplot(ax = ax, x="z", y="jz", style = 'species', hue = 'species', data=df_part_all, err_style=None) @@ -134,7 +134,7 @@ def plot_part_jz_z(df_part_all, ax): handles, labels = ax.get_legend_handles_labels() ax.legend(handles=handles[1:], labels=labels[1:]) - + print("plot_part_jz_z fertig") def plot_part_iz_z(df_part_all, ax): def get_charge(species): @@ -156,7 +156,7 @@ def plot_part_iz_z(df_part_all, ax): handles, labels = ax.get_legend_handles_labels() ax.legend(handles=handles[1:], labels=labels[1:]) - + print("plot_part_iz_z fertig") def plot_part_rw(df_part_rw, ax): sns.lineplot(ax = ax, x="E", y="I", style = 'species', hue = 'species', data=df_part_rw, err_style=None) @@ -168,7 +168,8 @@ def plot_part_rw(df_part_rw, ax): handles, labels = ax.get_legend_handles_labels() ax.legend(handles=handles[1:], labels=labels[1:]) - + print("plot_part_rw fertig") + def plot_part_rw_zoom(df_part_rw_zoom, ax): sns.lineplot(ax = ax, x="E", y="I", style = 'species', hue = 'species', data=df_part_rw_zoom, err_style=None) ax.set_xscale('linear') @@ -179,3 +180,4 @@ def plot_part_rw_zoom(df_part_rw_zoom, ax): handles, labels = ax.get_legend_handles_labels() ax.legend(handles=handles[1:], labels=labels[1:]) + print("plot_part_rw_zoom fertig") \ No newline at end of file diff --git a/src/mcelectron-analysis/functions/populations/get_df_pop.py b/src/mcelectron-analysis/functions/populations/get_df_pop.py index a32c786..12a7e76 100644 --- a/src/mcelectron-analysis/functions/populations/get_df_pop.py +++ b/src/mcelectron-analysis/functions/populations/get_df_pop.py @@ -6,7 +6,7 @@ def get_df_pop(file_path): def append_V_m3 (df_meta): A_m2 = np.pi*(df_meta.r_max_m**2-df_meta.r_min_m**2)*(df_meta.phi_max-df_meta.phi_min)/2/np.pi V_m3 = A_m2*(df_meta.z_max_m-df_meta.z_min_m) - df_meta.insert(len(df_meta.columns),'V_m3',V_m3) + df_meta.insert(len(df_meta.columns),'V_m3',V_m3) return df_meta def get_V_m3(df_meta): @@ -72,5 +72,5 @@ def get_df_pop(file_path): 'n': df_data['n_m3'] }) df = df.append(a) #append to final - + return (df) \ No newline at end of file diff --git a/src/mcelectron-analysis/functions/populations/plot_df_pop.py b/src/mcelectron-analysis/functions/populations/plot_df_pop.py index 3375d3c..888028e 100644 --- a/src/mcelectron-analysis/functions/populations/plot_df_pop.py +++ b/src/mcelectron-analysis/functions/populations/plot_df_pop.py @@ -63,14 +63,15 @@ def plot_pop_n_z(df_pop, ax): handles, labels = ax.get_legend_handles_labels() ax.legend(handles=handles[1:], labels=labels[1:]) - + print("plot_pop_n_z") def plot_pop_e_dndE_z3(df_pop, ax): t_max = np.sort(df_pop.t.unique())[-1] df_plot = df_pop[(df_pop.species == 'e-') & (df_pop.t == t_max)] df_plot['zmid'] = (df_plot['zmin']+df_plot['zmax'])/2 df_plot['Emid'] = (df_plot['Emin']+df_plot['Emax'])/2 - df_plot['dndE'] = df_plot['n']/(df_plot['Emax'] - df_plot['Emin']) + #df_plot['dndE'] = df_plot['n']/(df_plot['Emax'] - df_plot['Emin']) + df_plot['dndE'] = df_plot['n'] df_plot = df_plot.groupby(['zmid','Emid'], as_index = False).dndE.mean() df_plot = df_plot[ (abs(df_plot['zmid'] - -2.675) < 1e-1) | @@ -98,14 +99,15 @@ def plot_pop_e_dndE_z3(df_pop, ax): ax.set_ylabel (r'Diff. e$^-$ density dn/dE (m$^{-3}$ eV$^{-1}$)') handles, labels = ax.get_legend_handles_labels() ax.legend(handles=handles[1:], labels=labels[1:]) - + print("plot_pop_e_dndE_z3 fertig") def plot_pop_e_dndE_zmid(df_pop, ax): t_max = np.sort(df_pop.t.unique())[-1] df_plot = df_pop[(df_pop.species == 'e-') & (df_pop.t == t_max)] df_plot['zmid'] = (df_plot['zmin']+df_plot['zmax'])/2 df_plot['Emid'] = (df_plot['Emin']+df_plot['Emax'])/2 - df_plot['dndE'] = df_plot['n']/(df_plot['Emax'] - df_plot['Emin']) + #df_plot['dndE'] = df_plot['n']/(df_plot['Emax'] - df_plot['Emin']) + df_plot['dndE'] = df_plot['n'] df_plot = df_plot.groupby(['zmid','Emid'], as_index = False).dndE.mean() df_plot = df_plot[abs(df_plot['zmid'] - 5.125) < 1e-1] @@ -116,3 +118,4 @@ def plot_pop_e_dndE_zmid(df_pop, ax): ax.set_xlabel ('Electron energy (eV)') ax.set_ylabel (r'Diff. e$^-$ density dn/dE (m$^{-3}$ eV$^{-1}$)') + print("plot_pop_e_dndE_zmid fertig") \ No newline at end of file diff --git a/src/mcelectron-analysis/scripts/get_csv.py b/src/mcelectron-analysis/scripts/get_csv.py new file mode 100644 index 0000000..8bb9523 --- /dev/null +++ b/src/mcelectron-analysis/scripts/get_csv.py @@ -0,0 +1,23 @@ +import sys +import os +import glob + +import h5py + + + +if (len(sys.argv) != 3): + print ('Error: Too many or too few number of arguments.') + sys.exit() + +print( "This is the name of the script: ", sys.argv[0]) +print( "Number of arguments: ", len(sys.argv)) +print( "The arguments are: " , str(sys.argv)) + +inputpath = sys.argv[1] +sim_time = sys.argv[2] +print("inputpath = ", inputpath) +print("sim_time = ", sim_time) + +import get_csv_part +get_csv_part_e(inputpath, sim_time) \ No newline at end of file diff --git a/src/mcelectron-analysis/scripts/merge.py b/src/mcelectron-analysis/scripts/merge.py index b14ebdc..dba11be 100644 --- a/src/mcelectron-analysis/scripts/merge.py +++ b/src/mcelectron-analysis/scripts/merge.py @@ -4,6 +4,7 @@ import sys import os import glob + import h5py base_dir = os.path.dirname(os.path.realpath(__file__)) + '/..'