Skip to content

Commit

Permalink
feat: finish tests, docstrings and bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
vishwa2710 committed Oct 12, 2023
1 parent 8e2f4fd commit b0d0586
Show file tree
Hide file tree
Showing 17 changed files with 513 additions and 110 deletions.
Original file line number Diff line number Diff line change
@@ -1,59 +1,67 @@
/// Apache License 2.0

#include <OpenSpaceToolkit/Physics/Units/Derived/Angle.hpp>

#include <OpenSpaceToolkit/Astrodynamics/Trajectory/Orbit/Models/Kepler/BrouwerLyddaneMean.hpp>

using namespace pybind11;

using ostk::core::types::Real;
using ostk::physics::units::Length;
using ostk::physics::units::Angle;

using ostk::astro::trajectory::orbit::models::kepler::COE;
using ostk::astro::trajectory::orbit::models::kepler::BrouwerLyddaneMean;

// Trampoline class for virtual member functions
class PyBrouwerLyddaneMean : public BrouwerLyddaneMean
{
public:
using BrouwerLyddaneMean::BrouwerLyddaneMean;

// Trampoline (need one for each virtual function)

Angle getMeanAnomaly() const
{
PYBIND11_OVERRIDE_PURE_NAME(
Angle, BrouwerLyddaneMean, "get_mean_anomaly", getMeanAnomaly
);
PYBIND11_OVERRIDE_NAME(Angle, BrouwerLyddaneMean, "get_mean_anomaly", getMeanAnomaly);
}

Angle getTrueAnomaly() const
{
PYBIND11_OVERRIDE_PURE_NAME(
Angle, BrouwerLyddaneMean, "get_true_anomaly", getTrueAnomaly
);
PYBIND11_OVERRIDE_NAME(Angle, BrouwerLyddaneMean, "get_true_anomaly", getTrueAnomaly);
}

Angle getEccentricAnomaly() const
{
PYBIND11_OVERRIDE_PURE_NAME(
Angle, BrouwerLyddaneMean, "get_eccentric_anomaly", getEccentricAnomaly
);
PYBIND11_OVERRIDE_NAME(Angle, BrouwerLyddaneMean, "get_eccentric_anomaly", getEccentricAnomaly);
}

COE toCOE() const
{
PYBIND11_OVERRIDE_PURE_NAME(
COE, BrouwerLyddaneMean, "to_coe", toCOE
);
PYBIND11_OVERRIDE_PURE_NAME(COE, BrouwerLyddaneMean, "to_coe", toCOE);
}
} ;

};

