appl121105_iotorus.f2j
ΒΆ
Convert f value to j value
''' Convert f value to j value
'''
import numpy as np
def f2j(f, ene, mass):
''' Convert distribution function to differential flux.
:param f: Distribution function in the unit of s^3 / m^6.
:param ene: Energy in eV.
:param mass: Mass in AMU.
:returns: Differential flux in /cm2 sr eV s.
>>> print('%.2e' % f2j(2.04751735385e-07, 800., 16.))
1.17e+06
'''
m = mass * 1.67e-27
j = 2 * ene * f / (m ** 2) * 1e-4 * (1.60e-19)**2
return j
def ene(vel, mass):
''' Energy in eV
:param vel: Velocity in km/s
:param mass: Mass in AMU
:returns: Energy in eV.
>>> print('%.2f' % ene(13.8, 1))
0.99
'''
m = mass * 1.67e-27 # kg
v = vel * 1e3 # m/s
e = v * v * m / 2. / 1.60e-19
return e
def vel(ene, mass):
''' Return velocity in km/s
:param ene: Energy in eV.
:param mass: Mass in AMU
:returns: Velocity in km/s.
>>> print('%.1f' % vel(1000, 1))
437.7
>>> print('%.1f' % vel(1000, 16))
109.4
'''
m = mass * 1.67e-27
v = np.sqrt(np.array(ene) * 1.60e-19 * 2 / m)
return v / 1e3
import unittest
import doctest
def doctests():
return unittest.TestSuite((
doctest.DocTestSuite(),
))
if __name__ == '__main__':
unittest.main(defaultTest='doctests')