Source code for irfpy.util.lorentztrans
''' Functions for Lorenz transformation
.. codeauthor:: Yoshifumi Futaana
.. todo::
Consider importing to physics module
'''
import numpy as np
from irfpy.util import constant as k
from irfpy.util import unitq as u
c = k.c
c_u = u.c.simplified
[docs]def beta(v):
r''' Return :math:`\beta`.
Return the parameter :math:`\beta`.
.. math::
\beta = \frac{v}{c}
where :math:`v` is the velocity of the object
and :math:`c` is the velocity of light.
:param v: Velocity (in meter) of the object.
:type v: float or np.array.
>>> print('%.5f' % beta(3e7)) # About 0.1
0.10007
'''
return v / c
beta_u = u.make_unitful_function(beta, [u.m], 1)
''' Unitful version of :func:`beta`.
'''
[docs]def gamma(v):
r''' Return :math:`\gamma`.
Return the parameter :math:`\gamma`.
.. math::
\gamma = \frac{1}{\sqrt{1 - \bigl(\frac{v}{c}\bigl)^2}}
where :math:`v` is the velocity of the object
and :math:`c` is the velocity of light.
:param v: Velocity of the object.
:type v: float or np.array.
>>> print('%.6f' % gamma(3e7))
1.005045
'''
p = 1 + v / c
m = 1 - v / c
return 1 / np.sqrt(p * m)
gamma_u = u.make_unitful_function(gamma, [u.m], 1)
''' Unitful version of :func:`gamma`.
'''
[docs]def gamma2vel(gamma):
r''' Inverse function of :func:`gamma`.
:param gamma: The parameter :math:`\gamma`.
:returns: :math:`v` in ``m/s``.
The relation is
.. math::
\gamma = \frac{1}{\sqrt{1 - \bigl(\frac{v}{c}\bigl)^2}}
so that
.. math::
v = c \sqrt{1 - \frac{1}{\gamma^2}}
>>> print('%.3e' % gamma2vel(1.01))
4.208e+07
You may use unitful version:
>>> print('%.3e' % gamma2vel_u(1.01).rescale(u.km / u.s))
4.208e+04
'''
return np.sqrt(1 - 1 / (gamma ** 2)) * c
gamma2vel_u = u.make_unitful_function(gamma2vel, [], u.m / u.s, offset=1)
transformx_u = u.make_unitful_function2(transformx, [u.m, u.s, u.m/u.s], [u.m, u.s])
''' Unitful version of :func:`transformx`
'''
import unittest
import doctest
[docs]def doctests():
return unittest.TestSuite((
doctest.DocTestSuite(),
))
if __name__ == '__main__':
unittest.main(defaultTest='doctests')