# Path: beyond/utils/beta.py
# def beta(orb, ref="Sun"):
#     """Compute beta angle
# 
#     Args:
#         orb (Orbit) : Orbit of the primary spacecraft, expressed in a
#             reference frame whose centre is the obscuring body.
#         ref (str or Orbit or Ephem) : Secondary object
#     Return:
#         float: Angle beta in radians
#     """
# 
#     if isinstance(ref, str):
#         ref = get_body(ref)
# 
#     orb = orb.copy(form="cartesian")
#     p, v = orb[:3], orb[3:]
# 
#     w = np.asarray(np.cross(p, v))
#     ref_pos = np.asarray(ref.propagate(orb.date).copy(frame=orb.frame)[:3])
# 
#     return np.arcsin(w @ ref_pos / (np.linalg.norm(w) * np.linalg.norm(ref_pos)))
# 
# def beta_limit(orb):
#     """Compute minimal beta angle for a constant visibility on
#     another body.
# 
#     Below this threshold the spacecraft will experience eclipses during
#     a portion of its orbit. Above, it will be fully illuminated during
#     all its orbit.
# 
#     Args:
#         orb (Orbit) : Orbit of the primary spacecraft, expressed in a
#             reference frame whose centre is the obscuring body.
#     Return:
#         float : Angle in radians
#     """
# 
#     return np.arccos(np.sqrt(1 - (orb.frame.center.body.r / orb.infos.r) ** 2))
# 
# Path: beyond/env/jpl.py
# def get_body(name):
#     """Retrieve a body instance for a given object"""
#     body = Pck()[name]
#     body.propagator = get_propagator(name)
#     return body


import numpy as np
from pytest import mark
from beyond.utils.beta import beta, beta_limit
from beyond.env.jpl import get_body



def test_beta(iss_tle):

    orbit = iss_tle.orbit()

    beta_ = beta(orbit)
    beta_lim = beta_limit(orbit)

    assert np.isclose(beta_, -0.018861895899919556)
    assert np.isclose(beta_lim, 1.2243289463926432)


@mark.jpl
def test_beta_mars(jplfiles, iss_tle):

    # Test with another body than the sun

# Path: beyond/utils/beta.py
# def beta(orb, ref="Sun"):
#     """Compute beta angle
# 
#     Args:
#         orb (Orbit) : Orbit of the primary spacecraft, expressed in a
#             reference frame whose centre is the obscuring body.
#         ref (str or Orbit or Ephem) : Secondary object
#     Return:
#         float: Angle beta in radians
#     """
# 
#     if isinstance(ref, str):
#         ref = get_body(ref)
# 
#     orb = orb.copy(form="cartesian")
#     p, v = orb[:3], orb[3:]
# 
#     w = np.asarray(np.cross(p, v))
#     ref_pos = np.asarray(ref.propagate(orb.date).copy(frame=orb.frame)[:3])
# 
#     return np.arcsin(w @ ref_pos / (np.linalg.norm(w) * np.linalg.norm(ref_pos)))
# 
# def beta_limit(orb):
#     """Compute minimal beta angle for a constant visibility on
#     another body.
# 
#     Below this threshold the spacecraft will experience eclipses during
#     a portion of its orbit. Above, it will be fully illuminated during
#     all its orbit.
# 
#     Args:
#         orb (Orbit) : Orbit of the primary spacecraft, expressed in a
#             reference frame whose centre is the obscuring body.
#     Return:
#         float : Angle in radians
#     """
# 
#     return np.arccos(np.sqrt(1 - (orb.frame.center.body.r / orb.infos.r) ** 2))
# 
# Path: beyond/env/jpl.py
# def get_body(name):
#     """Retrieve a body instance for a given object"""
#     body = Pck()[name]
#     body.propagator = get_propagator(name)
#     return body


# Path: tests/utils/test_beta.py
import numpy as np
from pytest import mark
from beyond.utils.beta import beta, beta_limit
from beyond.env.jpl import get_body




def test_beta(iss_tle):

    orbit = iss_tle.orbit()

    beta_ = beta(orbit)
    beta_lim = beta_limit(orbit)

    assert np.isclose(beta_, -0.018861895899919556)
    assert np.isclose(beta_lim, 1.2243289463926432)


@mark.jpl
def test_beta_mars(jplfiles, iss_tle):

    # Test with another body than the sun

    beta_mars = beta(iss_tle.orbit(), get_body("Mars"))