a
    ߙfbs6                     @   s   d Z ddlZddlmZ ddlmZ ddlm	Z	m
Z
mZ edjZedjZejejZd	d
 Zdd ZdddZdd Zdd Zdd Zdd Zddd ZeedZdd Zdd ZdS ) z
This module contains standard functions for earth orientation, such as
precession and nutation.

This module is (currently) not intended to be part of the public API, but
is instead primarily for internal use in `coordinates`
    N)Time)units   )rotation_matrixmatrix_productmatrix_transposeZB1950ZJ2000c                 C   s   | t  d }d}t||S )a  
    Eccentricity of the Earth's orbit at the requested Julian Date.

    Parameters
    ----------
    jd : scalar or array-like
        Julian date at which to compute the eccentricity

    Returns
    -------
    eccentricity : scalar or array
        The eccentricity (or array of eccentricities)

    References
    ----------
    * Explanatory Supplement to the Astronomical Almanac: P. Kenneth
      Seidelmann (ed), University Science Books (1992).
        @)g:;S逾gkԿg;!?jd1950nppolyvaljdTp r   Dlib/python3.9/site-packages/astropy/coordinates/earth_orientation.pyeccentricity   s    r   c                 C   s    | t  d }d}t||d S )a  
    Computes the mean longitude of perigee of the Earth's orbit at the
    requested Julian Date.

    Parameters
    ----------
    jd : scalar or array-like
        Julian date at which to compute the mean longitude of perigee

    Returns
    -------
    mean_lon_of_perigee : scalar or array
        Mean longitude of perigee in degrees (or array of mean longitudes)

    References
    ----------
    * Explanatory Supplement to the Astronomical Almanac: P. Kenneth
      Seidelmann (ed), University Science Books (1992).
    r   )g~jt?gffffff?gR.@gx.A      @r	   r   r   r   r   mean_lon_of_perigee2   s    r     c                 C   sb   | t  d }|dkrd}d}n0|dkr4d}d| }n|dkrFd}d}ntd	t||| d
 S )a  
    Computes the obliquity of the Earth at the requested Julian Date.

    Parameters
    ----------
    jd : scalar or array-like
        Julian date at which to compute the obliquity
    algorithm : int
        Year of algorithm based on IAU adoption. Can be 2006, 2000 or 1980. The
        2006 algorithm is mentioned in Circular 179, but the canonical reference
        for the IAU adoption is apparently Hilton et al. 06 is composed of the
        1980 algorithm with a precession-rate correction due to the 2000
        precession models, and a description of the 1980 algorithm can be found
        in the Explanatory Supplement to the Astronomical Almanac.

    Returns
    -------
    obliquity : scalar or array
        Mean obliquity in degrees (or array of obliquities)

    References
    ----------
    * Hilton, J. et al., 2006, Celest.Mech.Dyn.Astron. 94, 351. 2000
    * USNO Circular 179
    * Explanatory Supplement to the Astronomical Almanac: P. Kenneth
      Seidelmann (ed), University Science Books (1992).
    r   r   )gߧLggg+eSgb/oi`?g6q'g? ?kGg#~֙@r     )gJE]?g1ZGUCgQhGgJ+י@gC4ؙi  z.invalid algorithm year for computing obliquityr   )jd2000
ValueErrorr   r   )r   	algorithmr   r   Zcorrr   r   r   	obliquityM   s    
r   c                 C   s$   t t| j}t|j}t||S )a  
    Computes the precession matrix from one Julian epoch to another.
    The exact method is based on Capitaine et al. 2003, which should
    match the IAU 2006 standard.

    Parameters
    ----------
    fromepoch : `~astropy.time.Time`
        The epoch to precess from.
    toepoch : `~astropy.time.Time`
        The epoch to precess to.

    Returns
    -------
    pmatrix : 3x3 array
        Precession matrix to get from ``fromepoch`` to ``toepoch``

    References
    ----------
    USNO Circular 179
    )r   _precess_from_J2000_CapitaineZjyearr   dot)Z	fromepochZtoepochZmat_fromto2000Zmat_2000totor   r   r   precession_matrix_Capitaine{   s
    
r   c                 C   sj   | d d }d}d}d}t ||d }t ||d }t ||d }tt| dt|dt| dS )	aP  
    Computes the precession matrix from J2000 to the given Julian Epoch.
    Expression from from Capitaine et al. 2003 as expressed in the USNO
    Circular 179.  This should match the IAU 2006 standard from SOFA.

    Parameters
    ----------
    epoch : scalar
        The epoch as a Julian year number (e.g. J2000 is 2000.0)

    g     @@g      Y@)g*p(,Kg|OپgQRMbs?gxlT[ ?gJ*@gNP4@)gu}geI (.gΎ?g7S|{?gD'@gNP4)gtC@ngy{ݾgMigC|ۿgT8P@r   r   zyr   r   r   r   )epochr   pzetapzpthetazetar   thetar   r   r   r      s    
r   c                 C   s  | d d }|d d }|| }d|d  d| |  }dd|  }d}|||d	f}t ||d
 }	d|d  d| |  }
dd|  }d}|||
d	f}t ||d
 }dd|  d| |  }dd|  }d}|||d	f}t ||d
 }tt| dt|dt|	 dS )z
    Computes the precession matrix from one Besselian epoch to another using
    Newcomb's method.

    ``epoch1`` and ``epoch2`` are in Besselian year numbers.
    g     @     @@gG~@gףp=
wa@gQ?g=
ףp=>@gHzG?gQ1@r   i  gQ^[@g(\?g33333S2@gzǔ@g(\RU@gGz?g33333SEgfffffDr   r    r!   )Zepoch1Zepoch2t1t2ZdtZzeta1Zzeta2Zzeta3r#   r&   Zz1Zz2Zz3r$   r   Ztheta1Ztheta2Ztheta3r%   r'   r   r   r   _precession_matrix_besselian   s,    
r+   c                 C   sF  |dkrPdt fdt fdt fdt fdt fdtfdtfd	tfd
tfdtfdtfg}n||dkrdt fdt fdt fdt fdt fdt fdt fdt fdt fdt fdt fdt fdt fdt fdt fdt fdt fg}ntddd | dD }dd |D }|D ]8}t|d D ]$\}}|| || d! | qqtjj|d"d |D d#S )$zr
    Loads nutation series from data stored in string form.

    Seriestype can be 'lunisolar' or 'planetary'
    	lunisolarnlnlpnFnDnOmpspstpcecectesZ	planetaryZnmeZnveZneaZnmaZnjuZnsaZnurZnneZnpaZspZcpZseZcez&requested invalid nutation series typec                 S   s&   g | ]}| d s| dks|qS )# )
startswithstrip).0lr   r   r   
<listcomp>   s   z'_load_nutation_data.<locals>.<listcomp>
c                 S   s   g | ]}g qS r   r   )r<   _r   r   r   r>           r   c                 S   s   g | ]}|d  qS )r   r   )r<   er   r   r   r>     rA   )names)	intfloatr   split	enumerateappendr   ZrecZ
fromarrays)ZdatastrZ
seriestypeZdtypeslinesZlistsr=   irC   r   r   r   _load_nutation_data   sN     rL   aS  
#l lprime F D Omega longitude_sin longitude_sin*t longitude_cos obliquity_cos obliquity_cos*t,obliquity_sin

0 0 0 0 1 -172064161.0 -174666.0 33386.0 92052331.0 9086.0 15377.0
0 0 2 -2 2 -13170906.0 -1675.0 -13696.0 5730336.0 -3015.0 -4587.0
0 0 2 0 2 -2276413.0 -234.0 2796.0 978459.0 -485.0 1374.0
0 0 0 0 2 2074554.0 207.0 -698.0 -897492.0 470.0 -291.0
0 1 0 0 0 1475877.0 -3633.0 11817.0 73871.0 -184.0 -1924.0
0 1 2 -2 2 -516821.0 1226.0 -524.0 224386.0 -677.0 -174.0
1 0 0 0 0 711159.0 73.0 -872.0 -6750.0 0.0 358.0
0 0 2 0 1 -387298.0 -367.0 380.0 200728.0 18.0 318.0
1 0 2 0 2 -301461.0 -36.0 816.0 129025.0 -63.0 367.0
0 -1 2 -2 2 215829.0 -494.0 111.0 -95929.0 299.0 132.0
0 0 2 -2 1 128227.0 137.0 181.0 -68982.0 -9.0 39.0
-1 0 2 0 2 123457.0 11.0 19.0 -53311.0 32.0 -4.0
-1 0 0 2 0 156994.0 10.0 -168.0 -1235.0 0.0 82.0
1 0 0 0 1 63110.0 63.0 27.0 -33228.0 0.0 -9.0
-1 0 0 0 1 -57976.0 -63.0 -189.0 31429.0 0.0 -75.0
-1 0 2 2 2 -59641.0 -11.0 149.0 25543.0 -11.0 66.0
1 0 2 0 1 -51613.0 -42.0 129.0 26366.0 0.0 78.0
-2 0 2 0 1 45893.0 50.0 31.0 -24236.0 -10.0 20.0
0 0 0 2 0 63384.0 11.0 -150.0 -1220.0 0.0 29.0
0 0 2 2 2 -38571.0 -1.0 158.0 16452.0 -11.0 68.0
0 -2 2 -2 2 32481.0 0.0 0.0 -13870.0 0.0 0.0
-2 0 0 2 0 -47722.0 0.0 -18.0 477.0 0.0 -25.0
2 0 2 0 2 -31046.0 -1.0 131.0 13238.0 -11.0 59.0
1 0 2 -2 2 28593.0 0.0 -1.0 -12338.0 10.0 -3.0
-1 0 2 0 1 20441.0 21.0 10.0 -10758.0 0.0 -3.0
2 0 0 0 0 29243.0 0.0 -74.0 -609.0 0.0 13.0
0 0 2 0 0 25887.0 0.0 -66.0 -550.0 0.0 11.0
0 1 0 0 1 -14053.0 -25.0 79.0 8551.0 -2.0 -45.0
-1 0 0 2 1 15164.0 10.0 11.0 -8001.0 0.0 -1.0
0 2 2 -2 2 -15794.0 72.0 -16.0 6850.0 -42.0 -5.0
0 0 -2 2 0 21783.0 0.0 13.0 -167.0 0.0 13.0
1 0 0 -2 1 -12873.0 -10.0 -37.0 6953.0 0.0 -14.0
0 -1 0 0 1 -12654.0 11.0 63.0 6415.0 0.0 26.0
-1 0 2 2 1 -10204.0 0.0 25.0 5222.0 0.0 15.0
0 2 0 0 0 16707.0 -85.0 -10.0 168.0 -1.0 10.0
1 0 2 2 2 -7691.0 0.0 44.0 3268.0 0.0 19.0
-2 0 2 0 0 -11024.0 0.0 -14.0 104.0 0.0 2.0
0 1 2 0 2 7566.0 -21.0 -11.0 -3250.0 0.0 -5.0
0 0 2 2 1 -6637.0 -11.0 25.0 3353.0 0.0 14.0
0 -1 2 0 2 -7141.0 21.0 8.0 3070.0 0.0 4.0
0 0 0 2 1 -6302.0 -11.0 2.0 3272.0 0.0 4.0
1 0 2 -2 1 5800.0 10.0 2.0 -3045.0 0.0 -1.0
2 0 2 -2 2 6443.0 0.0 -7.0 -2768.0 0.0 -4.0
-2 0 0 2 1 -5774.0 -11.0 -15.0 3041.0 0.0 -5.0
2 0 2 0 1 -5350.0 0.0 21.0 2695.0 0.0 12.0
0 -1 2 -2 1 -4752.0 -11.0 -3.0 2719.0 0.0 -3.0
0 0 0 -2 1 -4940.0 -11.0 -21.0 2720.0 0.0 -9.0
-1 -1 0 2 0 7350.0 0.0 -8.0 -51.0 0.0 4.0
2 0 0 -2 1 4065.0 0.0 6.0 -2206.0 0.0 1.0
1 0 0 2 0 6579.0 0.0 -24.0 -199.0 0.0 2.0
0 1 2 -2 1 3579.0 0.0 5.0 -1900.0 0.0 1.0
1 -1 0 0 0 4725.0 0.0 -6.0 -41.0 0.0 3.0
-2 0 2 0 2 -3075.0 0.0 -2.0 1313.0 0.0 -1.0
3 0 2 0 2 -2904.0 0.0 15.0 1233.0 0.0 7.0
0 -1 0 2 0 4348.0 0.0 -10.0 -81.0 0.0 2.0
1 -1 2 0 2 -2878.0 0.0 8.0 1232.0 0.0 4.0
0 0 0 1 0 -4230.0 0.0 5.0 -20.0 0.0 -2.0
-1 -1 2 2 2 -2819.0 0.0 7.0 1207.0 0.0 3.0
-1 0 2 0 0 -4056.0 0.0 5.0 40.0 0.0 -2.0
0 -1 2 2 2 -2647.0 0.0 11.0 1129.0 0.0 5.0
-2 0 0 0 1 -2294.0 0.0 -10.0 1266.0 0.0 -4.0
1 1 2 0 2 2481.0 0.0 -7.0 -1062.0 0.0 -3.0
2 0 0 0 1 2179.0 0.0 -2.0 -1129.0 0.0 -2.0
-1 1 0 1 0 3276.0 0.0 1.0 -9.0 0.0 0.0
1 1 0 0 0 -3389.0 0.0 5.0 35.0 0.0 -2.0
1 0 2 0 0 3339.0 0.0 -13.0 -107.0 0.0 1.0
-1 0 2 -2 1 -1987.0 0.0 -6.0 1073.0 0.0 -2.0
1 0 0 0 2 -1981.0 0.0 0.0 854.0 0.0 0.0
-1 0 0 1 0 4026.0 0.0 -353.0 -553.0 0.0 -139.0
0 0 2 1 2 1660.0 0.0 -5.0 -710.0 0.0 -2.0
-1 0 2 4 2 -1521.0 0.0 9.0 647.0 0.0 4.0
-1 1 0 1 1 1314.0 0.0 0.0 -700.0 0.0 0.0
0 -2 2 -2 1 -1283.0 0.0 0.0 672.0 0.0 0.0
1 0 2 2 1 -1331.0 0.0 8.0 663.0 0.0 4.0
-2 0 2 2 2 1383.0 0.0 -2.0 -594.0 0.0 -2.0
-1 0 0 0 2 1405.0 0.0 4.0 -610.0 0.0 2.0
1 1 2 -2 2 1290.0 0.0 0.0 -556.0 0.0 0.0
r,   c                 C   sL  t t| d}| t d }dd|  d t }dd|  d t }dd	|  d t }d
d|  d t }dd|  d t }t}|j| |j|  |j|  |j	|  |j
|  }	t |	}
t |	}td }t |j|j|  |
 |j|  | }t |j|j|  | |j|
  | }td }d| }d| }||| || fS )aW  
    Computes nutation components following the IAU 2000B specification

    Parameters
    ----------
    jd : scalar
        epoch at which to compute the nutation components as a JD

    Returns
    -------
    eps : float
        epsilon in radians
    dpsi : float
        dpsi in radians
    deps : float
        depsilon in raidans
    r   i  gKAgoDTAi g&S3Ag A1Ag~Ag[BAg!%\0AgB`M0Ag˿yAg&¢Zg    cAr(   gHzGgE?)r   Zradiansr   r   _asecperrad_nut_data_00br-   r.   r/   r0   r1   ZsinZcossumr2   r3   r4   r5   r6   r7   )r   epsatZelZelpFDZOmZdatargZsargZcargZp1u_asecperradZdpsilsZdepslsZm_asecperradZdpsiplZdepsplr   r   r   nutation_components2000B]  s$    2

((rV   c                 C   s<   t | j\}}}tt||  ddt| ddt|ddS )z
    Nutation matrix generated from nutation components.

    Matrix converts from mean coordinate to true coordinate as
    r_true = M * r_mean
    xFr   )rV   r   r   r   )r"   rQ   ZdpsiZdepsr   r   r   nutation_matrix  s
    
rX   )r   )__doc__Znumpyr   Zastropy.timer   Zastropyr   uZmatrix_utilitiesr   r   r   r   r
   r   ZradiantoZarcsecrN   r   r   r   r   r   r+   rL   rO   rV   rX   r   r   r   r   <module>   s(   	


.#2PQ
2