
    R1i                     P    d Z ddlZddlmZ ddlmZ ddlmZ ddlm	Z	m
Z
 d Zd	 Zy)
aC  Constellation identification.

Constellation identification is tradionally performed with:

http://cdsarc.u-strasbg.fr/viz-bin/Cat?VI/42
https://iopscience.iop.org/article/10.1086/132034/pdf

Given a position, a binary search can be used to index into its roughly
12k data table for a matching declination, but the table then needs to
be scanned linearly for the first subsequent segment that contains the
target right ascension within its bounds.  The big problem for Skyfield:
that algorithm can't be constructed from vectorized NumPy primitives.

So we here take an approach that requires no linear search.  The sky is
divided into a grid, with a grid line at every right ascension and
declination that is mentioned in a constellation boundary.  This is a
bit wasteful, as many values are only ever used for one boundary, but
makes the search easy: do a binary search for right ascension, then for
declination, then look up the indexes in the grid.  Memory requirement:

  1.8k  right ascension table
  1.6k  declination table
 46.6k  grid table
    1k  constellation name abbreviations

    N)searchsorted)get_data   )load_bundled_npy)Timejulian_date_of_besselian_epochc                      t        dt        d            t        d      } | d   | d   | d   | d   fd}|S )	aL  Load Skyfield's constellation boundaries and return a lookup function.

    Skyfield carries an internal map of constellation boundaries that is
    optimized for quick position lookup.  Call this function to load the
    map and return a function mapping position to constellation name.

    >>> from skyfield.api import position_of_radec, load_constellation_map
    >>> constellation_at = load_constellation_map()
    >>> north_pole = position_of_radec(0, 90)
    >>> constellation_at(north_pole)
    'UMi'

    If you pass an array of positions, you'll receive an array of names.

    NiS  zconstellations.npz	sorted_ra
sorted_decradec_to_indexindexed_abbreviationsc                     | j                        \  }}}t        
|j                        }t        	|j                  d      }||f   }|   S )N)epochright)side)radecr   hoursdegrees)positionradecdistanceijkr   r   r   r
   t1875s          ]/home/cursorai/projects/iching/venv/lib/python3.12/site-packages/skyfield/constellationlib.pyconstellation_atz0load_constellation_map.<locals>.constellation_at:   sU    $NNN7CBHH-S[[w?1a4 $Q''    )r   r   r   )arraysr   r   r   r   r
   r   s     @@@@@r   load_constellation_mapr!   "   s_      5d;<E23F{#I%J,-N"#:;( ( r   c                      t        dd      } t        j                  | t        j                  dz         j	                  d      } | j                         D cg c]  }|j                  dd       c}S c c}w )u?  Return a list of abbreviation-name tuples, like ``('Aql', 'Aquila')``.

    You can pass the list to Python’s ``dict()`` to build a dictionary
    that turns a constellation abbreviation into a full name:

    >>> from skyfield.api import load_constellation_names
    >>> d = dict(load_constellation_names())
    >>> d['UMa']
    'Ursa Major'

    By swapping the order of the two items, you can map the other way,
    from a full name back to an abbreviation:

    >>> f = dict(reversed(item) for item in load_constellation_names())
    >>> f['Ursa Major']
    'UMa'

    skyfieldzdata/constellations.gz    )wbitsascii r   )r   zlib
decompress	MAX_WBITSdecode
splitlinessplit)datalines     r   load_constellation_namesr0   C   sa    & J 89D??4t~~b'89@@ID+/??+<=+<4DJJsA+<===s   A2)__doc__r(   numpyr   pkgutilr   	functionsr   timelibr   r   r!   r0    r   r   <module>r7      s&   4    ' 9B>r   