a
    ëÝEbØ  ã                   @   sN   d Z ddlZddlZddlZddlZddlmZ ddlm	Z	 G dd„ dƒZ
dS )zEpoch module.é    N)Ú_api)Ú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	e
 e	ej¡Ze
 e	ej¡Ze
 e	ej¡Ze
 e	ej¡Ze
 e	ej¡Ze
 e	ej¡Zdd„ Zdd„ Zdd„ Zdd„ Zedd„ ƒZdS )ÚEpochÚUTCg o�ÅP@ÚETg o�ÅPÀ)r   r   Nc                 C   sJ  |du r|dus”|dur |du s”|dur8|dus”|dus”|du rX|du rX|du s”|du s”|durh|dus”|dur€|dus”|dus”|dur¨t |tjƒs¨td||||f ƒ‚tj| j|d� || _|durÎt|ƒ}|du�rt	|ƒd }t
 |¡| _|| j d | _nDt	|ƒ| _t	|ƒ| _t
 | 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  = %s)Úframeg   €QD:Aç     õ@é€Q )Ú
isinstanceÚDTÚdatetimeÚ
ValueErrorr   Zcheck_in_listÚallowedÚ_framer   ÚfloatÚmathÚfloorÚ_jdÚ_seconds)Úselfr   ÚsecÚjdZdaynumÚdtZ	deltaDays© r   úb/home/ja/django-apps/lartica_env/lib/python3.9/site-packages/matplotlib/testing/jpl_units/Epoch.pyÚ__init__   sf    ÿÿþýýüüûûúúùùùø
ø	
ûÿ


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 r   )r   ©r   r   r   r   r   \   s    zEpoch.framec                 C   s(   | }|| j kr|  |¡}|j|jd  S )Nr   ©r   r   r   r   )r   r   Útr   r   r   Ú
julianDate_   s    

zEpoch.julianDatec                 C   s0   | }|| j kr|  |¡}|j| }|j|d  S )Nr	   r    )r   r   r   r!   Údeltar   r   r   ÚsecondsPastf   s
    


zEpoch.secondsPastc                 C   sD   | }| j |j kr|  |j ¡}|j|jkr6||j|jƒS ||j|jƒS )z4Compare Epochs *self* and *rhs* using operator *op*.r    )r   ÚopÚrhsr!   r   r   r   Ú_cmpn   s    z
Epoch._cmpc                 C   s<   | }| j | ¡ kr|  |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   sr   ddl m  m} t||jƒr(| |  S | }| j|jkrD|  |j¡}|j|j }|j|j }| |j|d | ¡S )aƒ  
        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   Nr	   )	Zmatplotlib.testing.jpl_unitsÚ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f S )úPrint the Epoch.z
%22.15e %s)r"   r   r   r   r   r   Ú__str__¯   s    zEpoch.__str__c                 C   s   t | ƒS )r.   )Ústrr   r   r   r   Ú__repr__³   s    zEpoch.__repr__c                 C   s6   g }d}| ||  }||krq2|  |¡ |d7 }q|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.range)NNNN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r"   r$   r'   Ú	functoolsÚpartialmethodÚoperatorÚeqÚ__eq__ÚneÚ__ne__ÚltÚ__lt__ÚleÚ__le__ÚgtÚ__gt__ÚgeÚ__ge__r)   r-   r/   r1   Ústaticmethodr:   r   r   r   r   r      s.   ÿÿü	
<	r   )Ú__doc__r>   r@   r   r   r   Z
matplotlibr   Zmatplotlib.datesr   r   r   r   r   r   Ú<module>   s   