
    R1i(                         d Z ddlmZmZ ddlmZmZ ddlmZm	Z	 ddl
mZ ddlmZ ddlmZ dd	lmZ e d
 Zd Zg dZg dZg dZd Zg dZd Zd ZddgZd ZddgZd ZddgZd Z d Z!dddd d!d"Z"d# Z#	 d&d$Z$y%)'zIRoutines to solve for circumstances like sunrise, sunset, and moon phase.    )print_functiondivision)cos
zeros_like   )pitau)ecliptic_frame)find_discrete)iau2000b_radians)Anglec                 v    | d   j                  |      j                  | |         }|j                  | d         S )z~
    .. deprecated:: 1.42
       Use the :meth:`~skyfield.positionlib.ICRF.phase_angle()` position
       method instead.
    earthsun)atobservephase_angle)	ephemerisbodytps       T/home/cursorai/projects/iching/venv/lib/python3.12/site-packages/skyfield/almanac.pyr   r      s<     	'a ((49A==5)**    c                 R    t        | ||      j                  }ddt        |      z   z  S )z
    .. deprecated:: 1.42
       Use the :meth:`~skyfield.positionlib.ICRF.fraction_illuminated()`
       position method instead.
    g      ?g      ?)r   radiansr   )r   r   r   as       r   fraction_illuminatedr      s+     	ItQ'//A#A,r   )SpringSummerAutumnWinter)zVernal EquinoxzSummer SolsticezAutumnal EquinoxzWinter Solstice)zMarch EquinoxzJune SolsticezSeptember EquinoxzDecember Solsticec                 8    | d   | d   fd}d|_         |S )a  Build a function of time that returns the quarter of the year.

    The function that this returns will expect a single argument that is
    a :class:`~skyfield.timelib.Time` and will return 0 through 3 for
    the seasons Spring, Summer, Autumn, and Winter.

    r   r   c                 
   t        |       | _        j                  |       }|j                        j	                         j                  t              \  }}}|j                  t        dz  z  dz  j                  t              S )z8Return season 0 (Spring) through 3 (Winter) at time `t`.   r   _nutation_angles_radiansr   r   apparentframe_latlonr
   r   r	   astypeint)r   e_slonr   r   s       r   	season_atzseasons.<locals>.season_atG   sg    %5a%8"HHQKYYs^,,.;;NK
4q)A-55c::r   g     V@	step_days)r   r.   r   r   s     @@r   seasonsr1   <   s.     gE
E
C; Ir   )zNew MoonzFirst Quarterz	Full MoonzLast Quarterc                 j   | d   j                  |      }| d   | d   }}|j                  |      j                         j                  t              \  }}}|j                  |      j                         j                  t              \  }}}t        |j                  |j                  z
  t        z        S )uh  Return the Moon phase 0°–360° at time ``t``, where 180° is Full Moon.

    More precisely: this returns an :class:`~skyfield.units.Angle`
    giving the difference between the geocentric apparent ecliptic
    longitudes of the Moon and Sun, constrained to the interval 0°–360°
    (0–𝜏 radians) where 0° is New Moon and 180° is Full Moon.

    r   moonr   )r   )r   r   r'   r(   r
   r   r   r	   )r   r   r+   r3   r   r,   mlonr-   s           r   
moon_phaser5   X   s     	'a A&!9U#3#D4))+88HJAtQ3((*77GJAtQ$,,5<==r   c                 F    | d   | d   | d   fd}d|_         |S )aP  Build a function of time that returns the moon phase 0 through 3.

    The function that this returns will expect a single argument that is
    a :class:`~skyfield.timelib.Time` and will return the phase of the
    moon as an integer.  See the accompanying array ``MOON_PHASES`` if
    you want to give string names to each phase.

    r   r3   r   c                    t        |       | _        j                  |       }|j                        j	                         j                  t              \  }}}|j                        j	                         j                  t              \  }}}|j                  |j                  z
  t        dz  z  dz  j                  t              S )5Return the phase of the moon 0 through 3 at time `t`.r$   r%   )r   r+   r,   r4   r-   r   r3   r   s        r   moon_phase_atz"moon_phases.<locals>.moon_phase_att   s    %5a%8"HHQKYYt_--/<<^L
