# Path: skyfield/constants.py
# RAD2DEG = 57.295779513082321
# 
# Path: skyfield/functions.py
# def angle_between(u, v):
#     """Given two vectors `v` and `u`, return the radian angle separating them.
# 
#     This works whether `v` and `u` each have the shape ``(3,)``, or
#     whether they are each whole arrays of corresponding x, y, and z
#     coordinates with shape ``(3, N)``. The returned angle will be
#     between 0 and tau/2.
# 
#     This formula is from Section 12 of:
#     https://people.eecs.berkeley.edu/~wkahan/Mindless.pdf
# 
#     """
#     a = u * length_of(v)
#     b = v * length_of(u)
#     return 2.0 * arctan2(length_of(a - b), length_of(a + b))
# 
# def length_of(xyz):
#     """Given a 3-element array |xyz|, return its length.
# 
#     The three elements can be simple scalars, or the array can be two
#     dimensions and offer three whole series of x, y, and z coordinates.
# 
#     """
#     return sqrt((xyz * xyz).sum(axis=0))
# 
# Path: skyfield/naifcodes.py
# def _target_name(target):
#     """Return `target` annotated for display to the user.
# 
#     * A string target is quoted to make clear that it's a string, like 'comet'.
#     * A numeric target has its NAIF name appended, like 399 EARTH.
# 
#     """
#     if isinstance(target, str):
#         return repr(target)
#     name = code_names.get(target, 'UNKNOWN')
#     return '{0} {1}'.format(target, name)


from numpy import array, clip, exp, log10, nan, sin, where
from .constants import RAD2DEG
from .functions import angle_between, length_of
from .naifcodes import _target_name
    <https://arxiv.org/pdf/1808.01973.pdf>`_.  Two of the formulae have
    inherent limits:

    * Saturn’s magnitude is unknown and the function will return ``nan``
      (the floating-point value “Not a Number”) if the “illumination
      phase angle” — the angle of the vertex observer-Saturn-Sun —
      exceeds 6.5°.

    * Neptune’s magnitude is unknown and will return ``nan`` if the
      illumination phase angle exceeds 1.9° and the position's date is
      before the year 2000.

    And one formula is not fully implemented (though contributions are
    welcome!):

    * Skyfield does not compute which features on Mars are facing the
      observer, which can introduce an error of ±0.06 magnitude.

    """
    target = position.target
    function = _FUNCTIONS.get(target)
    if function is None:
        name = _target_name(target)
        raise ValueError('cannot compute the magnitude of target %s' % name)

    # Shamelessly treat the Sun as sitting at the Solar System Barycenter.
    sun_to_observer = position.center_barycentric.xyz.au
    observer_to_planet = position.xyz.au
    sun_to_planet = sun_to_observer + observer_to_planet


# Path: skyfield/constants.py
# RAD2DEG = 57.295779513082321
# 
# Path: skyfield/functions.py
# def angle_between(u, v):
#     """Given two vectors `v` and `u`, return the radian angle separating them.
# 
#     This works whether `v` and `u` each have the shape ``(3,)``, or
#     whether they are each whole arrays of corresponding x, y, and z
#     coordinates with shape ``(3, N)``. The returned angle will be
#     between 0 and tau/2.
# 
#     This formula is from Section 12 of:
#     https://people.eecs.berkeley.edu/~wkahan/Mindless.pdf
# 
#     """
#     a = u * length_of(v)
#     b = v * length_of(u)
#     return 2.0 * arctan2(length_of(a - b), length_of(a + b))
# 
# def length_of(xyz):
#     """Given a 3-element array |xyz|, return its length.
# 
#     The three elements can be simple scalars, or the array can be two
#     dimensions and offer three whole series of x, y, and z coordinates.
# 
#     """
#     return sqrt((xyz * xyz).sum(axis=0))
# 
# Path: skyfield/naifcodes.py
# def _target_name(target):
#     """Return `target` annotated for display to the user.
# 
#     * A string target is quoted to make clear that it's a string, like 'comet'.
#     * A numeric target has its NAIF name appended, like 399 EARTH.
# 
#     """
#     if isinstance(target, str):
#         return repr(target)
#     name = code_names.get(target, 'UNKNOWN')
#     return '{0} {1}'.format(target, name)


# Path: skyfield/magnitudelib.py
from numpy import array, clip, exp, log10, nan, sin, where
from .constants import RAD2DEG
from .functions import angle_between, length_of
from .naifcodes import _target_name

    <https://arxiv.org/pdf/1808.01973.pdf>`_.  Two of the formulae have
    inherent limits:

    * Saturn’s magnitude is unknown and the function will return ``nan``
      (the floating-point value “Not a Number”) if the “illumination
      phase angle” — the angle of the vertex observer-Saturn-Sun —
      exceeds 6.5°.

    * Neptune’s magnitude is unknown and will return ``nan`` if the
      illumination phase angle exceeds 1.9° and the position's date is
      before the year 2000.

    And one formula is not fully implemented (though contributions are
    welcome!):

    * Skyfield does not compute which features on Mars are facing the
      observer, which can introduce an error of ±0.06 magnitude.

    """
    target = position.target
    function = _FUNCTIONS.get(target)
    if function is None:
        name = _target_name(target)
        raise ValueError('cannot compute the magnitude of target %s' % name)

    # Shamelessly treat the Sun as sitting at the Solar System Barycenter.
    sun_to_observer = position.center_barycentric.xyz.au
    observer_to_planet = position.xyz.au
    sun_to_planet = sun_to_observer + observer_to_planet


    r = length_of(sun_to_planet)