Skip to content

Commit

Permalink
introduce speed2energy()
Browse files Browse the repository at this point in the history
introduce speed2energy()
  • Loading branch information
jgieseler authored Aug 11, 2023
2 parents cef8e44 + 99f0286 commit 0fff20f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
21 changes: 20 additions & 1 deletion seppy/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion seppy/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

0 comments on commit 0fff20f

Please sign in to comment.