4YYs^,,.;;NK
4,#':Q>FFsKKr   g      @r/   )r   r9   r   r3   r   s     @@@r   moon_phasesr:   g   s9     gEVD
E
CL "Mr   
descending	ascendingc                 8    | d   | d   fd}d|_         |S )a  Build a function of time that identifies lunar nodes.

    This returns a function taking a :class:`~skyfield.timelib.Time` and
    returning ``True`` if the Moon is above the ecliptic else ``False``.
    See :ref:`lunar-nodes` for how to use this routine.

    r   r3   c                     j                  |       }|j                        j                         j                  t              \  }}}|j
                  dkD  S )r8   g        )r   r   r'   r(   r
   r   )r   r+   latr,   r   r3   s       r   moon_node_atz moon_nodes.<locals>.moon_node_at   sF    HHQKIIdO,,.;;NK	Q{{S  r   g      (@r/   )r   r@   r   r3   s     @@r   
moon_nodesrA      s.     gEVD! "Lr   conjunction
oppositionc                     | d   j                   | d   fd}j                  dk(  r	d|_        |S d|_        |S )zBuild a function to find oppositions and conjunctions with the Sun.

    See :ref:`oppositions-conjunctions` for how to call this routine and
    interpret the results.

    r   r   c                 P    |       }|j                        j                         j                  t              \  }}}|j                        j                         j                  t              \  }}}|j                  |j                  z
  t
        z  dz  j                  d      S )z5Return whether the target is east or west of the Sun.g       @int8)r   r'   r(   r
   r   r   r)   )r   r+   r,   r-   tlonearth_atr   targets        r   leading_or_trailingz5oppositions_conjunctions.<locals>.leading_or_trailing   s    QKYYs^,,.;;NK
4YYv&//1>>~N
4,2S8@@HHr   i-     (   )r   rI   r0   )r   rI   rJ   rH   r   s    ` @@r   oppositions_conjunctionsrM      sU     !$$H
E
CI }}(*%  )+%r   zAntimeridian transitzMeridian transitc                 L    | d   z   j                   fd}d|_        |S )u  Build a function of time for finding when a body transits the meridian.

    The returned function accepts a :class:`~skyfield.timelib.Time`
    argument and returns ``True`` if the ``target`` body is west of the
    observer’s meridian at that time, and otherwise returns ``False.``
    See :ref:`transits` for how to use this to search for a body’s
    meridian transits and antimeridian transits.

    r   c                 .   t        |       | _        j                  |       j                  d      \  }}} |       j	                        j                         j                  d      \  }}}|j                  |j                  z
  t        z  t        k  S )uA   Return `True` if the target is west of the observer’s meridian.date)epoch)	r   r&   r   radecr   r'   r   r	   r   )r   ra1r,   ra2rI   topostopos_ats       r   west_of_meridian_atz.meridian_transits.<locals>.west_of_meridian_at   s    %5a%8"
 HHQK%%F%3	QQK''/88:@@v@N	Qckk)S0255r   g?r   r0   )r   rI   rU   rW   rV   s    `` @r   meridian_transitsrY      s0     '"U*..H	6 %(!r   c                 R    | d   | d   |z   j                   fd}d|_        |S )ul  Build a function of time that returns whether the Sun is up.

    The function that is returned will expect a single argument that is
    a :class:`~skyfield.timelib.Time`, and will return ``True`` if the
    sun is up, else ``False``.

    Skyfield uses the same definition as the United States Naval
    Observatory: the Sun is up when its center is 0.8333 degrees below
    the horizon, which accounts for both its apparent radius of around
    16 arcminutes and also for the 34 arcminutes by which atmospheric
    refraction on average lifts the image of the Sun.

    If you need to provide a custom value for refraction, adjust the
    estimate of the Sun’s radius, or account for a vantage point above
    the Earth’s surface, see :ref:`risings-and-settings` to learn about
    the more versatile :func:`~skyfield.almanac.risings_and_settings()`
    routine.

    r   r   c                     t        |       | _         |       j                        j                         j	                         d   j
                  dk\  S )zReturn `True` if the sun has risen by time `t`.

        The Sun has risen if its altitude above the horizon is greater
        than -0.8333 degrees.

        r   7d꿩r   r&   r   r'   altazdegrees)r   r   rV   s    r   is_sun_up_atz$sunrise_sunset.<locals>.is_sun_up_at   sI     &6a%8"{""3'00288:1=EEPPr   {Gz?rX   )r   rU   r`   r   rV   s      @@r   sunrise_sunsetrb      s:    ( E
C'"U*..HQ "Lr   NightzAstronomical twilightzNautical twilightzCivil twilightDay)r   r         r$   c                 R    | d   | d   |z   j                   fd}d|_        |S )u`  Build a function of time returning whether it is dark, twilight, or day.

    The function that this returns will expect a single argument that is
    a :class:`~skyfield.timelib.Time` and will return:

    | 0 — Dark of night.
    | 1 — Astronomical twilight.
    | 2 — Nautical twilight.
    | 3 — Civil twilight.
    | 4 — Sun is up.

    r   r   c                    t        |       | _         |       j                        j                         j	                         d   j
                  }t        |t              }d||dk\  <   d||dk\  <   d||dk\  <   d||d	k\  <   |S )
