308 lines
12 KiB
Python
Executable File
308 lines
12 KiB
Python
Executable File
#from asyncio import open_unix_connection
|
|
import numpy as np
|
|
import h5py as h5py
|
|
import os
|
|
import sys
|
|
import matplotlib
|
|
import matplotlib.pyplot as plt
|
|
import plot_standards as pst
|
|
|
|
|
|
def getSpecies(filename):
|
|
file = h5py.File(filename, 'r')
|
|
return list(file.keys())
|
|
|
|
|
|
def outputPeriodKey(output_period):
|
|
if (output_period == "LastSyncPeriod"):
|
|
return "/LastSyncPeriod"
|
|
else:
|
|
return "/" + output_period
|
|
|
|
|
|
def mass(filename, path_to_species):
|
|
file = h5py.File(filename, 'r')
|
|
path_to_mass = path_to_species + "/Mass"
|
|
return np.array(file[path_to_mass])[0]
|
|
|
|
|
|
def charge(filename, path_to_species):
|
|
file = h5py.File(filename, 'r')
|
|
path_to_charge = path_to_species + "/Charge"
|
|
return np.array(file[path_to_charge])[0]
|
|
|
|
|
|
def zBinsDensityField(filename, path_to_species):
|
|
file = h5py.File(filename, 'r')
|
|
path_to_border = path_to_species + "/DensityField/BinBorders/longitudinal"
|
|
return np.array(file[path_to_border])
|
|
|
|
|
|
def energyBinsDensityfield(filename, path_to_species):
|
|
file = h5py.File(filename, 'r')
|
|
path_to_border = path_to_species + "/DensityField/BinBorders/energy"
|
|
return np.array(file[path_to_border])
|
|
|
|
|
|
def binVolumes(filename, path_to_species):
|
|
file = h5py.File(filename, 'r')
|
|
path_to_volumes = path_to_species + "/DensityField/BinVolumes"
|
|
return np.array(file[path_to_volumes])
|
|
|
|
|
|
def deletionsMaxInteractions(filename, path_to_species, output_period):
|
|
file = h5py.File(filename, 'r')
|
|
path = path_to_species + "/DeletionLogger" + \
|
|
outputPeriodKey(output_period) + "/NumDeletions/MaxInteractions"
|
|
return np.array(file[path])[0]
|
|
|
|
|
|
def deletionsMaxTimeAlive(filename, path_to_species, output_period):
|
|
file = h5py.File(filename, 'r')
|
|
path = path_to_species + "/DeletionLogger" + \
|
|
outputPeriodKey(output_period) + "/NumDeletions/MaxTimeAlive"
|
|
return np.array(file[path])[0]
|
|
|
|
|
|
def deletionsRecombination(filename, path_to_species, output_period):
|
|
file = h5py.File(filename, 'r')
|
|
path = path_to_species + "/DeletionLogger" + \
|
|
outputPeriodKey(output_period) + "/NumDeletions/Recombination"
|
|
return np.array(file[path])[0]
|
|
|
|
|
|
def deletionsWall(filename, path_to_species, output_period):
|
|
file = h5py.File(filename, 'r')
|
|
path = path_to_species + "/DeletionLogger" + \
|
|
outputPeriodKey(output_period) + "/NumDeletions/Wall"
|
|
return np.array(file[path])[0]
|
|
|
|
|
|
def timeInBin(filename, path_to_species, output_period):
|
|
file = h5py.File(filename, 'r')
|
|
path_to_time = path_to_species + "/DensityField/SimulationData" + \
|
|
outputPeriodKey(output_period) + "/TimeInBin"
|
|
return np.array(file[path_to_time])
|
|
|
|
|
|
def physicalTime(filename, path_to_species, output_period):
|
|
file = h5py.File(filename, 'r')
|
|
path_to_time = path_to_species + "/DensityField/SimulationData" + \
|
|
outputPeriodKey(output_period) + "/PhysicalTime"
|
|
return np.array(file[path_to_time])[0]
|
|
|
|
|
|
def spectrum(filename, path_to_species, output_period):
|
|
file = h5py.File(filename, 'r')
|
|
path_to_spectrum = path_to_species + "/DensityField/SimulationData" + \
|
|
outputPeriodKey(output_period) + "/Spectrum"
|
|
return np.array(file[path_to_spectrum])
|
|
|
|
|
|
def density(filename, path_to_species, output_period):
|
|
file = h5py.File(filename, 'r')
|
|
path_to_density = path_to_species + "/DensityField/SimulationData" + \
|
|
outputPeriodKey(output_period) + "/Density"
|
|
return np.array(file[path_to_density])
|
|
|
|
|
|
def longitudinalCurrent(filename, path_to_species, output_period):
|
|
file = h5py.File(filename, 'r')
|
|
path_to_current = path_to_species + "/CurrentCollector/SimulationData" + \
|
|
outputPeriodKey(output_period) + "/CurrentInZ"
|
|
return np.array(file[path_to_current])
|
|
|
|
|
|
def longitudinalNegativeCrossings(filename, path_to_species, output_period):
|
|
file = h5py.File(filename, 'r')
|
|
path_to_current = path_to_species + "/CurrentCollector/SimulationData" + \
|
|
outputPeriodKey(output_period) + "/NegativeCrossingsInZ"
|
|
return np.array(file[path_to_current])
|
|
|
|
|
|
def longitudinalPositiveCrossings(filename, path_to_species, output_period):
|
|
file = h5py.File(filename, 'r')
|
|
path_to_current = path_to_species + "/CurrentCollector/SimulationData" + \
|
|
outputPeriodKey(output_period) + "/PositiveCrossingsInZ"
|
|
return np.array(file[path_to_current])
|
|
|
|
|
|
def radialCurrent(filename, path_to_species, output_period):
|
|
file = h5py.File(filename, 'r')
|
|
path_to_current = path_to_species + "/CurrentCollector/SimulationData" + \
|
|
outputPeriodKey(output_period) + "/CurrentInR"
|
|
return np.array(file[path_to_current])
|
|
|
|
|
|
def longitudinalAreas(filename, path_to_species):
|
|
file = h5py.File(filename, 'r')
|
|
path_to_areas = path_to_species + "/CurrentCollector/AreaInZ"
|
|
return np.array(file[path_to_areas])
|
|
|
|
|
|
def radialAreas(filename, path_to_species):
|
|
file = h5py.File(filename, 'r')
|
|
path_to_areas = path_to_species + "/CurrentCollector/AreaInR"
|
|
return np.array(file[path_to_areas])
|
|
|
|
|
|
def longitudinalCurrentVsZ(filename, path_to_species, output_period="LastSyncPeriod"):
|
|
areas_in_z = longitudinalAreas(filename, path_to_species)
|
|
current_in_z = longitudinalCurrent(
|
|
filename, path_to_species, output_period)
|
|
particles = current_in_z * areas_in_z
|
|
return np.sum(particles, axis=(0, 1)) / np.sum(areas_in_z, axis=(0, 1))
|
|
|
|
|
|
def longitudinalNegativeCrossingsVsZ(filename, path_to_species, output_period="LastSyncPeriod"):
|
|
areas_in_z = longitudinalAreas(filename, path_to_species)
|
|
current_in_z = longitudinalCurrent(
|
|
filename, path_to_species, output_period)
|
|
particles = current_in_z * areas_in_z
|
|
return np.sum(particles, axis=(0, 1)) / np.sum(areas_in_z, axis=(0, 1))
|
|
|
|
|
|
def tubeCurrentVsZ(filename, path_to_species, output_period="LastSyncPeriod"):
|
|
areas_in_r = radialAreas(filename, path_to_species)
|
|
current_in_r = radialCurrent(filename, path_to_species, output_period)
|
|
particles = current_in_r * areas_in_r
|
|
return (np.sum(particles, axis=(1)) / np.sum(areas_in_r, axis=(1)))[-2, :]
|
|
|
|
|
|
def densityVsZ(filename, path_to_species, output_period="LastSyncPeriod"):
|
|
bin_volumes = binVolumes(filename, path_to_species)
|
|
densities = density(filename, path_to_species, output_period)
|
|
particles = densities*bin_volumes
|
|
return np.sum(particles, axis=(0, 1)) / np.sum(bin_volumes, axis=(0, 1))
|
|
|
|
|
|
def findClosestIndex(position, bin_borders):
|
|
return (np.abs(bin_borders - position)).argmin()
|
|
|
|
|
|
def spectrumAtZ(filename, path_to_species, z_position, output_period="LastSyncPeriod"):
|
|
bin_volumes = binVolumes(filename, path_to_species)
|
|
spectrums = spectrum(filename, path_to_species, output_period)
|
|
particles = spectrums
|
|
for i in np.arange(0, particles.shape[3]):
|
|
particles[:, :, :, i] = spectrums[:, :, :, i]*bin_volumes
|
|
z_index = findClosestIndex(
|
|
z_position, zBinsDensityField(filename, path_to_species))
|
|
volume = np.sum(bin_volumes, axis=(0, 1))[z_index]
|
|
return np.sum(particles, axis=(0, 1))[z_index, :]/volume
|
|
|
|
|
|
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 plotSpectrumAtZ(filename, path_to_species, z_position, plot_axis, output_period="LastSyncPeriod"):
|
|
spectrum_at_z = spectrumAtZ(
|
|
filename, path_to_species, z_position, output_period)
|
|
E_bins = energyBinsDensityfield(filename, path_to_species)
|
|
plot_bins, plot_datas = makeBarPlotData(
|
|
spectrum_at_z[1:-1], E_bins[0:-1], E_bins[1:])
|
|
plot_axis.plot(plot_bins, plot_datas, label=str(path_to_species))
|
|
plot_axis.set_xscale("log")
|
|
plot_axis.set_yscale("log")
|
|
plot_axis.set_xlabel(r"Energy $E$ (eV)")
|
|
plot_axis.set_ylabel(
|
|
r"Diff. Density $\frac{\mathrm{d}n_e}{\mathrm{d}\log_{10}E}$ $\left(\frac{1}{\mathrm{m}^{3} \log_{10}(\mathrm{eV})}\right)$")
|
|
|
|
|
|
def plotAllSpectrumAtZ(filename, z_position, output_period, specie_keys, output_folder, plot_instructions={}):
|
|
pst.setRcParams()
|
|
fig, ax = plt.subplots(figsize=pst.set_size('thesis'))
|
|
for key in specie_keys:
|
|
plotSpectrumAtZ(filename, key, z_position, ax, output_period)
|
|
ax.set_facecolor('#e7e7e7ff')
|
|
ax.grid(color='white')
|
|
|
|
ax.legend()
|
|
if "xlim" in plot_instructions.keys():
|
|
ax.set_xlim(plot_instructions["xlim"])
|
|
if "ylim" in plot_instructions.keys():
|
|
ax.set_ylim(plot_instructions["ylim"])
|
|
|
|
fig.savefig(output_folder +
|
|
"/spectrum_at_z={}_at_period={}.pdf".format(z_position, output_period))
|
|
|
|
|
|
def plotDensityVsZ(filename, path_to_species, plot_axis, output_period="LastSyncPeriod"):
|
|
density = densityVsZ(filename, path_to_species, output_period)
|
|
z_bins = zBinsDensityField(filename, path_to_species)
|
|
|
|
plot_bins, plot_datas = makeBarPlotData(
|
|
density[1:-1], z_bins[0:-1], z_bins[1:])
|
|
plot_axis.plot(plot_bins, plot_datas, label=str(path_to_species))
|
|
plot_axis.set_yscale("log")
|
|
plot_axis.set_xlabel(r"Distance to rear wall $z$ (m)")
|
|
plot_axis.set_ylabel(r"Density $n$ ($m^{-3}$)")
|
|
|
|
|
|
def plotAllDensityVsZ(filename, output_period, specie_keys, output_folder):
|
|
pst.setRcParams()
|
|
fig, ax = plt.subplots(figsize=pst.set_size('thesis'))
|
|
for key in specie_keys:
|
|
plotDensityVsZ(filename, key, ax, output_period)
|
|
|
|
ax.set_facecolor('#e7e7e7ff')
|
|
ax.grid(color='white')
|
|
ax.legend()
|
|
fig.savefig(output_folder + "/density_vs_z_at_period={}.pdf".format(output_period),
|
|
format='pdf', bbox_inches='tight')
|
|
|
|
|
|
def plotLongitudinalParticleCurrentVsZ(filename, path_to_species, plot_axis, output_period="LastSyncPeriod"):
|
|
current_in_z = longitudinalCurrentVsZ(
|
|
filename, path_to_species, output_period)
|
|
z_bins = zBinsDensityField(filename, path_to_species)
|
|
plot_axis.plot(z_bins, current_in_z, label=str(path_to_species))
|
|
plot_axis.set_xlabel(r"Distance to rear wall $z$ (m)")
|
|
plot_axis.set_ylabel(r"Particle current $j$ ($m^{-2}s^{-1}$)")
|
|
|
|
|
|
def plotAllLongitudinalParticleCurrentVsZ(filename, output_period, specie_keys, output_folder):
|
|
pst.setRcParams()
|
|
fig, ax = plt.subplots(figsize=pst.set_size('thesis'))
|
|
for key in specie_keys:
|
|
plotLongitudinalParticleCurrentVsZ(filename, key, ax, output_period)
|
|
|
|
ax.set_facecolor('#e7e7e7ff')
|
|
ax.grid(color='white')
|
|
ax.legend()
|
|
fig.savefig(output_folder + "/longitudinal_particle_current_vs_z_at_period={}.pdf".format(output_period),
|
|
format='pdf', bbox_inches='tight')
|
|
|
|
|
|
def plotLongitudinalElectricCurrentVsZ(filename, path_to_species, plot_axis, output_period="LastSyncPeriod"):
|
|
current_in_z = longitudinalCurrentVsZ(
|
|
filename, path_to_species, output_period)*charge(filename, path_to_species)
|
|
z_bins = zBinsDensityField(filename, path_to_species)
|
|
plot_axis.plot(z_bins, current_in_z)
|
|
plot_axis.set_xlabel(r"Distance to rear wall $z$ (m)")
|
|
plot_axis.set_ylabel(r"Electric current $I$ ($A$)")
|
|
|
|
|
|
def printDeletionLoggerStats(filename, path_to_species, output_period="LastSyncPeriod"):
|
|
max_interactions = deletionsMaxInteractions(
|
|
filename, path_to_species, output_period)
|
|
max_time_alive = deletionsMaxTimeAlive(
|
|
filename, path_to_species, output_period)
|
|
recombinations = deletionsRecombination(
|
|
filename, path_to_species, output_period)
|
|
wall = deletionsWall(filename, path_to_species, output_period)
|
|
|
|
print("Deletion Logger stats for: " + str(path_to_species))
|
|
print("MaxTimeAlive: {}".format(max_time_alive))
|
|
print("MaxInteractions: {}".format(max_interactions))
|
|
print("Recombinations: {}".format(recombinations))
|
|
print("Wall hits: {}".format(wall))
|
|
|
|
|
|
def printAllDeletionLoggerStats(filename, specie_keys, output_period):
|
|
for key in specie_keys:
|
|
printDeletionLoggerStats(filename, key, output_period)
|