''' Frame conversion between JUICE and JNA frame.
Spacecraft frame and JNA frame conversion is
::
x_SC = -x_JNA
y_SC = z_JNA
z_SC = y_JNA
See :ref:`definition_of_frames` for details.
'''
import numpy as np
import irfpy.cena.frame
[docs]def jna2nsc(vec):
''' JNA to SC.
:param vec: Vector in JNA frame. (3,) or (3, N) shaped numpy array.
>>> r_jna = np.array([1, 3, 5])
>>> r_nsc = jna2nsc(r_jna)
>>> print(r_nsc)
[-1 5 3]
Multiple vector conversion is supported. Shape should be (3, N), where N
is the number of vectors. The returned is also (3, N) shape.
>>> rs_jna = np.array([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15]])
>>> print(rs_jna.shape)
(3, 5)
>>> rs_nsc = jna2nsc(rs_jna)
>>> print(rs_nsc.shape)
(3, 5)
>>> print(rs_nsc[:, 0])
[-1 11 6]
'''
if np.array(vec).shape[0] != 3:
raise IndexError('The vec should have shape (3,) or (3, N)')
return np.array([-vec[0], vec[2], vec[1]])
[docs]def nsc2jna(vec):
''' SC frame vector, vec, is converted to JNA frame.
:param vec: Vector in NSC frame. (3,) or (3, N) shaped numpy array.
>>> r_jna = np.array([-1, 2, 8])
>>> r_nsc = jna2nsc(r_jna)
>>> print(r_nsc)
[1 8 2]
'''
if np.array(vec).shape[0] != 3:
raise IndexError('The vec should have shape (3,) or (3, N)')
return np.array([-vec[0], vec[2], vec[1]])
[docs]def jna2angles(vec):
''' Return the angles in degrees.
>>> jna2angles([1, 0, 0])
(0.0, 90.0)
>>> jna2angles([0, 1, 0])
(0.0, 0.0)
>>> jna2angles([0, 0, 1])
(-90.0, 0.0)
>>> jna2angles([0, 0, -1])
(90.0, 0.0)
'''
return irfpy.cena.frame.cena2angles(vec, degrees=True)
[docs]def angles2jna(theta, phi):
''' Angles (degrees) to a np.array.
>>> v = angles2jna(0, 90)
>>> print('%.3f %.3f %.3f' % (v[0], v[1], v[2]))
1.000 0.000 -0.000
>>> v = angles2jna(0, 0)
>>> print('%.3f %.3f %.3f' % (v[0], v[1], v[2]))
0.000 1.000 -0.000
>>> v = angles2jna(-90, 0)
>>> print('%.3f %.3f %.3f' % (v[0], v[1], v[2]))
0.000 0.000 1.000
>>> v = angles2jna(90, 0)
>>> print('%.3f %.3f %.3f' % (v[0], v[1], v[2]))
0.000 0.000 -1.000
'''
return irfpy.cena.frame.angles2cena(theta, phi, degrees=True)
import unittest
import doctest
[docs]def doctests():
return unittest.TestSuite((
doctest.DocTestSuite(),
))
if __name__ == '__main__':
unittest.main(defaultTest='doctests')