
    R1iU4                        d dl mZmZmZmZmZmZmZ ddlm	Z	m
Z
mZmZmZmZ ddlmZ ddlmZ ddlmZmZmZmZmZmZ ddlmZ ddlmZmZmZ dd	l m!Z!  ed d e
e	z  f      Z"d
dddddZ#d
ddddZ$dddddZ% G d de!      Z& G d de&      Z' G d de(      Z) e)ddd      Z* e)ddd      Z+de*_,        de+_,         G d d e'      Z-y!)"    )arctan2arrayarray2stringcosexpsinsqrt   )ANGVELDAY_SRAD2DEGT0pitau)refract)itrs)_Tangular_velocity_matrixmxmmxvrot_yrot_z)reify)AngleDistance_ltude)VectorFunction   fixed+      )	precision	floatmodesign	threshold	edgeitems)r#   r$   r&   r'   c                   0    e Zd ZdZdZd Zed        Zd Zy)ITRSPositionzFAn |xyz| position in the Earth-centered Earth-fixed (ECEF) ITRS frame.  c                 |    || _         |j                  \  }}}t        t        z  t	        | |d|z  f      z  | _        y )N        )itrs_xyzaur   r   r   _velocity_au_per_d)selfr-   xyzs        U/home/cursorai/projects/iching/venv/lib/python3.12/site-packages/skyfield/toposlib.py__init__zITRSPosition.__init__   s;     ++1a"(5.51"aq9I3J"J    c                     | S N r0   s    r4   targetzITRSPosition.target!   s	     r6   c                     | j                   j                  }| j                  }t        t	        j
                  |            }t        ||      }t        ||      }||ddfS )z/Compute GCRS position and velocity at time `t`.N)r-   r.   r/   r   r   rotation_atr   )r0   trvRTs        r4   _atzITRSPosition._at)   sV    MM##  #$AJAJ!T4r6   N)	__name__
__module____qualname____doc__centerr5   propertyr;   rB   r9   r6   r4   r)   r)      s)    PFK
   r6   r)   c                   N     e Zd ZdZdZ fdZed        Zd Zd Z	d Z
d Z xZS )	GeographicPositionu~  A latitude-longitude-elevation position on Earth.

    Each instance of this class holds an |xyz| vector for a geographic
    position on, above, or below the Earth’s surface, in the ITRS
    reference frame: the international standard for an Earth-centered
    Earth-fixed (ECEF) reference frame.  Instead of instantiating this
    class directly, Skyfield users usually give a reference geoid the
    longitude and latitude they are interested in::

        from skyfield.api import wgs84
        topos = wgs84.latlon(37.3414, -121.6429)

    Once a geographic position has been created, here are its attributes
    and methods:

    Geodeticc                     t         t        |   |       || _        || _        || _        || _        t        |j                        d d d   x| _	        }t        |t        |j                               | _        y )N)superrJ   r5   modellatitude	longitude	elevationr   radians_R_latr   r   	_R_latlon)r0   rO   rP   rQ   rR   r-   rT   	__class__s          r4   r5   zGeographicPosition.__init__F   sk     $0:
 ""$X%5%56tt<<fVUI,=,=+=%>?r6   c           
         dj                  | j                  j                  t        | j                  j
                  fi t        t        | j                  j
                  fi t        t        | j                  j                  fi t              S )Nz2{0} latitude {1} N longitude {2} E elevation {3} m)formatrO   namer   rP   degrees_lat_optionsrQ   _lon_optionsrR   m_elev_optionsr:   s    r4   target_namezGeographicPosition.target_nameO   se    CJJJJOO..?,?//@<@));];	= 	=r6   c                     d|j                   t        z
  |j                  z   z  dz  }|j                  | j                  j
                  z   |dz  z   dz  S )ux  Return the Local Apparent Sidereal Time, in hours, at time ``t``.

        This location’s Local Apparent Sidereal Time (LAST) is the right
        ascension of the zenith at the time ``t``, as measured against
        the “true” Earth equator and equinox (rather than the fictional
        “mean” equator and equinox, which ignore the Earth’s nutation).

        g4;g    @g     ^@g      8@)wholer   tdb_fractiongastrQ   _hours)r0   r>   sprimes      r4   lst_hours_atzGeographicPosition.lst_hours_atW   sL     QWWr\ANN:;gE...'1AATIIr6   c                     |dk(  rd}|dk(  r&dt        | j                  j                   dz        z  }t        |||      }t	        |      S )u  Predict how the atmosphere will refract a position.

        Given a body that is standing ``altitude_degrees`` above the
        true horizon, return an ``Angle`` predicting its apparent
        altitude given the supplied temperature and pressure, either of
        which can be the string ``'standard'`` to use 10°C and a
        pressure of 1010 mbar adjusted for the elevation of this
        geographic location.

        standardg      $@g     @g     @rZ   )r   rR   r]   r   r   )r0   altitude_degreestemperature_Cpressure_mbaralts        r4   r   zGeographicPosition.refractc   sT     J& MJ&"S$..*:*:):U)B%CCM&}ES!!r6   c                 T    t        | j                  t        j                  |            S )uB   Compute rotation from GCRS to this location’s altazimuth system.)r   rU   r   r=   )r0   r>   s     r4   r=   zGeographicPosition.rotation_atu   s    4>>4#3#3A#677r6   c                 L    t        | j                  t              }t        |      S r8   )r   rT   _EARTH_ANGULAR_VELOCITY_VECTORr   )r0   r>   Rs      r4   _dRdt_times_RT_atz$GeographicPosition._dRdt_times_RT_aty   s      ;<&q))r6   )rC   rD   rE   rF   vector_namer5   r   r_   rf   r   r=   rr   __classcell__rV   s   @r4   rJ   rJ   3   s>      K@ = =
