Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update DataExporters.py to deal with an issue when all particles have the same kinetic energy. #168

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions ParticlePhaseSpace/DataExporters.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,36 +222,36 @@ def _generate_topas_header_file(self):
electron_PS = self._PS('electrons')
electron_PS.fill.kinetic_E()
particle_number_string.append('Number of e-: ' + str(len(electron_PS.ps_data['x [mm]'])) )
minimum_Ek_string.append('Minimum Kinetic Energy of e-: ' + str(min(electron_PS.ps_data['Ek [MeV]'])) + ' MeV')
maximum_Ek_string.append('Maximum Kinetic Energy of e-: ' + str(max(electron_PS.ps_data['Ek [MeV]'])) + ' MeV')
minimum_Ek_string.append('Minimum Kinetic Energy of e-: ' + str(min(electron_PS.ps_data['Ek [MeV]'], default=electron_PS.ps_data['Ek [MeV]'].mean)) + ' MeV')
maximum_Ek_string.append('Maximum Kinetic Energy of e-: ' + str(max(electron_PS.ps_data['Ek [MeV]'], default=electron_PS.ps_data['Ek [MeV]'].mean)) + ' MeV')
elif particle_cfg.particle_properties[particle]['name'] == 'positrons':
positron_PS = self._PS('positrons')
positron_PS.fill.kinetic_E()
particle_number_string.append('Number of e+: ' + str(len(positron_PS.ps_data['x [mm]'])))
minimum_Ek_string.append('Minimum Kinetic Energy of e+: ' + str(min(positron_PS.ps_data['Ek [MeV]'])) + ' MeV')
maximum_Ek_string.append('Maximum Kinetic Energy of e+: ' + str(max(positron_PS.ps_data['Ek [MeV]'])) + ' MeV')
minimum_Ek_string.append('Minimum Kinetic Energy of e+: ' + str(min(positron_PS.ps_data['Ek [MeV]'], default=positron_PS.ps_data['Ek [MeV]'].mean)) + ' MeV')
maximum_Ek_string.append('Maximum Kinetic Energy of e+: ' + str(max(positron_PS.ps_data['Ek [MeV]'], default=positron_PS.ps_data['Ek [MeV]'].mean)) + ' MeV')
elif particle_cfg.particle_properties[particle]['name'] == 'gammas':
gamma_PS = self._PS('gammas')
gamma_PS.fill.kinetic_E()
particle_number_string.append('Number of gamma: ' + str(len(gamma_PS.ps_data['x [mm]'])))
minimum_Ek_string.append('Minimum Kinetic Energy of gamma: ' + str(min(gamma_PS.ps_data['Ek [MeV]'])) + ' MeV')
maximum_Ek_string.append('Maximum Kinetic Energy of gamma: ' + str(max(gamma_PS.ps_data['Ek [MeV]'])) + ' MeV')
minimum_Ek_string.append('Minimum Kinetic Energy of gamma: ' + str(min(gamma_PS.ps_data['Ek [MeV]'], default=gamma_PS.ps_data['Ek [MeV]'].mean)) + ' MeV')
maximum_Ek_string.append('Maximum Kinetic Energy of gamma: ' + str(max(gamma_PS.ps_data['Ek [MeV]'], default=gamma_PS.ps_data['Ek [MeV]'].mean)) + ' MeV')
elif particle_cfg.particle_properties[particle]['name'] == 'neutrons':
neutrons_PS = self._PS('neutrons')
neutrons_PS.fill.kinetic_E()
particle_number_string.append('Number of neutrons: ' + str(len(neutrons_PS.ps_data['x [mm]'])))
minimum_Ek_string.append(
'Minimum Kinetic Energy of neutron: ' + str(min(neutrons_PS.ps_data['Ek [MeV]'])) + ' MeV')
'Minimum Kinetic Energy of neutron: ' + str(min(neutrons_PS.ps_data['Ek [MeV]'], default=neutrons_PS.ps_data['Ek [MeV]'].mean)) + ' MeV')
maximum_Ek_string.append(
'Maximum Kinetic Energy of neutron: ' + str(max(neutrons_PS.ps_data['Ek [MeV]'])) + ' MeV')
'Maximum Kinetic Energy of neutron: ' + str(max(neutrons_PS.ps_data['Ek [MeV]'], default=neutrons_PS.ps_data['Ek [MeV]'].mean)) + ' MeV')
elif particle_cfg.particle_properties[particle]['name'] == 'protons':
protons_PS = self._PS('protons')
protons_PS.fill.kinetic_E()
particle_number_string.append('Number of protons: ' + str(len(protons_PS.ps_data['x [mm]'])))
minimum_Ek_string.append(
'Minimum Kinetic Energy of proton: ' + str(min(protons_PS.ps_data['Ek [MeV]'])) + ' MeV')
'Minimum Kinetic Energy of proton: ' + str(min(protons_PS.ps_data['Ek [MeV]'], default=protons_PS.ps_data['Ek [MeV]'].mean)) + ' MeV')
maximum_Ek_string.append(
'Maximum Kinetic Energy of proton: ' + str(max(protons_PS.ps_data['Ek [MeV]'])) + ' MeV')
'Maximum Kinetic Energy of proton: ' + str(max(protons_PS.ps_data['Ek [MeV]'], default=protons_PS.ps_data['Ek [MeV]'].mean)) + ' MeV')
else:
raise NotImplementedError(f'cannot currently export particle type {particle_cfg.particle_properties[particle]["name"]}.'
f'\nneed to update header writer')
Expand Down Expand Up @@ -291,4 +291,4 @@ def _export_data(self):
self._PS.ps_data[data_string].to_csv(self._output_location / self._output_name, index=False, header=False)

def _set_expected_units(self):
self._expected_units = ParticlePhaseSpaceUnits()('p2_sat_UHI')
self._expected_units = ParticlePhaseSpaceUnits()('p2_sat_UHI')