appl121105_iotorus.moon_ioΒΆ

Io class.

Provides Io class, providing position of Io and its velocity.

''' Io class.

Provides :class:`Io` class, providing position of Io and its velocity.
'''
import numpy as np

from . import parameters

class Io:
    ''' Io class in JEqS system.

    For simplicity, we assume that Io rotates in the
    equator of Jupiter.  This provides ``z``=0 and ``vz``=0.

    >>> io = Io()
    >>> print(io.get_phase())
    0.0
    >>> print('%.3f' % io.get_phase(t=3600))  # 1 hour later.
    8.479

    Phase can be given by array.

    >>> phases = io.get_phase(t=[0, 3600])
    >>> print('%.3f %.3f' % (phases[0], phases[1]))
    0.000 8.479

    Position can be get by :meth:`get_position`.

    >>> print(io.get_position(t=3600))
    [ 417091.32220872   62174.90601668       0.        ]
    >>> print(io.get_position(t=[0, 3600]))
    [[ 421700.          417091.32220872]
     [      0.           62174.90601668]
     [      0.               0.        ]]
    >>> print(io.get_velocity(t=[0, 3600]))
    [[ -0.          -2.55570268]
     [ 17.334       17.14456006]
     [  0.           0.        ]]



    '''
    def __init__(self, initial_phase_degree=0):
        ''' Setup Io.

        :param initial_phase_degree: Phase of Io in degrees at t=0.
        '''
        self.phase = np.deg2rad(initial_phase_degree)

    def _omega_t(self, t=0):
        omega = parameters.Vio / parameters.Rji
        t = np.array(t)
        return omega * np.array(t)

    def get_phase(self, t=0):
        ''' Return the phase in deg
        '''
        return np.rad2deg(self.phase + self._omega_t(t))

    def get_position(self, t=0):
        ''' Return the position.

        :param t: Scalar or (N,) shaped np.array.
        :returns: Position with array (3,) or (3, N) shape.
        '''
        x = np.cos(self.phase + self._omega_t(t))
        y = np.sin(self.phase + self._omega_t(t))
        z = np.zeros_like(x)

        return parameters.Rji * np.array([x, y, z])

    def get_velocity(self, t=0):
        ''' Return the position.

        :param t: Scalar or (N,) shaped np.array.
        :returns: Velocity with array (3,) or (3, N) shape.
        '''
        vx = -np.sin(self.phase + self._omega_t(t))
        vy = np.cos(self.phase + self._omega_t(t))
        vz = np.zeros_like(vx)

        return parameters.Vio * np.array([vx, vy, vz])

import unittest
import doctest


def doctests():
    return unittest.TestSuite((
        doctest.DocTestSuite(),
        ))
if __name__ == '__main__':
    unittest.main(defaultTest='doctests')