J"$8*r6   rJ   c                   D    e Zd ZdZd ZdefdZd Zd Zd Z	d Z
d	 Ze	Zy
)Geoidu  An Earth ellipsoid: maps latitudes and longitudes to |xyz| positions.

    Instead of creating their own geoid object, most Skyfield users
    simply use the `wgs84` object that comes built-in.

    The math for turning a position into latitude and longitude is based
    on Dr. T.S. Kelso's quite helpful article `Orbital Coordinate
    Systems, Part III <https://www.celestrak.org/columns/v02n03/>`_.

    c                     || _         t        |      | _        || _        |dz
  |z  }||z  | _        d|z  }d|z  ||z  z
  | _        y )Nr]         ?g       @)rY   r   radiusinverse_flattening_one_minus_flattening_squared_e2)r0   rY   radius_mr|   omffs         r4   r5   zGeoid.__init__   sW    	*"4!C'+==-03Y*$$q51Q3;r6   r,   c           	         t        |      }t        |      }t        |      }|j                  }|j                  }	| j                  j                  }
|j                  }t        |      }t        |      }| j                  }dt        ||z  ||z  |z  z         z  }||z  }|
|z  }||z   |z  }|t        |	      z  }|t        |	      z  }|
|z  }||z   |z  }t        |||f      } || |||t        |            S )u  Return a `GeographicPosition` for a given latitude and longitude.

        The longitude and latitude should both be specified in degrees.
        If no elevation in meters is supplied, the returned position
        will lie on the surface of the ellipsoid.  Longitude is positive
        towards the east, so supply a negative number for west::

            from skyfield.api import wgs84
            observatory = wgs84.latlon(37.3414, -121.6429)  # 121.6° West

        You can avoid remembering which directions are negative by using
        Skyfield’s compass direction constants, which have the values +1
        and −1::

            from skyfield.api import N, S, E, W
            observatory = wgs84.latlon(37.3414 * N, 121.6429 * W)

        ri   ry   rz   )
r   r   rS   r{   r.   r   r   r}   r	   r   )r0   latitude_degreeslongitude_degreeselevation_mclsrP   rQ   rR   latlon	radius_auelevation_ausinphicosphiomf2cs	radius_xyxyr1   r2   radius_zr3   r?   s                           r4   latlonzGeoid.latlon   s   ( !12"34	{+	KKNN	 ||SS11$v&4)??@@1H M	,&&0SMSM q=$.1a)49i!EEr6   c                     | j                  |      \  }}}}}}}t        ||      t        z
  t        z  t        z
  }	t	        |      t	        |	      fS )u   Return the latitude and longitude of a ``position``.

        The position’s ``.center`` must be 399, the center of the Earth.
        Geodetic latitude and longitude are returned as a pair of
        :class:`~skyfield.units.Angle` objects.

        rS   )_compute_latituder   r   r   r   
r0   positionxyz_aur1   r2   rq   aChypr   r   s
             r4   	latlon_ofzGeoid.latlon_of   sR     )-(>(>x(H%1aS#q!}r!S(2-S!5#555r6   c                 x    | j                  |      \  }}}}}}}t        ||z  ||z  z         |z
  }	t        |	      S )u  Return the height above the Earth’s ellipsoid of a ``position``.

        The position’s ``.center`` must be 399, the center of the Earth.
        A :class:`~skyfield.units.Distance` is returned giving the
        position’s geodetic height above the Earth’s surface.

        )r   r	   r   )
