#!/bin/python3 import numpy as np import os import sys from astropy import units as u from astropy import constants as const import matplotlib import matplotlib.pyplot as plt # Specific includes # ======================= homebase = os.getenv('HOMEBASE') if homebase is None: homebase = "/home/jonas/new_workspace/Coding/KARL/karl" sys.path.append(homebase+"/src/tools/analysis_jkellerer") from functions.calculate_density_from_karl import * import functions.plot_standards as pst # inputs # ===================== paper_path = "/home/jonas/new_workspace/notes/paper/docs/paper/monte-carlo-electron-spectrum/" output_folder = paper_path+"/figures/" filename_Nastoyashchii = paper_path + "/calculations/ComparisonNastoyashchii/data_Nastoyashchii.txt" folder_karl = "/home/jonas/new_workspace/Coding/Output/LRZ/SCRATCH/KARL/ComparisonNastoyashchii36/parameter_20210716_1/" filename_karl = folder_karl + "mc_electron_out_1391.h5" z_pos_1 = 8 z_pos_2 = 0 # calculation # ====================== # data from karl key = "/Populations/e-/e-" density_karl = getDensities(filename_karl, key) zmins = getZBinsMin(filename_karl, key) zmaxs = getZBinsMax(filename_karl, key) Emins = getEBinsMin(filename_karl, key) Emaxs = getEBinsMax(filename_karl, key) particles = getParticlesPerBin(filename_karl, key) volumes = getVolumes(filename_karl, key) volumes_longitudinal = np.sum(volumes, axis=(1,2)) # z, r, phi z_index_1 = np.where(zmins <= z_pos_1)[-1][-1] particles_at_z_1 = np.sum(particles[z_index_1,:,:,:], axis=(0,1)) # z, r, phi, E dndE_1 = particles_at_z_1/volumes_longitudinal[z_index_1] / 1E6 plot_bins = np.dstack((Emins,Emaxs)).flatten() plot_datas_1 = np.dstack((dndE_1,dndE_1)).flatten() z_index_2 = np.where(zmins <= z_pos_2)[-1][-1] particles_at_z_2 = np.sum(particles[z_index_2,:,:,:], axis=(0,1)) # z, r, phi, E dndE_2 = particles_at_z_2/volumes_longitudinal[z_index_2] / 1E6 plot_bins = np.dstack((Emins,Emaxs)).flatten() plot_datas_2 = np.dstack((dndE_2,dndE_2)).flatten() # data from Nastoyashchii data_Nastoyashchii = np.genfromtxt(filename_Nastoyashchii) energy_Nastoyashchii = 10**data_Nastoyashchii[:,0] denisty_Nastoyashchii = 10**data_Nastoyashchii[:,1] denisty_Nastoyashchii = denisty_Nastoyashchii/denisty_Nastoyashchii.max() * 2E4 # plots # ====================== pst.setRcParams() prop_cycle = plt.rcParams['axes.prop_cycle'] colors = prop_cycle.by_key()['color'] (width, height) = pst.set_size('thesis') fig, ax = plt.subplots(1, 1, figsize=(width, height*1.0),sharex=True) ax.set_facecolor('#e7e7e7ff') ax.grid(color='white') ax.set_axisbelow(True) ax.plot(plot_bins, plot_datas_1, '-', label="KARL, inlet") ax.plot(plot_bins, plot_datas_2, '--', label="KARL, rear wall") ax.plot(energy_Nastoyashchii[1:], denisty_Nastoyashchii[1:], '-.', label='Nastoyashchii') ax.set_ylim(1E-3, dndE_1.max()*1.2) ax.set_xlim(1E-5, 18.3E3) ax.set_yscale('log') ax.set_xscale('log') ax.legend() ax.set_xlabel(r'Energy $E$ (eV)') ax.set_ylabel(r"Diff. Density $\frac{\mathrm{d}n_e}{\mathrm{d}\log_{10}E}$ $\left(\frac{1}{\mathrm{cm}^{3} \log_{10}(\mathrm{eV})}\right)$") plt.savefig(output_folder+"comprarison_ndE_Nastoyashchii.pdf",bbox_inches='tight') plt.show()