
    R1i                         d Z ddlmZmZmZmZmZmZmZ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mZmZmZ ddlmZ eez  Zddez  z
  Zeez  Zd ZddZ d	 Z!d
 Z"ddZ#d Z$d Z%y)z2Formulae for specific earth behaviors and effects.    )absarcsinarccosarctan2arrayclipcosminimumpisinsqrttanwhere
zeros_like   )	AU_MANGVELDAY_SDEG2RADERAD"IERS_2010_INVERSE_EARTH_FLATTENINGRAD2DEGT0tau)dots      ?c                    t        |      }t        |       }t        |       }dt        ||z  ||z  t        z  z         z  }t        |z  }t
        |z  |z   }	t
        |z  |z   }
dt        z  |z  |z   }t        |      }t        |      }|	|z  }||z  }||z  }t        ||||
|z  z   f      }t        t        z  t        | ||f      z  }||fS )zDDeprecated conversion from lat,lon,t -> GCRS; neglects polar motion.r   g      .@)
r   r   r	   r   one_minus_flattening_squaredearth_radius_aur   r   r   r   )latitude	longitude	elevationgastzerosinphicosphicsachashstloclsinstcosstacacsstaccstposvels                      U/home/cursorai/projects/iching/venv/lib/python3.12/site-packages/skyfield/earthlib.pyterrar4      s    dD]F]Fd6F?F?%AAB C 	CA$q(A
A
	
)C
A
	
)C G^d"Y.FKEKE 
vBJEJE
tcFl23
4C 5.55&%!67
7C8O    c                    | \  }}}t        ||z  ||z  z         }t        ||      dt        z  |z  z
  t        z
  t        z  t        z
  }t        ||      }t
        t        z  }	dt        z  }
d|
z  |
|
z  z
  }d}d}||k  rL|dz  }dt        d|t        |      dz  z  z
        z  }t        ||	|z  |z  t        |      z  z   |      }||k  rL|t        |      z  |	|z  z
  t        z  }|||fS )zDDeprecated conversion from GCRS -> lat,lon,t; neglects polar motion.   r   g       @r   r   )
r   r   r   r   r   r   r   r   r   r	   )xyz_aur#   
iterationsxyzRlonlatafe2iCelevation_ms                  r3   reverse_terrarF   ,   s
   GAq!QqS1Q3YA1a=2<$..3s
:R
?C
!Q-CtA00A	Q1B	AA
j.	Q$sR3s8s?3344a!a%"*s3x//3 j. CLAE)T1K[  r5   c                 ,   t        t        | |             }t        t        ||            }t        t        t        |z  d            }t
        |z
  }t        | |      ||z  z  }t        |dd      }t        |      }||z
  t        z  }t
        |z
  |z  }	||	fS )a(  Determine the angle of an object above or below the Earth's limb.

    Given an object's GCRS `position_au` |xyz| vector and the position
    of an `observer_au` as a vector in the same coordinate system,
    return a tuple that provides `(limb_ang, nadir_ang)`:

    limb_angle
        Angle of observed object above (+) or below (-) limb in degrees.
    nadir_angle
        Nadir angle of observed object as a fraction of apparent radius
        of limb: <1.0 means below the limb, =1.0 means on the limb, and
        >1.0 means above the limb.

    r         )	r   r   r   r
   r   r   r   r   r   )
position_auobserver_audisobjdisobsapradzdlimcoszdzdobj
limb_anglenadir_angles
             r3   compute_limb_anglerS   @   s    " ${K01F${K01F 7?V3S9:E JE k*fvo>Ec"E5ME %-7*J :&K{""r5   c                     t        | j                  | j                        }| j                  t        z
  | j                  z   dz  } dd| z  dz
  | z  dz
  | z  dz   | z  dz   | z  z   }|dz  |d	z  z   d	z  S )
zCCompute Greenwich Mean Sidereal Time (GMST) in hours at time ``t``.g    @g5&\R?g^cg%@i>gw$>gd3,C?g(@g     ^@g      8@)earth_rotation_anglewholeut1_fractionr   tdb_fraction)tthetasts      r3   sidereal_timer\   m   s     !!..9E 
2	&'1A1$#$%#$%  $%
% 	
 $%		%%B L54<'4//r5   c                 H    dd| t         z
  |z   z  z   }|dz  | dz  z   |z   dz  S )zReturn the value of the Earth Rotation Angle (theta) for a UT1 date.

    Uses the expression from the note to IAU Resolution B1.8 of 2000.
    Returns a fraction between 0.0 and 1.0 whole rotations.

    gr'̄	?gU擛mf?r   )r   )jd_ut1fraction_ut1ths      r3   rU   rU      s:     
.&2+2LM	MBHv|#l2c99r5   c                     dt        | d| dz   z  z   t        z        z  }|d|z  |dz   z  z  }t        d| k  | dk  z  |d      S )	zGiven an observed altitude, return how much the image is refracted.

    Zero refraction is returned both for objects very near the zenith,
    as well as for objects more than one degree below the horizon.

    go'?g=
ףp=@g@gQ?g     q@rH   gyV@        )r   r   r   )alt_degreestemperature_Cpressure_mbarrds        r3   
refractionrh      s^     	3dkC.?&@@GKLLA	TM!]U%:;<A$+%+*=>3GGr5   c                 v    | }	 |}| t        |||      z   }t        ||z
        j                         dk  }|r	 |S 7)zEGiven an unrefracted `alt` determine where it will appear in the sky.giUMu>)rh   r   max)rc   rd   re   altalt1	convergeds         r3   refractrn      sM    
C
JsM=IId
O'')V3	J r5   N)   )rb   )&__doc__numpyr   r   r   r   r   r   r	   r
   r   r   r   r   r   r   	constantsr   r   r   r   r   r   r   r   r   	functionsr   r   one_minus_flatteningr   r4   rF   rS   r\   rU   rh   rn    r5   r3   <module>rv      s    8C C C CN N N +S#EEE 36JJ <!(*#Z0(:	H	r5   