zAReturn whether the Sun is up, down, or whether there is twilight.r   r   g      2re   g      (rf   g      r$   r\   )r   r&   r   r'   r^   r_   r   r*   )r   r_   rr   rV   s      r   is_it_dark_twilight_day_atz5dark_twilight_day.<locals>.is_it_dark_twilight_day_at  s    %5a%8"1+%%c*335;;=a@HHw$'U
'U
'T/ !'W
r   ra   rX   )r   rU   rj   r   rV   s      @@r   dark_twilight_dayrk      s:     E
C'"U*..H	 ,0(%%r   c                 V    | d   |z   j                   ||z
  fd}d|_        |S )u  Build a function of time that returns whether a body is up.

    This returns a function taking a :class:`~skyfield.timelib.Time`
    argument returning ``True`` if the body’s altazimuth altitude angle
    plus ``radius_degrees`` is greater than ``horizon_degrees``, else
    ``False``.  See :ref:`risings-and-settings` to learn about how to
    search for risings and settings, and to see more about using the
    parameters ``horizon_degrees`` and ``radius_degrees``.

    r   c                     t        |       | _         |       j                        j                         j	                         d   j
                  kD  S )z2Return `True` if the target has risen by time `t`.r   r]   )r   hrI   rV   s    r   is_body_up_atz+risings_and_settings.<locals>.is_body_up_at)  sG    %5a%8"{""6*335;;=a@HH1LLr   g      ?rX   )r   rI   rU   horizon_degreesradius_degreesro   rn   rV   s    `    @@r   risings_and_settingsrr     s:     '"U*..H.(AM
 #Mr   N)g""""""r   )%__doc__
__future__r   r   numpyr   r   	constantsr   r	   framelibr
   	searchlibr   nutationlibr   unitsr   r   r   SEASONSSEASON_EVENTSSEASON_EVENTS_NEUTRALr1   MOON_PHASESr5   r:   
MOON_NODESrA   CONJUNCTIONSrM   MERIDIAN_TRANSITSrY   rb   	TWILIGHTSrk   rr    r   r   <module>r      s    O / !  $ $ )  +  *>2 

* 
. ,-?@ 4"J 	&> EFr   