o
    h                     @   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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   v/var/www/html/construction_image-detection-poc/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   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r||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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   |  | jdd| j S )Print the Epoch.z22.15e )r%   r   r"   r   r   r   __str__   s   zEpoch.__str__c                 C   s   t | S )r4   )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*   	functoolspartialmethodoperatoreq__eq__ne__ne__lt__lt__le__le__gt__gt__ge__ge__r,   r3   r6   r8   staticmethodrA   r   r   r   r   r      s0    
	<	r   )__doc__rE   rG   r   r   r   
matplotlibr   matplotlib.datesr   r   r   r   r   r   <module>   s    