
    zYHh                     T    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      Z
y)zEpoch module.    N)_api)date2numc                      e Zd ZddiddidZddZd Zd	 Zd
 Zd Zd Z	 e
j                  e	ej                        Z e
j                  e	ej                        Z e
j                  e	ej"                        Z e
j                  e	ej&                        Z e
j                  e	ej*                        Z e
j                  e	ej.                        Zd Zd Zd Zd Zed        Zy)EpochUTCg oP@ETg oP)r   r   Nc           
      v   ||8||4||0|.|||(|&||"||||1t        |t        j                        st        d|d|d|d|      t	        j
                  | j                  |       || _        |t        |      }|@t        |      dz   }t        j                  |      | _        || j                  z
  dz  | _        yt        |      | _        t        |      | _        t        j                  | j                  d	z        }| xj                  |z  c_        | xj                  |dz  z  c_        y)
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.
        NzlInvalid inputs.  Must enter sec and jd together, daynum by itself, or dt (must be a python datetime).
Sec = z
JD  = z
dnum= z
dt  = )frameg   QD:A     @Q )
isinstanceDTdatetime
ValueErrorr   check_in_listallowed_framer   floatmathfloor_jd_seconds)selfr
   secjddaynumdt	deltaDayss          [/var/www/html/planif/env/lib/python3.12/site-packages/matplotlib/testing/jpl_units/Epoch.py__init__zEpoch.__init__   s1   , [R^RZ#/R^BJ+#S_.*R*E "2vr34 4 	4<<u5>b\Fv*Bzz"~DH$((]g5DM "#JDMRyDH 

4==5#89IHH	!HMMY00M    c                     | j                   |k(  r| S | j                  | j                      |   }t        || j                  |z   | j                        S N)r   r   r   r   r   )r   r
   offsets      r   convertzEpoch.convertT   sF    ;;%Kdkk*51UDMMF2DHH==r!   c                     | j                   S r#   )r   r   s    r   r
   zEpoch.frame\   s    {{r!   c                 ~    | }|| j                   k7  r| j                  |      }|j                  |j                  dz  z   S )Nr   r   r%   r   r   )r   r
   ts      r   
julianDatezEpoch.julianDate_   s9    DKKU#AuuqzzG+++r!   c                     | }|| j                   k7  r| j                  |      }|j                  |z
  }|j                  |dz  z   S )Nr   r)   )r   r
   r   r*   deltas        r   secondsPastzEpoch.secondsPastf   sA    DKKU#A
zzEEM))r!   c                    | }| j                   |j                   k7  r| j                  |j                         }|j                  |j                  k7  r ||j                  |j                        S  ||j                  |j                        S )z4Compare Epochs *self* and *rhs* using operator *op*.r)   )r   oprhsr*   s       r   _cmpz
Epoch._cmpn   sc    ;;#**$SZZ(A55CGGaeeSWW%%!**cll++r!   c                     | }| j                   |j                         k7  r| j                  |j                         }|j                  |j	                         z   }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   r1   r*   r   s       r   __add__zEpoch.__add__~   sX     ;;#))+%SZZ(Ajj3;;=(QXXsAEE**r!   c                 `   ddl mc m} t        ||j                        r| | z   S | }| j
                  |j
                  k7  r| j                  |j
                        }|j                  |j                  z
  }|j                  |j                  z
  }|j	                  |j
                  |dz  |z         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   r1   Ur*   daysr   s         r   __sub__zEpoch.__sub__   s      	10 c1::&3$;;;#**$SZZ(Auuswwjj3<<'zz#**d5j3&677r!   c                 X    | j                  | j                        dd| j                   S )Print the Epoch.z22.15e )r+   r   r'   s    r   __str__zEpoch.__str__   s'    //$++.v6a}EEr!   c                     t        |       S )r?   )strr'   s    r   __repr__zEpoch.__repr__   s    4yr!   c                 Z    g }d}	 | ||z  z   }||k\  r	 |S |j                  |       |dz  }')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ds         r   rangezEpoch.range   sK    " D ADy
  LLOFA r!   )NNNN)__name__
__module____qualname__r   r    r%   r
   r+   r.   r2   	functoolspartialmethodoperatoreq__eq__ne__ne__lt__lt__le__le__gt__gt__ge__ge__r5   r=   rA   rD   staticmethodrN    r!   r   r   r      s    
 8 (	
G:1x>,*, %Y$$T8;;7F$Y$$T8;;7F$Y$$T8;;7F$Y$$T8;;7F$Y$$T8;;7F$Y$$T8;;7F+$8>F  r!   r   )__doc__rR   rT   r   r   r   
matplotlibr   matplotlib.datesr   r   rb   r!   r   <module>rf      s&          %G Gr!   