r0   r   r   r1   r2   rq   r   r   r   	height_aus
             r4   	height_ofzGeoid.height_of   sJ     )-(>(>x(H%1aS#sQU*+b0		""r6   c                    | j                  |      \  }}}}}}}t        ||      t        z
  t        z  t        z
  }	t	        ||z  ||z  z         |z
  }
t        t        |      t        |	      t        |
      t        |      |       S )uF  Return the `GeographicPosition` of a ``position``.

        The position’s ``.center`` must be 399, the center of the Earth.
        A `GeographicPosition` is returned giving the position’s
        geodetic ``latitude`` and ``longitude``, and an ``elevation``
        above or below the surface of the ellipsoid.

        r   )rP   rQ   rR   r-   rO   )r   r   r   r   r	   rJ   r   r   )r0   r   r   r1   r2   rq   r   r   r   r   r   s              r4   geographic_position_ofzGeoid.geographic_position_of   s     )-(>(>x(H%1aS#q!}r!S(2-sQU*+b0	!3'C(y)f%
 	
r6   c                     | j                  |      \  }}}}}}}t        ||      t        z
  t        z  t        z
  }	| j	                  |t
        z  |	t
        z        S )u^  Return the point on the ellipsoid directly below a ``position``.

        The position’s ``.center`` must be 399, the center of the Earth.
        Returns a `GeographicPosition` giving the geodetic ``latitude``
        and ``longitude`` that lie directly below the input position,
        and an ``elevation`` above the ellipsoid of zero.

        )r   r   r   r   r   r   r   s
             r4   subpoint_ofzGeoid.subpoint_of   sV     )-(>(>x(H%1aS#q!}r!S(2-{{3=#-88r6   c                    |j                   dk7  r$t        dj                  |j                               |j                  t              j
                  }|\  }}}| j                  j
                  }| j                  }t        ||z  ||z  z         }t        ||      }	dD ]:  }
t        |	      }||z  }|t        d||z  z
        z  }|||z  z   }t        ||      }	< |||||	fS )Nr*   zyou can only calculate a geographic position from a position which is geocentric (center=399), but this position has a center of {0})r   r
   r"   rz   )rG   
ValueErrorrX   	frame_xyzr   r.   r{   r~   r	   r   r   )r0   r   r   r1   r2   r3   ae2rq   r   	iterationsin_lat
e2_sin_latr   r   s                  r4   r   zGeoid._compute_latitude   s    ??c!006x0G 
 ##D),,1aKKNNXX1qsOamI#hGgJ T#
W 4455Bb:o%C#q/C  q!QC,,r6   N)rC   rD   rE   rF   r5   rJ   r   r   r   r   r   r   subpointr9   r6   r4   rw   rw      s=    	 GJ%0Fd
6
#
(9-. &Hr6   rw   WGS84g   @TXAgmtr@IERS2010gfff&TXAgKr@u   World Geodetic System 1984 `Geoid`.

This is the standard geoid used by the GPS system,
and is likely the standard that’s intended
if you are supplied a latitude and longitude
that don’t specify an alternative geoid.

z2International Earth Rotation Service 2010 `Geoid`.c                   .     e Zd ZdZ	 	 d fd	Zd Z xZS )ToposzDDeprecated: use ``wgs84.latlon()`` or ``iers2010.latlon()`` instead.c                    |nRt        |t              r|j                  }n5t        |t        t        t
        f      rt        |ddd      }nt        d      |nRt        |t              r|j                  }n5t        |t        t        t
        f      rt        |ddd      }nt        d      t        j                  |||t        t        | 2         | j                  | _        y )	NrP   NSzrplease provide either latitude_degrees=<float> or latitude=<skyfield.units.Angle object> with north being positiverQ   EWzsplease provide either longitude_degrees=<float> or longitude=<skyfield.units.Angle object> with east being positive)
isinstancer   rZ   strfloattupler   	TypeErroriers2010r   rN   r   r5   rT   R_lat)	r0   rP   rQ   r   r   r   r1   r2   rV   s	           r4   r5   zTopos.__init__)  s     '%('//3u"56%h
CE 9 : : (	5) ) 1 1	C#67 &y+sC H 8 9 9 	(*;[eT3	5 [[
r6   c                     | j                   S r8   )r-   r:   s    r4   itrf_xyzzTopos.itrf_xyzK  s    }}r6   )NNNNr,   r,   r,   )rC   rD   rE   rF   r5   r   rt   ru   s   @r4   r   r   &  s    NGKCF !Dr6   r   N).numpyr   r   r   r   r   r   r	   	constantsr   r   r   r   r   r   earthlibr   framelibr   	functionsr   r   r   r   r   r   descriptorlibr   unitsr   r   r   	vectorlibr   rp   r[   r\   r^   r)   rJ   objectrw   wgs84r   rF   r   r9   r6   r4   <module>r      s    D C C : :    ! * * %!&1efn'=!> WcQ0WQ0ga1 >  8J* J*XV&F V&p 	gy-0Y	2 H & &r6   