a
    s=ic                     @   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rt |tjstd||||f tj| j|d || _|durt|}|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.
        NzInvalid 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   s/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/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   