o
    g                     @   sF   d 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	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UTCg oP@ETg oP)r   r   Nc                 C   sJ  |du r|dusJ|dur|du sJ|dur|dusJ|dusJ|du r,|du r,|du sJ|du sJ|dur4|dusJ|dur@|dusJ|dusJ|durTt |tjsTtd||||f tj| j|d || _|durgt|}|durt	|d }t
|| _|| j d | _dS t	|| _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   check_in_listallowed_framer   floatmathfloor_jd_seconds)selfr   secjddaynumdt	deltaDays r   `/home/ubuntu/cloudmapper/venv/lib/python3.10/site-packages/matplotlib/testing/jpl_units/Epoch.py__init__   s6   


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   convertS   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   secondsPaste   s
   


zEpoch.secondsPastc                 C      |  |tjS r   )_cmpoperatoreqr   rhsr   r   r   __eq__m      zEpoch.__eq__c                 C   r(   r   )r)   r*   ner,   r   r   r   __ne__p   r/   zEpoch.__ne__c                 C   r(   r   )r)   r*   ltr,   r   r   r   __lt__s   r/   zEpoch.__lt__c                 C   r(   r   )r)   r*   ler,   r   r   r   __le__v   r/   zEpoch.__le__c                 C   r(   r   )r)   r*   gtr,   r   r   r   __gt__y   r/   zEpoch.__gt__c                 C   r(   r   )r)   r*   ger,   r   r   r   __ge__|   r/   zEpoch.__ge__c                 C   sD   | }| j |j kr| |j }|j|jkr||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-   opr$   r   r   r   r)      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r"| |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	   )	matplotlib.testing.jpl_unitstesting	jpl_unitsr
   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 )rD   )strr"   r   r   r   __repr__   s   zEpoch.__repr__c                 C   s8   g }d}	 | ||  }||kr	 |S | | |d7 }q)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   T   )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.   r1   r3   r5   r7   r9   r)   r<   rC   rE   rG   staticmethodrP   r   r   r   r   r      s0    
	<r   )
__doc__r*   r   r   r   
matplotlibr   matplotlib.datesr   r   r   r   r   r   <module>   s    