analyisis scripts
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
import numpy as np
|
||||
import h5py as h5py
|
||||
import os
|
||||
import sys
|
||||
import matplotlib
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
import functions.calculate_density_from_karl as ck
|
||||
|
||||
|
||||
def spectrumToCsv(filename, filename_output, z_pos, Emin, Emax):
|
||||
|
||||
key = "/Populations/e-/e-"
|
||||
|
||||
particles = ck.getParticlesPerBin(filename, key)
|
||||
volumes = ck.getVolumes(filename, key)
|
||||
|
||||
zmins = ck.getZBinsMin(filename, key)
|
||||
zmaxs = ck.getZBinsMax(filename, key)
|
||||
Emins = ck.getEBinsMin(filename, key)
|
||||
Emaxs = ck.getEBinsMax(filename, key)
|
||||
|
||||
z_index = np.where(zmins <= z_pos)[-1][-1]
|
||||
|
||||
particles_at_z = np.sum(particles[z_index,:,:,:], axis=(0,1)) # z, r, phi, E
|
||||
volumes_longitudinal = np.sum(volumes, axis=(1,2)) # z, r, phi
|
||||
|
||||
dndE = particles_at_z/volumes_longitudinal[z_index]
|
||||
Emins = ck.getEBinsMin(filename, key)
|
||||
Emaxs = ck.getEBinsMax(filename, key)
|
||||
Emids = (Emaxs + Emins)/2
|
||||
|
||||
Emin_index = np.where(Emins <= Emin)[-1][-1]
|
||||
Emax_index = np.where(Emins <= Emax)[-1][-1]
|
||||
|
||||
dndE_bound = dndE[Emin_index:Emax_index+1]
|
||||
E_bound = Emins[Emin_index:Emax_index+1]
|
||||
|
||||
dndE_bound = np.append(dndE_bound, 0)
|
||||
E_bound = np.append(E_bound, Emaxs[Emax_index])
|
||||
|
||||
np.savetxt(
|
||||
filename_output,
|
||||
np.transpose(np.array([E_bound, dndE_bound])),
|
||||
delimiter=",",
|
||||
header="Energy, dndE")
|
||||
Reference in New Issue
Block a user