Elastic scattering drift and current logger
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
import numpy as np
|
||||
import matplotlib
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
import functions.calculate_currents_from_karl as cc
|
||||
import functions.plot_standards as pst
|
||||
|
||||
|
||||
def plotCurrentRVsR(filename_current, filename_density, output_folder, z_pos):
|
||||
#species_keys = ["/e-", "/T+", "/T2+", "/T3+"]
|
||||
|
||||
pst.setRcParams()
|
||||
prop_cycle = plt.rcParams['axes.prop_cycle']
|
||||
colors = prop_cycle.by_key()['color']
|
||||
|
||||
e_dict = {"key" : "/e-", "linestyle": '-', "label": "e"}
|
||||
T3_dict = {"key" : "/T3+", "linestyle": '--', "label": "T3+"}
|
||||
dicts = [e_dict, T3_dict]
|
||||
|
||||
fig, ax = plt.subplots(figsize=pst.set_size('thesis'))
|
||||
|
||||
for d in dicts:
|
||||
j_total_r = cc.particleCurrentR(filename_current, filename_density, d["key"])
|
||||
r_bins = cc.binBordersR(filename_current, d["key"])
|
||||
z_bins = cc.binBordersZ(filename_current, d["key"])
|
||||
|
||||
z_bin = np.abs((z_bins-z_pos)).argmin()
|
||||
|
||||
plot_data = np.sum(j_total_r,2)[:,z_bin]
|
||||
x_mins = r_bins[:-1]
|
||||
x_maxs = r_bins[1:]
|
||||
plot_bins, plot_datas = cc.makeBarPlotData(plot_data, x_mins, x_maxs)
|
||||
|
||||
ax.plot(plot_bins, plot_datas, linestyle=d["linestyle"], label=d["label"])
|
||||
|
||||
ax.set_xlabel(r"Radius $r$ [m]")
|
||||
ax.set_ylabel(r"Particle Current $j_r$ [$m^{-2}s^{-1}$]")
|
||||
|
||||
ax.set_facecolor('#e7e7e7ff')
|
||||
ax.grid(color='white')
|
||||
|
||||
ax.legend(loc="upper right")
|
||||
|
||||
filename_output = output_folder + 'jr_vs_r.pdf'
|
||||
fig.savefig(filename_output, format='pdf', bbox_inches='tight')
|
||||
|
||||
def plotCurrentZVsR(filename_current, filename_density, output_folder, z_pos):
|
||||
#species_keys = ["/e-", "/T+", "/T2+", "/T3+"]
|
||||
|
||||
pst.setRcParams()
|
||||
prop_cycle = plt.rcParams['axes.prop_cycle']
|
||||
colors = prop_cycle.by_key()['color']
|
||||
|
||||
e_dict = {"key" : "/e-", "linestyle": '-', "label": "e"}
|
||||
T3_dict = {"key" : "/T3+", "linestyle": '--', "label": "T3+"}
|
||||
dicts = [e_dict, T3_dict]
|
||||
|
||||
fig, ax = plt.subplots(figsize=pst.set_size('thesis'))
|
||||
|
||||
for d in dicts:
|
||||
j_total_z = cc.particleCurrentZ(filename_current, filename_density, d["key"])
|
||||
r_bins = cc.binBordersR(filename_current, d["key"])
|
||||
z_bins = cc.binBordersZ(filename_current, d["key"])
|
||||
|
||||
z_bin = np.abs((z_bins-z_pos)).argmin()
|
||||
|
||||
plot_data = np.sum(j_total_z,2)[:,z_bin]
|
||||
x_mins = r_bins[:-1]
|
||||
x_maxs = r_bins[1:]
|
||||
plot_bins, plot_datas = cc.makeBarPlotData(plot_data, x_mins, x_maxs)
|
||||
|
||||
ax.plot(plot_bins, plot_datas, linestyle=d["linestyle"], label=d["label"])
|
||||
|
||||
ax.set_xlabel(r"Radius $r$ [m]")
|
||||
ax.set_ylabel(r"Particle Current $j_z$ [$m^{-2}s^{-1}$]")
|
||||
|
||||
ax.set_facecolor('#e7e7e7ff')
|
||||
ax.grid(color='white')
|
||||
|
||||
ax.legend(loc="upper right")
|
||||
|
||||
filename_output = output_folder + 'jz_vs_r.pdf'
|
||||
fig.savefig(filename_output, format='pdf', bbox_inches='tight')
|
||||
@@ -0,0 +1,71 @@
|
||||
import numpy as np
|
||||
import matplotlib
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
import functions.calculate_currents_from_karl as cc
|
||||
import functions.plot_standards as pst
|
||||
|
||||
def plotTubeCurrentVsZ(filename_current, filename_density, output_folder):
|
||||
#species_keys = ["/e-", "/T+", "/T2+", "/T3+"]
|
||||
|
||||
pst.setRcParams()
|
||||
prop_cycle = plt.rcParams['axes.prop_cycle']
|
||||
colors = prop_cycle.by_key()['color']
|
||||
|
||||
e_dict = {"key" : "/e-", "linestyle": '-', "label": "e"}
|
||||
T3_dict = {"key" : "/T3+", "linestyle": '--', "label": "T3+"}
|
||||
dicts = [e_dict, T3_dict]
|
||||
|
||||
fig, ax = plt.subplots(figsize=pst.set_size('thesis'))
|
||||
|
||||
for d in dicts:
|
||||
j_total = cc.particleCurrentR(filename_current, filename_density, d["key"])
|
||||
z_bins = cc.binBordersZ(filename_current, d["key"])
|
||||
|
||||
plot_data = np.sum(j_total,2)[-1,:]
|
||||
x_mins = z_bins[:-1]
|
||||
x_maxs = z_bins[1:]
|
||||
plot_bins, plot_datas = cc.makeBarPlotData(plot_data, x_mins, x_maxs)
|
||||
|
||||
ax.plot(plot_bins, plot_datas, linestyle=d["linestyle"], label=d["label"])
|
||||
|
||||
ax.set_xlabel(r"Position $z$ [m]")
|
||||
ax.set_ylabel(r"Particle Current $j_r$ [$m^{-2}s^{-1}$]")
|
||||
|
||||
ax.set_facecolor('#e7e7e7ff')
|
||||
ax.grid(color='white')
|
||||
|
||||
ax.legend(loc="upper right")
|
||||
|
||||
filename_output = output_folder + 'tube_current_vs_z.pdf'
|
||||
fig.savefig(filename_output, format='pdf', bbox_inches='tight')
|
||||
|
||||
def plotLongitudinalCurrentVsZ(filename_current, filename_density, output_folder):
|
||||
|
||||
e_dict = {"key" : "/e-", "linestyle": '-', "label": "e"}
|
||||
T3_dict = {"key" : "/T3+", "linestyle": '--', "label": "T3+"}
|
||||
dicts = [e_dict, T3_dict]
|
||||
|
||||
pst.setRcParams()
|
||||
prop_cycle = plt.rcParams['axes.prop_cycle']
|
||||
colors = prop_cycle.by_key()['color']
|
||||
|
||||
fig, ax = plt.subplots(figsize=pst.set_size('thesis'))
|
||||
|
||||
for d in dicts:
|
||||
j_total = cc.particleCurrentZ(filename_current, filename_density, d["key"])
|
||||
z_bins = cc.binBordersZ(filename_current, d["key"])
|
||||
|
||||
plot_data = np.sum(np.sum(j_total,2),0)
|
||||
ax.plot(z_bins, plot_data, linestyle=d["linestyle"], label=d["label"])
|
||||
|
||||
ax.set_xlabel(r"Position $z$ [m]")
|
||||
ax.set_ylabel(r"Particle Current $j_z$ [$m^{-2}s^{-1}$]")
|
||||
|
||||
ax.set_facecolor('#e7e7e7ff')
|
||||
ax.grid(color='white')
|
||||
|
||||
ax.legend(loc="lower right")
|
||||
|
||||
filename_output = output_folder + 'jz_vs_z.pdf'
|
||||
fig.savefig(filename_output, format='pdf', bbox_inches='tight')
|
||||
@@ -0,0 +1,78 @@
|
||||
import numpy as np
|
||||
import h5py as h5py
|
||||
import os
|
||||
import sys
|
||||
import matplotlib
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
from functions.calculate_density_from_karl import *
|
||||
import functions.plot_standards as pst
|
||||
|
||||
def makeBarPlotData(data, mins, maxs):
|
||||
plot_bins = np.dstack((mins,maxs)).flatten()
|
||||
plot_datas = np.dstack((data,data)).flatten()
|
||||
return plot_bins, plot_datas
|
||||
|
||||
def plotAllDensityVsZ(filename, filename_output):
|
||||
keys = ["/Populations/e-/e-", "/Populations/T+/T+", "/Populations/T2+/T2+", "/Populations/T3+/T3+"]
|
||||
|
||||
density_e = getDensities(filename, keys[0])
|
||||
density_T = getDensities(filename, keys[1])
|
||||
density_T2 = getDensities(filename, keys[2])
|
||||
density_T3 = getDensities(filename, keys[3])
|
||||
|
||||
zmins = getZBinsMin(filename, keys[0])
|
||||
zmaxs = getZBinsMax(filename, keys[0])
|
||||
Emins = getEBinsMin(filename, keys[0])
|
||||
Emaxs = getEBinsMax(filename, keys[0])
|
||||
|
||||
total_density_e = np.sum(density_e,3)
|
||||
total_density_e = np.sum(total_density_e,2)
|
||||
total_density_e = np.sum(total_density_e,1)
|
||||
|
||||
print("Total density e-: ")
|
||||
print(total_density_e)
|
||||
|
||||
total_density_T = np.sum(density_T,3)
|
||||
total_density_T = np.sum(total_density_T,2)
|
||||
total_density_T = np.sum(total_density_T,1)
|
||||
|
||||
total_density_T2 = np.sum(density_T2,3)
|
||||
total_density_T2 = np.sum(total_density_T2,2)
|
||||
total_density_T2 = np.sum(total_density_T2,1)
|
||||
|
||||
total_density_T3 = np.sum(density_T3,3)
|
||||
total_density_T3 = np.sum(total_density_T3,2)
|
||||
total_density_T3 = np.sum(total_density_T3,1)
|
||||
|
||||
print("Total density T3+: ")
|
||||
print(total_density_T3)
|
||||
|
||||
pst.setRcParams()
|
||||
prop_cycle = plt.rcParams['axes.prop_cycle']
|
||||
colors = prop_cycle.by_key()['color']
|
||||
|
||||
fig, ax = plt.subplots(figsize=pst.set_size('thesis'))
|
||||
|
||||
plot_bins, plot_data = makeBarPlotData(total_density_e, zmins, zmaxs)
|
||||
ax.plot(plot_bins, plot_data,'-', label="e-")
|
||||
|
||||
plot_bins, plot_data = makeBarPlotData(total_density_T3, zmins, zmaxs)
|
||||
ax.plot(plot_bins, plot_data, '--', label=r'T$^+_3$')
|
||||
|
||||
plot_bins, plot_data = makeBarPlotData(total_density_T, zmins, zmaxs)
|
||||
ax.plot(plot_bins, plot_data, '-.', label=r'T$^+_2$')
|
||||
|
||||
plot_bins, plot_data = makeBarPlotData(total_density_T2, zmins, zmaxs)
|
||||
ax.plot(plot_bins, plot_data, ':', label=r'T$^+$')
|
||||
|
||||
ax.set_yscale("log")
|
||||
ax.set_xlabel(r"Position $z$ [m]")
|
||||
ax.set_ylabel(r"Density $n$ [$m^{-3}$]")
|
||||
|
||||
ax.set_facecolor('#e7e7e7ff')
|
||||
ax.grid(color='white')
|
||||
|
||||
ax.legend(loc="lower right")
|
||||
|
||||
fig.savefig(filename_output, format='pdf', bbox_inches='tight')
|
||||
@@ -0,0 +1,65 @@
|
||||
import numpy as np
|
||||
import h5py as h5py
|
||||
import os
|
||||
import sys
|
||||
import matplotlib
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
from functions.calculate_density_from_karl import *
|
||||
import functions.plot_standards as pst
|
||||
|
||||
def makeBarPlotData(data, mins, maxs):
|
||||
plot_bins = np.dstack((mins,maxs)).flatten()
|
||||
plot_datas = np.dstack((data,data)).flatten()
|
||||
return plot_bins, plot_datas
|
||||
|
||||
|
||||
def plotElectronDensityVsE(filename, z_rearwall, z_mid, z_dps, filename_output):
|
||||
keys = ["/Populations/e-/e-", "/Populations/T+/T+", "/Populations/T2+/T2+", "/Populations/T3+/T3+"]
|
||||
|
||||
k = keys[0]
|
||||
density = getDensities(filename, k)
|
||||
zmins = getZBinsMin(filename, k)
|
||||
zmaxs = getZBinsMax(filename, k)
|
||||
Emins = getEBinsMin(filename, k)
|
||||
Emaxs = getEBinsMax(filename, k)
|
||||
|
||||
rw_z_index = np.where(zmins <= z_rearwall)[-1][-1]
|
||||
mid_z_index = np.where(zmins <= z_mid)[-1][-1]
|
||||
dps_z_index = np.where(zmins <= z_dps)[-1][-1]
|
||||
|
||||
density_sum = np.sum(density,2)
|
||||
density_sum = np.sum(density_sum,1)
|
||||
|
||||
density_rw = density_sum[rw_z_index,:]
|
||||
density_mid = density_sum[mid_z_index,:]
|
||||
density_dps = density_sum[dps_z_index,:]
|
||||
|
||||
pst.setRcParams()
|
||||
prop_cycle = plt.rcParams['axes.prop_cycle']
|
||||
colors = prop_cycle.by_key()['color']
|
||||
|
||||
fig, ax = plt.subplots(figsize=pst.set_size('thesis'))
|
||||
|
||||
plot_bins, plot_data = makeBarPlotData(density_mid, Emins, Emaxs)
|
||||
ax.plot(plot_bins, plot_data, '-', label="Mid")
|
||||
|
||||
plot_bins, plot_data = makeBarPlotData(density_rw, Emins, Emaxs)
|
||||
ax.plot(plot_bins, plot_data,'--', label="Rearwall")
|
||||
|
||||
plot_bins, plot_data = makeBarPlotData(density_dps, Emins, Emaxs)
|
||||
ax.plot(plot_bins, plot_data, '-.', label="DPS")
|
||||
|
||||
ax.set_yscale("log")
|
||||
ax.set_xscale("log")
|
||||
ax.set_xlabel(r"Energy $E$ [eV]")
|
||||
ax.set_ylabel(r"Density $n_e$ [$m^{-3}$]")
|
||||
|
||||
ax.set_xlim(1E-5, 2E4)
|
||||
|
||||
ax.set_facecolor('#e7e7e7ff')
|
||||
ax.grid(color='white')
|
||||
|
||||
ax.legend()
|
||||
|
||||
fig.savefig(filename_output, format='pdf', bbox_inches='tight')
|
||||
@@ -0,0 +1,82 @@
|
||||
import numpy as np
|
||||
import h5py as h5py
|
||||
import os
|
||||
import sys
|
||||
import matplotlib
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
from functions.calculate_density_from_karl import *
|
||||
import functions.plot_standards as pst
|
||||
|
||||
def makeBarPlotData(data, mins, maxs):
|
||||
plot_bins = np.dstack((mins,maxs)).flatten()
|
||||
plot_datas = np.dstack((data,data)).flatten()
|
||||
return plot_bins, plot_datas
|
||||
|
||||
|
||||
def plotElectronDensityVsZ(filename, E_th_max, E_beta_min, filename_output):
|
||||
keys = ["/Populations/e-/e-", "/Populations/T+/T+", "/Populations/T2+/T2+", "/Populations/T3+/T3+"]
|
||||
|
||||
k = keys[0]
|
||||
density = getDensities(filename, k)
|
||||
zmins = getZBinsMin(filename, k)
|
||||
zmaxs = getZBinsMax(filename, k)
|
||||
Emins = getEBinsMin(filename, k)
|
||||
Emaxs = getEBinsMax(filename, k)
|
||||
|
||||
thermal_energy = E_th_max
|
||||
thermal_energy_index = np.where(Emins <= thermal_energy)[-1][-1]
|
||||
thermal_density = np.sum(density[:,:,:,0:thermal_energy_index],3)
|
||||
thermal_density = np.sum(thermal_density,2)
|
||||
thermal_density = np.sum(thermal_density,1)
|
||||
|
||||
print("thermal density: ")
|
||||
print(thermal_density)
|
||||
|
||||
beta_energy = E_beta_min
|
||||
beta_energy_index = np.where(Emins >= beta_energy)[-1][-1]
|
||||
beta_density = np.sum(density[:,:,:,beta_energy_index:],3)
|
||||
beta_density = np.sum(beta_density, 2)
|
||||
beta_density = np.sum(beta_density, 1)
|
||||
|
||||
print("beta density: ")
|
||||
print(beta_density)
|
||||
|
||||
secondary_density = np.sum(density[:,:,:,thermal_energy_index+1:beta_energy_index-1],3)
|
||||
secondary_density = np.sum(secondary_density, 2)
|
||||
secondary_density = np.sum(secondary_density, 1)
|
||||
|
||||
total_density = np.sum(density,3)
|
||||
total_density = np.sum(total_density,2)
|
||||
total_density = np.sum(total_density, 1)
|
||||
|
||||
|
||||
pst.setRcParams()
|
||||
prop_cycle = plt.rcParams['axes.prop_cycle']
|
||||
colors = prop_cycle.by_key()['color']
|
||||
|
||||
fig, ax = plt.subplots(figsize=pst.set_size('thesis'))
|
||||
|
||||
# uncomment if plot with total density
|
||||
#plot_bins, plot_data = makeBarPlotData(total_density, zmins, zmaxs)
|
||||
#plt.plot(plot_bins, plot_data)
|
||||
|
||||
plot_bins, plot_data = makeBarPlotData(thermal_density, zmins, zmaxs)
|
||||
ax.plot(plot_bins, plot_data,'-', label="thermal")
|
||||
|
||||
plot_bins, plot_data = makeBarPlotData(beta_density, zmins, zmaxs)
|
||||
ax.plot(plot_bins, plot_data, '--', label="beta")
|
||||
|
||||
plot_bins, plot_data = makeBarPlotData(secondary_density, zmins, zmaxs)
|
||||
ax.plot(plot_bins, plot_data, '-.', label="secondary")
|
||||
|
||||
ax.set_yscale("log")
|
||||
ax.set_xlabel(r"Position $z$ [m]")
|
||||
ax.set_ylabel(r"Density $n_e$ [$m^{-3}$]")
|
||||
|
||||
ax.set_facecolor('#e7e7e7ff')
|
||||
ax.grid(color='white')
|
||||
|
||||
ax.legend()
|
||||
|
||||
fig.savefig(filename_output, format='pdf', bbox_inches='tight')
|
||||
@@ -0,0 +1,34 @@
|
||||
import numpy as np
|
||||
import sys
|
||||
import os
|
||||
|
||||
homebase = os.getenv('HOMEBASE')
|
||||
if homebase is None:
|
||||
homebase = "/home/jonas/new_workspace/Coding/KARL/karl"
|
||||
sys.path.append(homebase+"/src/tools/analysis_jkellerer")
|
||||
|
||||
import functions.calculate_currents_from_karl as ic
|
||||
import currents.plot_current_vs_z as pcz
|
||||
import currents.plot_current_vs_r as pcr
|
||||
|
||||
#filename = "/hppfs/work/pn68gi/di67ham/KARL/CurrentBoundaries/parameter_20210328_1/mc_electron_out_"
|
||||
#num_cpu = 1392
|
||||
|
||||
|
||||
|
||||
#ic.mergeOutputs(filename, num_cpu, "/T3+")
|
||||
#ic.mergeOutputs(filename, num_cpu, "/T2+")
|
||||
#ic.mergeOutputs(filename, num_cpu, "/T+")
|
||||
#ic.mergeOutputs(filename, num_cpu, "/e-")
|
||||
|
||||
folder = "/home/jonas/new_workspace/Coding/Output/KARL/ElectricField/parameter_20210331_11/"
|
||||
filename_current = folder+"mc_electron_out_0_currents.h5"
|
||||
filename_density = folder+"mc_electron_out_0.h5"
|
||||
|
||||
output_folder = "/home/jonas/new_workspace/Coding/Output/KARL/ElectricField/plots/"
|
||||
|
||||
pcz.plotTubeCurrentVsZ(filename_current, filename_density, output_folder)
|
||||
pcz.plotLongitudinalCurrentVsZ(filename_current, filename_density, output_folder)
|
||||
|
||||
pcr.plotCurrentRVsR(filename_current, filename_density, output_folder, 5)
|
||||
pcr.plotCurrentZVsR(filename_current, filename_density, output_folder, 5)
|
||||
@@ -0,0 +1,176 @@
|
||||
import numpy as np
|
||||
import h5py as h5py
|
||||
import os
|
||||
import sys
|
||||
import matplotlib
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
|
||||
def NPosZ(filename, specie_key):
|
||||
file = h5py.File(filename, 'r')
|
||||
key = specie_key + "/N_pos_z"
|
||||
ar = np.array(file[key],dtype=np.long)
|
||||
file.close()
|
||||
return ar
|
||||
|
||||
def NNegZ(filename, specie_key):
|
||||
file = h5py.File(filename, 'r')
|
||||
key = specie_key + "/N_neg_z"
|
||||
ar = np.array(file[key],dtype=np.long)
|
||||
file.close()
|
||||
return ar
|
||||
|
||||
def NPosR(filename, specie_key):
|
||||
file = h5py.File(filename, 'r')
|
||||
key = specie_key + "/N_pos_r"
|
||||
ar = np.array(file[key],dtype=np.long)
|
||||
file.close()
|
||||
return ar
|
||||
|
||||
def NNegR(filename, specie_key):
|
||||
file = h5py.File(filename, 'r')
|
||||
key = specie_key + "/N_neg_r"
|
||||
ar = np.array(file[key],dtype=np.long)
|
||||
file.close()
|
||||
return ar
|
||||
|
||||
def binBordersE(filename, specie_key):
|
||||
file = h5py.File(filename, 'r')
|
||||
key = specie_key + "/current_bin_borders/bin_borders_E"
|
||||
ar = np.array(file[key])
|
||||
file.close()
|
||||
return ar
|
||||
|
||||
def binBordersZ(filename, specie_key):
|
||||
file = h5py.File(filename, 'r')
|
||||
key = specie_key + "/current_bin_borders/bin_borders_z"
|
||||
ar = np.array(file[key])
|
||||
file.close()
|
||||
return ar
|
||||
|
||||
def binBordersR(filename, specie_key):
|
||||
file = h5py.File(filename, 'r')
|
||||
key = specie_key + "/current_bin_borders/bin_borders_r"
|
||||
ar = np.array(file[key])
|
||||
file.close()
|
||||
return ar
|
||||
|
||||
def sumEnergyBins(current_data):
|
||||
return np.sum(current_data,2)
|
||||
|
||||
def sumRadiusBins(current_data):
|
||||
return np.sum(current_data,0)
|
||||
|
||||
def sumZBins(current_data):
|
||||
return np.sum(current_data,1)
|
||||
|
||||
def projectionZ(current_data):
|
||||
return sumRadiusBins(sumEnergyBins(current_data))
|
||||
|
||||
def projectionR(current_data):
|
||||
return sumZBins(sumEnergyBins(current_data))
|
||||
|
||||
def totalCurrentZ(n_pos, n_neg):
|
||||
return n_pos[:,:-1,:]-n_neg[:,1:,:]
|
||||
|
||||
def totalCurrentR(n_pos, n_neg):
|
||||
return n_pos[:-1,1:,:]-n_neg[1:,1:,:]
|
||||
|
||||
def binAreasR(bin_borders_r, bin_borders_z):
|
||||
areas = 2*np.pi* np.outer(bin_borders_r[1:], (bin_borders_z[1:]-bin_borders_z[:-1]))
|
||||
return areas
|
||||
|
||||
def binAreasZ(bin_borders_r, bin_borders_z):
|
||||
areas = np.pi * np.outer((bin_borders_r[1:]*bin_borders_r[1:] - bin_borders_r[:-1]*bin_borders_r[:-1]), np.ones_like(bin_borders_z))
|
||||
return areas
|
||||
|
||||
def particleCurrentR(filename_current, filename_densities, key):
|
||||
n_pos = NPosR(filename_current, key)
|
||||
n_neg = NNegR(filename_current, key)
|
||||
n_total = totalCurrentR(n_pos, n_neg)[:,1:,:]
|
||||
|
||||
delta_t = lastOutputTime(filename_densities)
|
||||
particle_current = n_total/delta_t
|
||||
|
||||
bin_borders_r = binBordersR(filename_current, key)
|
||||
bin_borders_z = binBordersZ(filename_current, key)
|
||||
bin_areas_r = binAreasR(bin_borders_r, bin_borders_z)
|
||||
for iz in np.arange(0, particle_current.shape[2], 1):
|
||||
particle_current[:,:,iz] = particle_current[:,:,iz]/bin_areas_r
|
||||
|
||||
return particle_current
|
||||
|
||||
def particleCurrentZ(filename_current, filename_densities, key):
|
||||
n_pos = NPosZ(filename_current, key)
|
||||
n_neg = NNegZ(filename_current, key)
|
||||
n_total = totalCurrentZ(n_pos, n_neg)[1:, :, :]
|
||||
|
||||
delta_t = lastOutputTime(filename_densities)
|
||||
particle_current = n_total/delta_t
|
||||
|
||||
bin_borders_r = binBordersR(filename_current, key)
|
||||
bin_borders_z = binBordersZ(filename_current, key)
|
||||
bin_areas_z = binAreasZ(bin_borders_r, bin_borders_z)
|
||||
for iz in np.arange(0, particle_current.shape[2], 1):
|
||||
particle_current[:,:,iz] = particle_current[:,:,iz]/bin_areas_z
|
||||
|
||||
return particle_current
|
||||
|
||||
def makeBarPlotData(data, mins, maxs):
|
||||
plot_bins = np.dstack((mins,maxs)).flatten()
|
||||
plot_datas = np.dstack((data,data)).flatten()
|
||||
return plot_bins, plot_datas
|
||||
|
||||
def lastOutputTime(filename):
|
||||
key = "/Populations/e-/e-"
|
||||
f = h5py.File(filename, 'r')
|
||||
data = np.array([f[key]])
|
||||
f.close()
|
||||
|
||||
data = np.array(data.tolist())[0]
|
||||
last_output_time = np.unique(data[:,0])[-1]
|
||||
|
||||
return last_output_time
|
||||
|
||||
def cpuString(cpu_number, max_cpu_number):
|
||||
length_string = len(str(max_cpu_number))
|
||||
return str(cpu_number).zfill(length_string)
|
||||
|
||||
def outputFilename(filename_bare, cpu_number, num_cpu):
|
||||
return filename_bare +cpuString(cpu_number, num_cpu) + "_currents.h5"
|
||||
|
||||
def mergeOutputs(filename, num_cpu, specie_key):
|
||||
|
||||
first_filename = outputFilename(filename, 0, num_cpu)
|
||||
|
||||
N_pos_z = NPosZ(first_filename, specie_key)
|
||||
N_neg_z = NNegZ(first_filename, specie_key)
|
||||
N_pos_r = NPosR(first_filename, specie_key)
|
||||
N_neg_r = NNegR(first_filename, specie_key)
|
||||
|
||||
for i in np.arange(1,num_cpu,1):
|
||||
N_pos_z += NPosZ(outputFilename(filename, i, num_cpu), specie_key)
|
||||
N_neg_z += NNegZ(outputFilename(filename, i, num_cpu), specie_key)
|
||||
N_pos_r += NPosR(outputFilename(filename, i, num_cpu), specie_key)
|
||||
N_neg_r += NNegR(outputFilename(filename, i, num_cpu), specie_key)
|
||||
|
||||
f = h5py.File(filename+"currents_merged.h5", 'a')
|
||||
|
||||
key = specie_key+"/N_pos_z"
|
||||
f.create_dataset(key,data=N_pos_z)
|
||||
|
||||
key = specie_key+"/N_neg_z"
|
||||
f.create_dataset(key,data=N_neg_z)
|
||||
|
||||
key = specie_key+"/N_pos_r"
|
||||
f.create_dataset(key,data=N_pos_r)
|
||||
|
||||
key = specie_key+"/N_neg_r"
|
||||
f.create_dataset(key,data=N_neg_r)
|
||||
|
||||
f.close()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,161 @@
|
||||
import numpy as np
|
||||
import h5py as h5py
|
||||
import os
|
||||
import sys
|
||||
|
||||
def getCumTimes(filename, key):
|
||||
f = h5py.File(filename, 'r')
|
||||
data = np.array([f[key]])
|
||||
f.close()
|
||||
|
||||
data = np.array(data.tolist())[0]
|
||||
last_output_time = np.unique(data[:,0])[-1]
|
||||
data_last = data[data[:,0] == last_output_time]
|
||||
|
||||
[zbins, rbins, phi_bins, E_bins] = getNumBins(filename, key)
|
||||
|
||||
cum_times = np.zeros((zbins, rbins, phi_bins, E_bins))
|
||||
|
||||
for iz in np.arange(0,zbins,1):
|
||||
for ir in np.arange(0,rbins,1):
|
||||
for iphi in np.arange(0,phi_bins,1):
|
||||
for iE in np.arange(0,E_bins,1):
|
||||
mask = np.logical_and(data_last[:,1]==iz, data_last[:,2] == ir)
|
||||
mask = np.logical_and(mask, data_last[:,3] == iphi)
|
||||
mask = np.logical_and(mask, data_last[:,4] == iE)
|
||||
cum_times[iz,ir,iphi,iE] = data_last[mask][0,5]
|
||||
|
||||
return cum_times
|
||||
|
||||
def getDensities(filename, key):
|
||||
f = h5py.File(filename, 'r')
|
||||
data = np.array([f[key]])
|
||||
f.close()
|
||||
|
||||
data = np.array(data.tolist())[0]
|
||||
last_output_time = np.unique(data[:,0])[-1]
|
||||
data_last = data[data[:,0] == last_output_time]
|
||||
|
||||
[zbins, rbins, phi_bins, E_bins] = getNumBins(filename, key)
|
||||
|
||||
cum_times = getCumTimes(filename, key)
|
||||
densities = np.zeros((zbins, rbins, phi_bins, E_bins))
|
||||
|
||||
for iz in np.arange(0,zbins,1):
|
||||
for ir in np.arange(0,rbins,1):
|
||||
for iphi in np.arange(0,phi_bins,1):
|
||||
for iE in np.arange(0,E_bins,1):
|
||||
densities[iz,ir,iphi,iE] = cum_times[iz, ir, iphi, iE]/(last_output_time*getVolume(filename, key, iz, ir, iphi))
|
||||
|
||||
return densities
|
||||
|
||||
def getZBinsMin(filename, key):
|
||||
meta_key = key + "_meta_data"
|
||||
f = h5py.File(filename, 'r')
|
||||
data = np.array([f[meta_key]])
|
||||
data = np.array(data.tolist())[0]
|
||||
|
||||
z_mins = np.unique(data[:,4])
|
||||
f.close()
|
||||
return z_mins
|
||||
|
||||
def getZBinsMax(filename, key):
|
||||
meta_key = key + "_meta_data"
|
||||
f = h5py.File(filename, 'r')
|
||||
data = np.array([f[meta_key]])
|
||||
data = np.array(data.tolist())[0]
|
||||
|
||||
z_maxs = np.unique(data[:,5])
|
||||
f.close()
|
||||
return z_maxs
|
||||
|
||||
def getRBinsMin(filename, key):
|
||||
meta_key = key + "_meta_data"
|
||||
f = h5py.File(filename, 'r')
|
||||
data = np.array([f[meta_key]])
|
||||
data = np.array(data.tolist())[0]
|
||||
|
||||
r_mins = np.unique(data[:,6])
|
||||
f.close()
|
||||
return r_mins
|
||||
|
||||
def getRBinsMax(filename, key):
|
||||
meta_key = key + "_meta_data"
|
||||
f = h5py.File(filename, 'r')
|
||||
data = np.array([f[meta_key]])
|
||||
data = np.array(data.tolist())[0]
|
||||
|
||||
r_maxs = np.unique(data[:,7])
|
||||
f.close()
|
||||
return r_maxs
|
||||
|
||||
def getPhiBinsMin(filename, key):
|
||||
meta_key = key + "_meta_data"
|
||||
f = h5py.File(filename, 'r')
|
||||
data = np.array([f[meta_key]])
|
||||
data = np.array(data.tolist())[0]
|
||||
|
||||
phi_mins = np.unique(data[:,8])
|
||||
f.close()
|
||||
return phi_mins
|
||||
|
||||
def getPhiBinsMax(filename, key):
|
||||
meta_key = key + "_meta_data"
|
||||
f = h5py.File(filename, 'r')
|
||||
data = np.array([f[meta_key]])
|
||||
data = np.array(data.tolist())[0]
|
||||
|
||||
phi_maxs = np.unique(data[:,9])
|
||||
f.close()
|
||||
return phi_maxs
|
||||
|
||||
def getEBinsMin(filename, key):
|
||||
meta_key = key + "_meta_data"
|
||||
f = h5py.File(filename, 'r')
|
||||
data = np.array([f[meta_key]])
|
||||
data = np.array(data.tolist())[0]
|
||||
|
||||
E_mins = np.unique(data[:,10])
|
||||
f.close()
|
||||
return E_mins
|
||||
|
||||
def getEBinsMax(filename, key):
|
||||
meta_key = key + "_meta_data"
|
||||
f = h5py.File(filename, 'r')
|
||||
data = np.array([f[meta_key]])
|
||||
data = np.array(data.tolist())[0]
|
||||
|
||||
E_maxs = np.unique(data[:,11])
|
||||
f.close()
|
||||
return E_maxs
|
||||
|
||||
def getNumBins(filename, key):
|
||||
|
||||
f = h5py.File(filename, 'r')
|
||||
data = np.array([f[key]])
|
||||
f.close()
|
||||
|
||||
data = np.array(data.tolist())[0]
|
||||
|
||||
last_output_time = np.unique(data[:,0])[-1]
|
||||
|
||||
data_last = data[data[:,0] == last_output_time]
|
||||
|
||||
zbins = np.size(np.unique(data_last[:,1]))
|
||||
rbins = np.size(np.unique(data_last[:,2]))
|
||||
phi_bins = np.size(np.unique(data_last[:,3]))
|
||||
E_bins = np.size(np.unique(data_last[:,4]))
|
||||
|
||||
return [zbins, rbins, phi_bins, E_bins]
|
||||
|
||||
def getVolume(filename, key, z_bin, r_bin, phi_bin):
|
||||
z_min = getZBinsMin(filename, key)[z_bin]
|
||||
z_max = getZBinsMax(filename, key)[z_bin]
|
||||
r_min = getRBinsMin(filename, key)[r_bin]
|
||||
r_max = getRBinsMax(filename, key)[r_bin]
|
||||
phi_min = getPhiBinsMin(filename, key)[phi_bin]
|
||||
phi_max = getPhiBinsMax(filename, key)[phi_bin]
|
||||
|
||||
A = (r_max**2 - r_min**2)*(phi_max-phi_min)/2
|
||||
h = z_max-z_min
|
||||
return A*h
|
||||
@@ -0,0 +1,83 @@
|
||||
import matplotlib
|
||||
import matplotlib.colors as clr
|
||||
import matplotlib.pyplot as plt
|
||||
from cycler import cycler
|
||||
from matplotlib.colors import ListedColormap, LinearSegmentedColormap
|
||||
|
||||
def set_size(width, fraction=1, subplots=(1, 1)):
|
||||
"""Set figure dimensions to avoid scaling in LaTeX.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
width: float or string
|
||||
Document width in points, or string of predined document type
|
||||
fraction: float, optional
|
||||
Fraction of the width which you wish the figure to occupy
|
||||
subplots: array-like, optional
|
||||
The number of rows and columns of subplots.
|
||||
Returns
|
||||
-------
|
||||
fig_dim: tuple
|
||||
Dimensions of figure in inches
|
||||
"""
|
||||
if width == 'thesis':
|
||||
width_pt = 426.79135
|
||||
elif width == 'beamer':
|
||||
width_pt = 307.28987
|
||||
else:
|
||||
width_pt = width
|
||||
|
||||
# Width of figure (in pts)
|
||||
fig_width_pt = width_pt * fraction
|
||||
# Convert from pt to inches
|
||||
inches_per_pt = 1 / 72.27
|
||||
|
||||
# Golden ratio to set aesthetic figure height
|
||||
# https://disq.us/p/2940ij3
|
||||
golden_ratio = (5**.5 - 1) / 2
|
||||
|
||||
# Figure width in inches
|
||||
fig_width_in = fig_width_pt * inches_per_pt
|
||||
# Figure height in inches
|
||||
fig_height_in = fig_width_in * golden_ratio * (subplots[0] / subplots[1])
|
||||
|
||||
return (fig_width_in, fig_height_in)
|
||||
|
||||
def setRcParams():
|
||||
#matplotlib.rcParams['text.usetex'] = True
|
||||
#matplotlib.rcParams['text.latex.preamble'] = r'\usepackage{amsmath}'
|
||||
|
||||
#matplotlib.rcParams['pcolor.shading'] = 'auto'
|
||||
|
||||
matplotlib.rcParams['font.family'] = "serif"
|
||||
matplotlib.rcParams['font.size'] = 10
|
||||
matplotlib.rcParams['axes.labelsize'] = 10
|
||||
|
||||
matplotlib.rcParams['legend.fontsize'] = 8
|
||||
matplotlib.rcParams['xtick.labelsize'] = 8
|
||||
matplotlib.rcParams['ytick.labelsize'] = 8
|
||||
matplotlib.rcParams['figure.autolayout'] = True
|
||||
matplotlib.rcParams['figure.titlesize'] = 4
|
||||
matplotlib.rcParams['axes.titlesize'] = 4
|
||||
matplotlib.rcParams['lines.markersize'] = 4
|
||||
|
||||
#matplotlib.rcParams['axes.facecolor'] = '#e7e7e7ff'
|
||||
#matplotlib.rcParams['axes.grid'] = True
|
||||
#matplotlib.rcParams['grid.color'] = 'white'
|
||||
|
||||
#matplotlib.rcParams['figure.dpi'] = 240
|
||||
|
||||
# lines for colorblind
|
||||
colour_blind_cycle = ['#377eb8', '#ff7f00', '#4daf4a',
|
||||
'#f781bf', '#a65628', '#984ea3',
|
||||
'#999999', '#e41a1c', '#dede00']
|
||||
matplotlib.rcParams['axes.prop_cycle'] = cycler(color=colour_blind_cycle)
|
||||
|
||||
#colorblind cmap
|
||||
colorblind_diverging = ['#ca0020','#f4a582','#f7f7f7','#92c5de','#0571b0']
|
||||
Cmap_Name="mymap"
|
||||
mymap = LinearSegmentedColormap.from_list(Cmap_Name,colorblind_diverging)
|
||||
plt.register_cmap(name=Cmap_Name, cmap=mymap)
|
||||
matplotlib.rcParams['image.cmap']=Cmap_Name
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ def createZeroFieldH5(filename_output):
|
||||
zero = np.zeros((1,1))
|
||||
saveToKarlH5File(filename_output, zero, zero)
|
||||
|
||||
def createFieldH5(filename_derived, filename_output, dx, timestep, cylinder_origin, radius, height, z_start, z_end):
|
||||
def createFieldH5(filename_derived, filename_output, dx, timestep, cylinder_origin, radius, height, z_start=0, z_end=0):
|
||||
L_wgts = 1300
|
||||
num_cells = int((L_wgts - height*dx)/dx)
|
||||
|
||||
@@ -111,6 +111,10 @@ def extendValues(data_2d, z_start, z_end, num_cells):
|
||||
return data_ext
|
||||
|
||||
def copyValues(data_2d, z_start, z_end, num_cells):
|
||||
if z_start >= z_end:
|
||||
return data_2d
|
||||
|
||||
|
||||
(size_x, size_y) = np.shape(data_2d)
|
||||
data_copy = np.zeros((size_x, size_y+num_cells))
|
||||
data_copy[:,:z_start] = data_2d[:,:z_start]
|
||||
|
||||
Reference in New Issue
Block a user