inline void OpenSpaceToolkitAstrodynamicsPy_Trajectory_Orbit_Models_Kepler_BrouwerLyddaneMean(pybind11::module& aModule)
{
using namespace pybind11;

using ostk::core::types::Real;
using ostk::core::types::Shared;
using ostk::physics::units::Length;

class_<BrouwerLyddaneMean, PyBrouwerLyddaneMean, COE, Shared<BrouwerLyddaneMean>> brouwerLyddaneMean(aModule, "BrouwerLyddaneMean");
class_<BrouwerLyddaneMean, PyBrouwerLyddaneMean, COE> brouwerLyddaneMean(aModule, "BrouwerLyddaneMean");

brouwerLyddaneMean

.def("get_cartesian_state", &BrouwerLyddaneMean::getCartesianState, arg("gravitational_parameter"), arg("frame"));
.def(
init<const Length&, const Real&, const Angle&, const Angle&, const Angle&, const Angle&>(),
arg("semi_major_axis"),
arg("eccentricity"),
arg("inclination"),
arg("raan"),
arg("aop"),
arg("mean_anomaly")
)

.def("get_mean_anomaly", &BrouwerLyddaneMean::getMeanAnomaly)
.def("get_true_anomaly", &BrouwerLyddaneMean::getTrueAnomaly)
.def("get_eccentric_anomaly", &BrouwerLyddaneMean::getEccentricAnomaly)
.def(
"get_cartesian_state", &BrouwerLyddaneMean::getCartesianState, arg("gravitational_parameter"), arg("frame")
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

#include <OpenSpaceToolkit/Astrodynamics/Trajectory/Orbit/Models/Kepler/BrouwerLyddaneMeanLong.hpp>

inline void OpenSpaceToolkitAstrodynamicsPy_Trajectory_Orbit_Models_Kepler_BrouwerLyddaneMeanLong(pybind11::module& aModule)
inline void OpenSpaceToolkitAstrodynamicsPy_Trajectory_Orbit_Models_Kepler_BrouwerLyddaneMeanLong(
pybind11::module& aModule
)
{
using namespace pybind11;

Expand All @@ -11,9 +13,10 @@ inline void OpenSpaceToolkitAstrodynamicsPy_Trajectory_Orbit_Models_Kepler_Brouw
using ostk::physics::units::Angle;
using ostk::physics::units::Length;

using ostk::astro::trajectory::orbit::models::kepler::BrouwerLyddaneMean;
using ostk::astro::trajectory::orbit::models::kepler::BrouwerLyddaneMeanLong;

class_<BrouwerLyddaneMeanLong> brouwerLyddaneMeanLong(aModule, "BrouwerLyddaneMeanLong");
class_<BrouwerLyddaneMeanLong, BrouwerLyddaneMean> brouwerLyddaneMeanLong(aModule, "BrouwerLyddaneMeanLong");

brouwerLyddaneMeanLong

Expand All @@ -27,15 +30,13 @@ inline void OpenSpaceToolkitAstrodynamicsPy_Trajectory_Orbit_Models_Kepler_Brouw
arg("mean_anomaly")
)

.def("to_coe", &BrouwerLyddaneMeanLong::toCOE)

.def_static(
"cartesian",
&BrouwerLyddaneMeanLong::Cartesian,
arg("cartersian_state"),
arg("gravitational_parameter")
"cartesian", &BrouwerLyddaneMeanLong::Cartesian, arg("cartersian_state"), arg("gravitational_parameter")
)

.def_static(
"undefined",
&BrouwerLyddaneMeanLong::Undefined
);
.def_static("undefined", &BrouwerLyddaneMeanLong::Undefined)

;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

#include <OpenSpaceToolkit/Astrodynamics/Trajectory/Orbit/Models/Kepler/BrouwerLyddaneMeanShort.hpp>

inline void OpenSpaceToolkitAstrodynamicsPy_Trajectory_Orbit_Models_Kepler_BrouwerLyddaneMeanShort(pybind11::module& aModule)
inline void OpenSpaceToolkitAstrodynamicsPy_Trajectory_Orbit_Models_Kepler_BrouwerLyddaneMeanShort(
pybind11::module& aModule
)
{
using namespace pybind11;

Expand All @@ -13,7 +15,7 @@ inline void OpenSpaceToolkitAstrodynamicsPy_Trajectory_Orbit_Models_Kepler_Brouw

using ostk::astro::trajectory::orbit::models::kepler::BrouwerLyddaneMeanShort;

class_<BrouwerLyddaneMeanShort, BrouwerLyddaneMean, Shared<BrouwerLyddaneMeanShort>> brouwerLyddaneMeanShort(aModule, "BrouwerLyddaneMeanShort");
class_<BrouwerLyddaneMeanShort, BrouwerLyddaneMean> brouwerLyddaneMeanShort(aModule, "BrouwerLyddaneMeanShort");

brouwerLyddaneMeanShort

Expand All @@ -25,17 +27,13 @@ inline void OpenSpaceToolkitAstrodynamicsPy_Trajectory_Orbit_Models_Kepler_Brouw
arg("raan"),
arg("aop"),
arg("mean_anomaly")
);
)

.def("to_coe", &BrouwerLyddaneMeanShort::toCOE)

.def_static(
"cartesian",
&BrouwerLyddaneMeanLong::Cartesian,
arg("cartersian_state"),
arg("gravitational_parameter")
"cartesian", &BrouwerLyddaneMeanShort::Cartesian, arg("cartersian_state"), arg("gravitational_parameter")
)

.def_static(
"undefined",
&BrouwerLyddaneMeanLong::Undefined
);
.def_static("undefined", &BrouwerLyddaneMeanShort::Undefined);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ inline void OpenSpaceToolkitAstrodynamicsPy_Trajectory_Orbit_Models_Kepler_COE(p

using ostk::astro::trajectory::orbit::models::kepler::COE;

class_<COE, Shared<COE>> coe(aModule, "COE");
class_<COE> coe(aModule, "COE");

coe

Expand Down Expand Up @@ -44,17 +44,25 @@ inline void OpenSpaceToolkitAstrodynamicsPy_Trajectory_Orbit_Models_Kepler_COE(p
.def("get_true_anomaly", &COE::getTrueAnomaly)
.def("get_mean_anomaly", &COE::getMeanAnomaly)
.def("get_eccentric_anomaly", &COE::getEccentricAnomaly)
.def("get_periapsis_radius", &COE::getPeriapsisRadius)
.def("get_periapsis_altitude", &COE::getPeriapsisRadius)
.def("get_SI_vector", &COE::getSIVector, arg("anomaly_type"))

.def("get_mean_motion", &COE::getMeanMotion, arg("gravitational_parameter"))

.def("get_orbital_period", &COE::getOrbitalPeriod, arg("gravitational_parameter"))

.def("get_cartesian_state", &COE::getCartesianState, arg("gravitational_parameter"), arg("frame"))

.def("to_brouwer_lyddane_mean_long", &COE::toBrouwerLyddaneMeanLong)
.def("to_brouwer_lyddane_mean_short", &COE::toBrouwerLyddaneMeanShort)

.def_static("undefined", &COE::Undefined)

.def_static("cartesian", &COE::Cartesian, arg("cartesian_state"), arg("gravitational_parameter"))

.def_static("from_SI_vector", &COE::FromSIVector, arg("vector"), arg("anomaly_type"))

.def_static(
"eccentric_anomaly_from_true_anomaly",
&COE::EccentricAnomalyFromTrueAnomaly,
Expand Down Expand Up @@ -84,6 +92,14 @@ inline void OpenSpaceToolkitAstrodynamicsPy_Trajectory_Orbit_Models_Kepler_COE(p
arg("tolerance")
)

.def_static(
"true_anomaly_from_mean_anomaly",
&COE::TrueAnomalyFromMeanAnomaly,
arg("mean_anomaly"),
arg("eccentricity"),
arg("tolerance")
)

.def_static("string_from_element", &COE::StringFromElement, arg("element"))

;
Expand All @@ -99,5 +115,13 @@ inline void OpenSpaceToolkitAstrodynamicsPy_Trajectory_Orbit_Models_Kepler_COE(p
.value("MeanAnomaly", COE::Element::MeanAnomaly)
.value("EccentricAnomaly", COE::Element::EccentricAnomaly)

;

enum_<COE::AnomalyType>(coe, "AnomalyType")

.value("TrueAnomaly", COE::AnomalyType::True)
.value("MeanAnomaly", COE::AnomalyType::Mean)
.value("EccentricAnomaly", COE::AnomalyType::Eccentric)

;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Apache License 2.0

import pytest

from ostk.physics.units import Length
from ostk.physics.units import Angle

from ostk.astrodynamics.trajectory.orbit.models.kepler import BrouwerLyddaneMean


@pytest.fixture
def semi_major_axis() -> Length:
return Length.kilometers(7000.0)


@pytest.fixture
def eccentricity() -> float:
return 1e-3


@pytest.fixture
def inclination() -> Angle:
return Angle.degrees(35.0)


@pytest.fixture
def raan() -> Angle:
return Angle.degrees(40.0)


@pytest.fixture
def aop() -> Angle:
return Angle.degrees(50.0)


@pytest.fixture
def mean_anomaly() -> Angle:
return Angle.degrees(60.0)


@pytest.fixture
def brouwer_lyddane_mean(
semi_major_axis, eccentricity, inclination, raan, aop, mean_anomaly
):
class BrouwerLyddaneMeanMock(BrouwerLyddaneMean):
def __init__(
self, semi_major_axis, eccentricity, inclination, raan, aop, mean_anomaly
):
super().__init__(
semi_major_axis, eccentricity, inclination, raan, aop, mean_anomaly
)

def to_coe():
return 0.0

return BrouwerLyddaneMeanMock(
semi_major_axis, eccentricity, inclination, raan, aop, mean_anomaly
)


class TestBrouwerLyddaneMean:
def test_getters(self, brouwer_lyddane_mean: BrouwerLyddaneMean):
assert isinstance(brouwer_lyddane_mean.get_mean_anomaly(), Angle)
assert isinstance(brouwer_lyddane_mean.get_true_anomaly(), Angle)
assert isinstance(brouwer_lyddane_mean.get_eccentric_anomaly(), Angle)
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Apache License 2.0

import pytest

from ostk.physics.units import Length
from ostk.physics.units import Angle
from ostk.physics.environment.gravitational import Earth

from ostk.physics.coordinate import Frame
from ostk.physics.coordinate import Position
from ostk.physics.coordinate import Velocity

from ostk.astrodynamics.trajectory.orbit.models.kepler import BrouwerLyddaneMeanLong


@pytest.fixture
def semi_major_axis() -> Length:
return Length.kilometers(7000.0)


@pytest.fixture
def eccentricity() -> float:
return 1e-3


@pytest.fixture
def inclination() -> Angle:
return Angle.degrees(35.0)


@pytest.fixture
def raan() -> Angle:
return Angle.degrees(40.0)


@pytest.fixture
def aop() -> Angle:
return Angle.degrees(50.0)


@pytest.fixture
def mean_anomaly() -> Angle:
return Angle.degrees(60.0)


@pytest.fixture
def cartesian_state() -> tuple[Position, Velocity]:
return (
Position.meters(
[6596407.223662058, 2281266.582975321, -10540.61521486086], Frame.GCRF()
),
Velocity.meters_per_second(
[337.7269674273224, -969.7192552349448, 7488.702816619139], Frame.GCRF()
),
)


@pytest.fixture
def gravitational_parameter():
return Earth.EGM2008.gravitational_parameter


@pytest.fixture
def brouwer_lyddane_mean_long(
semi_major_axis, eccentricity, inclination, raan, aop, mean_anomaly
):
return BrouwerLyddaneMeanLong(
semi_major_axis, eccentricity, inclination, raan, aop, mean_anomaly
)


class TestBrouwerLyddaneMeanLong:
def test_to_coe(self, brouwer_lyddane_mean_long: BrouwerLyddaneMeanLong):
assert brouwer_lyddane_mean_long.to_coe().is_defined()

def test_cartesian(
self, cartesian_state: tuple[Position, Velocity], gravitational_parameter
):
assert BrouwerLyddaneMeanLong.cartesian(
cartesian_state, gravitational_parameter
).is_defined()

def test_undefined(self):
assert BrouwerLyddaneMeanLong.undefined().is_defined() is False
Loading

0 comments on commit b0d0586

Please sign in to comment.