From a95f408c9f77cfd8ade0e22088ca82e17c0f7230 Mon Sep 17 00:00:00 2001 From: jgieseler Date: Fri, 11 Aug 2023 14:53:21 +0300 Subject: [PATCH 1/2] introduce speed2energy() --- seppy/util/__init__.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/seppy/util/__init__.py b/seppy/util/__init__.py index c7e1b17..14bbf2a 100644 --- a/seppy/util/__init__.py +++ b/seppy/util/__init__.py @@ -286,7 +286,7 @@ def energy2speed(species, kinetic_energy): Args: species (string): particle species (electrons 'e' or protons 'p') used to determine the particle mass - kinetic_energy (float/astropy units): kinetic energy of the particle using astropy units; if only float MeV is used + kinetic_energy (astropy units/float): kinetic energy of the particle using astropy units; if only float, MeV is used Returns: astropy units: relativistic particle speed. @@ -297,6 +297,25 @@ def energy2speed(species, kinetic_energy): return calc_particle_speed(mass_dict[species], kinetic_energy) +def speed2energy(species, speed): + ''' + Calculates the relativistic kinetic energy derived from particle speed. + + Args: + species (string): particle species (electrons 'e' or protons 'p') used to determine the particle mass + speed (astropy units/float): relativistic particle speed of the particle using astropy units; if only float, m/s is used + + Returns: + astropy units: kinetic energy + ''' + if not type(speed)==u.quantity.Quantity: + speed = speed * u.m/u.s + mass_dict = {'p': const.m_p, 'e': const.m_e} + gamma = 1/np.sqrt(1-speed**2/const.c**2) + K = (gamma-1)*mass_dict[species]*const.c**2 + return K.to(u.MeV) + + def speed2momentum(species, speed): ''' Calculates the relativistic particle momentum derived from speed. From 99f028670ebd3e0b8bb906760c949ad9c98dccb3 Mon Sep 17 00:00:00 2001 From: jgieseler Date: Fri, 11 Aug 2023 15:09:24 +0300 Subject: [PATCH 2/2] increase version to 0.1.9 --- seppy/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/seppy/version.py b/seppy/version.py index f91ffc5..17e72ca 100644 --- a/seppy/version.py +++ b/seppy/version.py @@ -5,4 +5,4 @@ from setuptools_scm import get_version __version__ = get_version(root='..', relative_to=__file__) except Exception: - __version__ = '0.1.8' + __version__ = '0.1.9'