
    R1iH                     b    d dl Z d dlZd dlmZmZ d dlmZ ddlmZ  e       Z	d Z
d Zd Zd	 Zy)
    N)datetime	timedelta)Lock   )julian_datec                     | d   }t        j                  |d   |d      }t        j                  | |d d |d f   gd      }|\  }}|||fS )N)r   r   right)sider   )axis)npsearchsortedconcatenate)deltat_datadeltat_predsleap_second_datdata_end_timeidelta_t_recent
leap_datesleap_offsetss           Y/home/cursorai/projects/iching/venv/lib/python3.12/site-packages/skyfield/io_timescale.py_build_legacy_datar   
   sY    &M
QWEA^^[,qt2D$EANN.J:|33    c                     t        j                  |       }|j                  \  }}}}t        j                  t	        |||      |f      S )zParse the United States Naval Observatory ``deltat.data`` file.

    Each line file gives the date and the value of Delta T::

    2016  2  1  68.1577

    This function returns a 2xN array of raw Julian dates and matching
    Delta T values.

    )r   loadtxtTarrayr   )fileobjr   yearmonthdaydelta_ts         r   parse_deltat_datar$      sA     JJwE %D%g88[uc2G<==r   c                    t        |       }t        |      }|j                  d      r2t        |       t        j                  |ddg      j
                  \  }}n&t        j                  |ddg      j
                  \  }}|j                  t              }d|dz  j                  t              dz  z   }t        j                  t        ||d      |f      S )a  Parse the United States Naval Observatory ``deltat.preds`` file.

    The old format supplies a floating point year, the value of Delta T,
    and one or two other fields::

    2015.75      67.97               0.210         0.02

    The new format adds a modified Julian day as the first field:

    58484.000  2019.00   69.34      -0.152       0.117

    This function returns a 2xN array of raw Julian dates and matching
    Delta T values.

    s   YEARr   r   )usecols   g      (@   )
iternext
startswithr   r   r   astypeintr   r   )r   linesheader
year_floatr#   r    r!   s          r   parse_deltat_predsr1       s      ME%[F!U jjA?AA
G !jjA?AA
GS!Dd"**3/"44E88[ua0':;;r   c                 r   t        |       }|D ]  }|j                  d      s n t        d      |j                  d      }t        5  t        j                  t
        j                        }t        j                  t
        j                  d       	 t        j                  |d      }t        j                  t
        j                  |       	 ddd       t        d      }j                         |z   }t        j                  |      j                  \  }}}	}
}t        j                  t!        |      d	z         }d
|d<   |dz   |dd d|d<   t        j                  t!        |      d	z         }|d   x|d<   |d<   ||d	d |||ffS # t        j                  t
        j                  |       w xY w# 1 sw Y   xY w)a   Parse the IERS file ``Leap_Second.dat``.

    The leap dates array can be searched with::

        index = np.searchsorted(leap_dates, jd, 'right')

    The resulting index allows (TAI - UTC) to be fetched with::

        offset = leap_offsets[index]

    s   #  File expires onz.Leap_Second.dat is missing its expiration dateasciiCz#  File expires on %d %B %Y
N   )daysr'   z-infr   g   @OBAr   r	   inf)r)   r+   
ValueErrordecode_locklocale	setlocaleLC_ALLr   strptimer   dater   r   r   ndarraylen)r   r.   lineoriginal_localedtgrace_periodexpiration_datemjdr"   r!   r    offsetsr   r   s                 r   parse_leap_secondsrI   ?   sz    ME??01  IJJ;;wD	 **6==9,	=""4)HIBV]]O< 
 "%Lggi,.O%'ZZ%6%8%8"CeT7CHqL)JJqMYJqJrN::c#hl+L(/
2LOl1oLZ666 V]]O< 
s%   AF-F'$F-&F**F--F6)r;   numpyr   r   r   	threadingr   timelibr   r:   r   r$   r1   rI    r   r   <module>rN      s/      (   4><>)7r   