3
$ßL]  ã               @   s<   d Z ddlZddlZddlZddlmZ G dd„ deƒZdS )zEpoch module.é    N)Údate2numc               @   s¬   e Zd Zdd(idd)idœZd*dd„Zdd	„ Zd
d„ Zdd„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd d!„ Zd"d#„ Zd$d%„ Zed&d'„ ƒZdS )+ÚEpochÚUTCç o�ÅP@ÚET)r   r   Nc             C   s`  |dkr|dk	s–|dk	r |dks–|dk	r8|dk	s–|dk	s–|dkrX|dkrX|dks–|dks–|dk	rh|dk	s–|dk	r€|dk	s–|dk	s–|dk	rªt |tjƒ rªtd||||f ƒ‚|| jkrÎtd|t| jjƒ ƒf ƒ‚|| _|dk	rät|ƒ}|dk	�rt	|ƒd }t
j|ƒ| _|| j d | _nDt	|ƒ| _t	|ƒ| _t
j| jd ƒ}|  j|7  _|  j|d 8  _dS )a™  Create a new Epoch object.

        Build an epoch 1 of 2 ways:

        Using seconds past a Julian date:
        #   Epoch('ET', sec=1e8, jd=2451545)

        or using a matplotlib day number
        #   Epoch('ET', daynum=730119.5)

        = ERROR CONDITIONS
        - If the input units are not in the allowed list, an error is thrown.

        = INPUT VARIABLES
        - frame     The frame of the epoch.  Must be 'ET' or 'UTC'
        - sec        The number of seconds past the input JD.
        - jd         The Julian date of the epoch.
        - daynum    The matplotlib day number of the epoch.
        - dt         A python datetime instance.
        Nz‰Invalid inputs.  Must enter sec and jd together, daynum by itself, or dt (must be a python datetime).
Sec = %s
JD  = %s
dnum= %s
dt  = %sz9Input frame '%s' is not one of the supported frames of %sg   €QD:Ag     õ@i€Q )Ú
isinstanceÚDTÚdatetimeÚ
ValueErrorÚallowedÚlistÚkeysÚ_framer   ÚfloatÚmathÚfloorÚ_jdÚ_seconds)ÚselfÚframeÚsecÚjdZdaynumÚdtZ	deltaDays© r   úJ/tmp/pip-install-edjban26/matplotlib/matplotlib/testing/jpl_units/Epoch.pyÚ__init__   s8    



zEpoch.__init__c             C   s2   | j |kr| S | j| j  | }t|| j| | jƒS )N)r   r   r   r   r   )r   r   Úoffsetr   r   r   ÚconvertT   s    
zEpoch.convertc             C   s   | j S )N)r   )r   r   r   r   r   \   s    zEpoch.framec             C   s(   | }|| j kr| j|ƒ}|j|jd  S )Ng     õ@)r   r   r   r   )r   r   Útr   r   r   Ú
julianDate_   s    

zEpoch.julianDatec             C   s0   | }|| j kr| j|ƒ}|j| }|j|d  S )Ni€Q )r   r   r   r   )r   r   r   r   Údeltar   r   r   ÚsecondsPastf   s
    


zEpoch.secondsPastc             C   s   | j |tjƒS )N)Ú_cmpÚoperatorÚeq)r   Úrhsr   r   r   Ú__eq__n   s    zEpoch.__eq__c             C   s   | j |tjƒS )N)r"   r#   Úne)r   r%   r   r   r   Ú__ne__q   s    zEpoch.__ne__c             C   s   | j |tjƒS )N)r"   r#   Últ)r   r%   r   r   r   Ú__lt__t   s    zEpoch.__lt__c             C   s   | j |tjƒS )N)r"   r#   Úle)r   r%   r   r   r   Ú__le__w   s    zEpoch.__le__c             C   s   | j |tjƒS )N)r"   r#   Úgt)r   r%   r   r   r   Ú__gt__z   s    zEpoch.__gt__c             C   s   | j |tjƒS )N)r"   r#   Úge)r   r%   r   r   r   Ú__ge__}   s    zEpoch.__ge__c             C   sD   | }| j |j kr| j|j ƒ}|j|jkr6||j|jƒS ||j|jƒS )zÔCompare two Epoch's.

        = INPUT VARIABLES
        - rhs     The Epoch to compare against.
        - op      The function to do the comparison

        = RETURN VALUE
        - Returns op(self, rhs)
        )r   r   r   r   )r   r%   Úopr   r   r   r   r"   €   s    
z
Epoch._cmpc             C   s<   | }| j |jƒ kr| j|j ƒ}|j|jƒ  }t|j ||jƒS )zÃAdd a duration to an Epoch.

        = INPUT VARIABLES
        - rhs     The Epoch to subtract.

        = RETURN VALUE
        - Returns the difference of ourselves and the input Epoch.
        )r   r   r   r   Úsecondsr   r   )r   r%   r   r   r   r   r   Ú__add__“   s
    	zEpoch.__add__c             C   sl   ddl jj}t||jƒr"| |  S | }| j|jkr>| j|jƒ}|j|j }|j|j }|j|j|d | ƒS )az  Subtract two Epoch's or a Duration from an Epoch.

        Valid:
        Duration = Epoch - Epoch
        Epoch = Epoch - Duration

        = INPUT VARIABLES
        - rhs     The Epoch to subtract.

        = RETURN VALUE
        - Returns either the duration between to Epoch's or the a new
          Epoch that is the result of subtracting a duration from an epoch.
        r   Ni€Q )	Zmatplotlib.testing.jpl_unitsZtestingZ	jpl_unitsr   ZDurationr   r   r   r   )r   r%   ÚUr   Údaysr   r   r   r   Ú__sub__¤   s    
zEpoch.__sub__c             C   s   d| j | jƒ| jf S )zPrint the Epoch.z
%22.15e %s)r   r   )r   r   r   r   Ú__str__Â   s    zEpoch.__str__c             C   s   t | ƒS )zPrint the Epoch.)Ústr)r   r   r   r   Ú__repr__Æ   s    zEpoch.__repr__c             C   s:   g }d}x,| ||  }||kr P |j |ƒ |d7 }q
W |S )aÃ  Generate a range of Epoch objects.

        Similar to the Python range() method.  Returns the range [
        start, stop) at the requested step.  Each element will be a
        Epoch object.

        = INPUT VARIABLES
        - start     The starting value of the range.
        - stop      The stop value of the range.
        - step      Step to use.

        = RETURN VALUE
        - Returns a list containing the requested Epoch values.
        r   é   )Úappend)ÚstartÚstopÚstepÚelemsÚiÚdr   r   r   ÚrangeÊ   s    
zEpoch.ranger   g o�ÅPÀ)NNNN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r!   r&   r(   r*   r,   r.   r0   r"   r3   r6   r7   r9   ÚstaticmethodrB   r   r   r   r   r   	   s&   
?r   )	Ú__doc__r#   r   r	   r   Zmatplotlib.datesr   Úobjectr   r   r   r   r   Ú<module>   s
   