
    R1i$                         d Z ddlmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZ dd	lmZ dd
lmZ  G d de      Z G d de      Z G d de      Zd Zd Zy)z'Vector functions and their composition.    )target_names)max   )C_AUDAY)reifyDeprecationError)	length_of)build_position)Timec                       e Zd ZdZdZed        Zed        Zed        Zd Z	d Z
d Zd	 Zd
 Zd Zd Zd Zd Z	 	 ddZd Zy)VectorFunctionz0Given a time, computes a corresponding position.Nc                 ,    t        |       j                  S N)type__name__selfs    V/home/cursorai/projects/iching/venv/lib/python3.12/site-packages/skyfield/vectorlib.pyvector_namezVectorFunction.vector_name   s    Dz"""    c                 ,    t        | j                        S r   )	_jpl_namecenterr   s    r   center_namezVectorFunction.center_name       %%r   c                 ,    t        | j                        S r   )r   targetr   s    r   target_namezVectorFunction.target_name   r   r   c                 ^    dj                  t        |       j                  t        |             S )Nz	<{0} {1}>)formatr   r   strr   s    r   __repr__zVectorFunction.__repr__   s#    !!$t*"5"5s4yAAr   c                 V    | j                   | u r| j                  S | j                         S r   )r   r   	arrow_strr   s    r   __str__zVectorFunction.__str__    s'    ;;$###~~r   c                 d    dj                  | j                  | j                  | j                        S )Nz{0} {1} -> {2})r!   r   r   r   r   s    r   r%   zVectorFunction.arrow_str%   s.    &&d..0@0@
 	
r   c                    | j                   |j                  k7  r)|j                   | j                  k(  r|| }} nt        d      t        | dd       xs | f}t        |dd       xs |f}t	        | j                  |j                   ||z         S )Nztyou can only add two vectors if the target where one of the vectors ends is the center where the other vector startsvector_functions)r   r   
ValueErrorgetattr	VectorSum)r   otherself_vfs	other_vfss       r   __add__zVectorFunction.__add__*   s    ;;%,,&||t{{*#Te C  4!3T:EtgE#5t<H	ellHy4HIIr   c                     t        |       S r   )ReversedVectorr   s    r   __neg__zVectorFunction.__neg__:   s    d##r   c                 *   | j                   |j                   k7  rt        d      t        | dd       xs | f}t        |dd       xs |f}t        t	        |D cg c]  }|  c}            }t        |j                  | j                  ||z         S c c}w )NzGyou can only subtract two vectors if they both start at the same centerr)   )r   r*   r+   tuplereversedr,   r   )r   r-   r.   r/   vfs        r   __sub__zVectorFunction.__sub__=   s    ;;%,,&9 
 4!3T:EtgE#5t<H	()#<)BRC)#<=>	t{{I4HII $=s   
Bc                    t        |t              st        dj                  |            | j	                  |      \  }}}}| j
                  }t        ||||| j                        }| j                  |_	        ||_
        ||_        |S )aI  At time ``t``, compute the target's position relative to the center.

        If ``t`` is an array of times, then the returned position object
        will specify as many positions as there were times.  The kind of
        position returned depends on the value of the ``center``
        attribute:

        * Solar System Barycenter: :class:`~skyfield.positionlib.Barycentric`
        * Center of the Earth: :class:`~skyfield.positionlib.Geocentric`
        * Difference: :class:`~skyfield.positionlib.Geometric`
        * Anything else: :class:`~skyfield.positionlib.ICRF`

        z_please provide the at() method with a Time instance as its argument, instead of the value {0!r})
isinstancer   r*   r!   _atr   r   r   	ephemeris
_ephemeris_observer_gcrs_aumessage)r   tpvgcrs_positionr?   r   positions           r   atzVectorFunction.atJ   s     !T" ,,2F1I7 7 (,xx{$1mW!!Q64;;?"nn%2""r   c                     | j                   dk7  r$t        dj                  | j                              t	        ||       S )Nr   ztyou can only observe() a body whose vector center is the Solar System Barycenter, but this vector has the center {0})r   r*   r!   r   _correct_for_light_travel_time)r   observers     r   _observe_from_bcrsz!VectorFunction._observe_from_bcrsd   sB    ;;! C %fT%5%568 8 .h==r   c                     t        d      )Na  the geometry_of() method has, alas, been deprecated

This old method has been replaced by an improved interface.  If you just
need your software working again, install Skyfield 0.9.1 for a quick fix:

    pip install skyfield==0.9.1

Or, to update your old code, replace each operation that looks like:

    position = boston.geometry_of(satellite).at(t)

with the vector math that was previously hiding inside the old method:

    position = (satellite - boston).at(t)r   )r   r-   s     r   geometry_ofzVectorFunction.geometry_ofl   s    -. 	.r   c                     t        d      )Na  the topos() method has, alas, been deprecated

This old method has been replaced by an improved interface.  If you just
need your software working again, install Skyfield 0.9.1 for a quick fix:

    pip install skyfield==0.9.1

Or, to update your old code, replace each operation that looks like:

    boston = earth.topos(...)

with the vector math that was previously hiding inside the old method:

    from skyfield.api import Topos
    boston = earth + Topos(...)r   )r   latitude	longitudelatitude_degreeslongitude_degreeselevation_mxys           r   toposzVectorFunction.topos}   s    #$ 	$r   c                     t        d      )NaM  the satellite() method has, alas, been deprecated

This old method has been replaced by an improved interface.  If you just
need your software working again, install Skyfield 0.9.1 for a quick fix:

    pip install skyfield==0.9.1

Or, to update your old code, replace each operation that looks like:

    sat = earth.satellite(tle_text)

with the vector math (and the little bit of text manipulation) that was
previously hiding inside the old method:

    from skyfield.api import EarthSatellite
    line1, line2 = tle_text.splitlines()[-2:]
    sat = earth + EarthSatellite(line1, line2)r   )r   texts     r   	satellitezVectorFunction.satellite   s    23 	3r   )NNNN        rX   rX   )r   
__module____qualname____doc__r<   r   r   r   r   r#   r&   r%   r0   r3   r8   rE   rI   rK   rT   rW    r   r   r   r      s    :I
# # & & & &B 


J $J4>." EI@C$&3r   r   c                   N    e Zd Zd Zed        Zed        Zed        Zd Zd Z	y)r2   c                 V    |j                   | _        |j                  | _         || _        y r   )r   r   vector_function)r   r_   s     r   __init__zReversedVector.__init__   s$    %,,%,,.r   c                 4    d| j                   j                  z   S )Nz	Reversed )r_   r   r   s    r   r   zReversedVector.vector_name   s    T11====r   c                 .    | j                   j                  S r   )r_   r   r   s    r   r   zReversedVector.center_name       ##///r   c                 .    | j                   j                  S r   )r_   r   r   s    r   r   zReversedVector.target_name   rc   r   c                     | j                   S r   )r_   r   s    r   r3   zReversedVector.__neg__   s    ###r   c                 R    | j                   j                  |      \  }}}}| | d |fS r   )r_   r;   )r   r@   rA   rB   _r?   s         r   r;   zReversedVector._at   s4    //33A61arA2tW$$r   N)
r   rY   rZ   r`   r   r   r   r   r3   r;   r\   r   r   r2   r2      sM    /
 > > 0 0 0 0$%r   r2   c                   $    e Zd Zd Zd Zd Zd Zy)r,   c                 b    || _         || _        || _        d |D        }t        |d       | _        y )Nc              3   L   K   | ]  }|j                   r|j                     y wr   )r<   ).0segments     r   	<genexpr>z%VectorSum.__init__.<locals>.<genexpr>   s'      -8HW!++ ((8Hs   "$)r   r   r)   nextr<   )r   r   r   r)   ephemeridess        r   r`   zVectorSum.__init__   s5     0-8H -k40r   c                     | j                   }|D cg c]  }d|j                         z    }}dj                  t        |      dj	                  |            S c c}w )N zSum of {0} vectors:
{1}
)r)   r%   r!   lenjoin)r   r)   rl   liness       r   r&   zVectorSum.__str__   s`    00:JK:Jww((**:JK)00 !IIe
 	
 Ls   Ac                 $    dj                  |       S )Nz<Vector{0}>)r!   r   s    r   r#   zVectorSum.__repr__   s    ##D))r   c                     d\  }}d }| j                   }|D ]4  }|j                  |      \  }}}	}
|j                  dk(  r| }||z  }||z  }6 |d   j                  dk(  rj                  dk(  r}|||
fS )N)rX   rX   i  r   )r)   r;   r   )r   r@   rA   rB   rC   vfsr7   p2v2rg   r?   s              r   r;   zVectorSum._at   s    1##B!#BAwyyC!"GAGA  q6==A"))s"2M!]G++r   N)r   rY   rZ   r`   r&   r#   r;   r\   r   r   r,   r,      s    1
*,r   r,   c                    | j                   }|j                  }|j                  }|j                  }| j                  j
                  }| j                  j                  }|j                  |      \  }}	}
}t        ||z
        }d}t        d      D ]d  }|t        z  }||z
  }t        t        |            dk  r nH|j                  |||z
        }|j                  |      \  }}	}
}t        ||z
        }|}f t        d      ||z
  |	|z
  ||fS )a  Return a light-time corrected astrometric position and velocity.

    Given an `observer` that is a `Barycentric` position somewhere in
    the solar system, compute where in the sky they will see the body
    `target`, by computing the light-time between them and figuring out
    where `target` was back when the light was leaving it that is now
    reaching the eyes or instruments of the `observer`.

    rX   
   g-q=z$light-travel time failed to converge)r@   tswholetdb_fractionrD   auvelocityau_per_dr;   r
   ranger   r   abstdb_jdr*   )rH   r   r@   r}   r~   r   	cposition	cvelocity	tposition	tvelocityrC   r?   distancelight_time0i
light_timedeltat2s                     r   rG   rG      s    	

A	
BGGE>>L!!$$I!!**I39::a=0Iy-Y./HK2Y'
[(s5z?U"
 YYulZ787=zz"~4	9mWY23   ?@@y )i"7JFFr   c                     t        | t              st        |       j                  S t	        j
                  |       }|t        |       S dj                  | |      S )Nz{0} {1})r:   intr   r   _jpl_code_name_dictgetr"   r!   )r   names     r   r   r   	  sN    fc"F|$$$""6*D|6{FD))r   N)r[   jplephem.namesr   r   numpyr   	constantsr   descriptorlibr   errorsr	   	functionsr
   positionlibr   timelibr   objectr   r2   r,   rG   r   r\   r   r   <module>r      sT    - >     $   ' V3V V3p%^ %2", ",H&GP*r   