diff --git a/bindings/python/src/OpenSpaceToolkitAstrodynamicsPy/Trajectory/Orbit.cpp b/bindings/python/src/OpenSpaceToolkitAstrodynamicsPy/Trajectory/Orbit.cpp index e1173a9b4..bdc023a0a 100644 --- a/bindings/python/src/OpenSpaceToolkitAstrodynamicsPy/Trajectory/Orbit.cpp +++ b/bindings/python/src/OpenSpaceToolkitAstrodynamicsPy/Trajectory/Orbit.cpp @@ -1,9 +1,10 @@ -/// Apache License 2.0 +/// Apache License 2.0 #include #include #include #include +#include #include #include @@ -24,6 +25,7 @@ inline void OpenSpaceToolkitAstrodynamicsPy_Trajectory_Orbit(pybind11::module& a using ostk::astro::trajectory::State; using ostk::astro::trajectory::orbit::models::Kepler; using ostk::astro::trajectory::orbit::models::Propagated; + using ostk::astro::trajectory::orbit::models::Tabulated; using ostk::astro::trajectory::orbit::models::SGP4; { @@ -77,6 +79,14 @@ inline void OpenSpaceToolkitAstrodynamicsPy_Trajectory_Orbit(pybind11::module& a }, return_value_policy::reference ) // [TBR] + .def( + "access_tabulated_model", + +[](const Orbit& anOrbit) -> const Tabulated& + { + return anOrbit.accessModel().as(); + }, + return_value_policy::reference + ) // [TBR] .def("get_revolution_number_at", &Orbit::getRevolutionNumberAt, arg("instant")) .def("get_pass_at", &Orbit::getPassAt, arg("instant")) diff --git a/bindings/python/src/OpenSpaceToolkitAstrodynamicsPy/Trajectory/Orbit/Models/Tabulated.cpp b/bindings/python/src/OpenSpaceToolkitAstrodynamicsPy/Trajectory/Orbit/Models/Tabulated.cpp index 6d545b308..d4b266ee6 100644 --- a/bindings/python/src/OpenSpaceToolkitAstrodynamicsPy/Trajectory/Orbit/Models/Tabulated.cpp +++ b/bindings/python/src/OpenSpaceToolkitAstrodynamicsPy/Trajectory/Orbit/Models/Tabulated.cpp @@ -1,4 +1,4 @@ -/// Apache License 2.0 +/// Apache License 2.0 #include @@ -12,7 +12,7 @@ inline void OpenSpaceToolkitAstrodynamicsPy_Trajectory_Orbit_Models_Tabulated(py using ostk::astro::trajectory::State; using ostk::astro::trajectory::orbit::models::Tabulated; - class_ tabulated_class(aModule, "Tabulated"); + class_ tabulated_class(aModule, "Tabulated"); enum_(tabulated_class, "InterpolationType") @@ -41,6 +41,7 @@ inline void OpenSpaceToolkitAstrodynamicsPy_Trajectory_Orbit_Models_Tabulated(py .def("get_epoch", &Tabulated::getEpoch) .def("get_revolution_number_at_epoch", &Tabulated::getRevolutionNumberAtEpoch) .def("get_interval", &Tabulated::getInterval) + .def("get_interpolation_type", &Tabulated::getInterpolationType) .def("calculate_state_at", &Tabulated::calculateStateAt, arg("instant")) .def("calculate_states_at", &Tabulated::calculateStatesAt, arg("instants")) .def("calculate_revolution_number_at", &Tabulated::calculateRevolutionNumberAt, arg("instant")) diff --git a/bindings/python/test/trajectory/orbit/models/test_tabulated.py b/bindings/python/test/trajectory/orbit/models/test_tabulated.py index 83e909bda..f423bebd0 100644 --- a/bindings/python/test/trajectory/orbit/models/test_tabulated.py +++ b/bindings/python/test/trajectory/orbit/models/test_tabulated.py @@ -1,4 +1,4 @@ -# Apache License 2.0 +# Apache License 2.0 import pytest @@ -11,11 +11,18 @@ from ostk.physics.coordinate import Position from ostk.physics.coordinate import Velocity from ostk.physics.coordinate import Frame +from ostk.physics import Environment from ostk.astrodynamics.trajectory import State +from ostk.astrodynamics.trajectory import Orbit from ostk.astrodynamics.trajectory.orbit.models import Tabulated +@pytest.fixture +def earth(): + return Environment.default().access_celestial_object_with_name("Earth") + + @pytest.fixture def reference_states() -> list[State]: data = [ @@ -240,6 +247,33 @@ def test_constructor( is not None ) + def test_constructor_orbit_tabulated_sucess( + self, + test_states: list[State], + earth, + ): + tabulated = Tabulated( + states=test_states, + initial_revolution_number=1, + interpolation_type=Tabulated.InterpolationType.CubicSpline, + ) + + orbit: Orbit = Orbit(tabulated, earth) + + assert orbit is not None + assert isinstance(orbit, Orbit) + + def test_get_interpolation_type(self, test_states: list[State]): + tabulated = Tabulated( + states=test_states, + initial_revolution_number=1, + interpolation_type=Tabulated.InterpolationType.CubicSpline, + ) + + assert ( + tabulated.get_interpolation_type() == Tabulated.InterpolationType.CubicSpline + ) + @pytest.mark.parametrize( "interpolation_type,error_tolerance", ( diff --git a/bindings/python/test/trajectory/test_orbit.py b/bindings/python/test/trajectory/test_orbit.py index a5e38a3b1..a66efe2ef 100644 --- a/bindings/python/test/trajectory/test_orbit.py +++ b/bindings/python/test/trajectory/test_orbit.py @@ -1,99 +1,79 @@ -# Apache License 2.0 +# Apache License 2.0 import pytest -import numpy +from ostk.physics import Environment +from ostk.physics.units import Length, Angle +from ostk.physics.time import Scale, Instant, DateTime -import ostk.physics as physics +from ostk.astrodynamics.trajectory import Orbit, State +from ostk.astrodynamics.trajectory.orbit.models import SGP4 +from ostk.astrodynamics.trajectory.orbit.models.sgp4 import TLE -import ostk.astrodynamics as astrodynamics -Length = physics.units.Length -Angle = physics.units.Angle -Scale = physics.time.Scale -Instant = physics.time.Instant -Interval = physics.time.Interval -DateTime = physics.time.DateTime -Position = physics.coordinate.Position -Velocity = physics.coordinate.Velocity -Frame = physics.coordinate.Frame -Environment = physics.Environment +@pytest.fixture +def earth(): + return Environment.default().access_celestial_object_with_name("Earth") -Trajectory = astrodynamics.Trajectory -Model = astrodynamics.trajectory.Model -Orbit = astrodynamics.trajectory.Orbit -Pass = astrodynamics.trajectory.orbit.Pass -Kepler = astrodynamics.trajectory.orbit.models.Kepler -COE = astrodynamics.trajectory.orbit.models.kepler.COE -SGP4 = astrodynamics.trajectory.orbit.models.SGP4 -TLE = astrodynamics.trajectory.orbit.models.sgp4.TLE -State = astrodynamics.trajectory.State -Access = astrodynamics.Access -earth = Environment.default().access_celestial_object_with_name("Earth") +class TestOrbit: + def test_trajectory_orbit_constructors(self, earth): + # Construct Two-Line Element set + tle = TLE( + "1 25544U 98067A 18231.17878740 .00000187 00000-0 10196-4 0 9994", + "2 25544 51.6447 64.7824 0005971 73.1467 36.4366 15.53848234128316", + ) + # Construct orbit using SGP4 model + orbit = Orbit(SGP4(tle), earth) -def test_trajectory_orbit_constructors(): - # Construct Two-Line Element set - tle = TLE( - "1 25544U 98067A 18231.17878740 .00000187 00000-0 10196-4 0 9994", - "2 25544 51.6447 64.7824 0005971 73.1467 36.4366 15.53848234128316", - ) + assert orbit is not None + assert isinstance(orbit, Orbit) + assert orbit.is_defined() - # Construct orbit using SGP4 model - orbit = Orbit(SGP4(tle), earth) + # Construct get state at current epoch + state: State = orbit.get_state_at(Instant.now()) - assert orbit is not None - assert isinstance(orbit, Orbit) - assert orbit.is_defined() + assert state is not None + assert isinstance(state, State) - # Construct get state at current epoch - state: State = orbit.get_state_at(Instant.now()) + def test_trajectory_orbit_circular(self, earth): + epoch = Instant.date_time(DateTime(2018, 1, 1, 0, 0, 0), Scale.UTC) + altitude = Length.kilometers(500.0) + inclination = Angle.degrees(45.0) - assert state is not None - assert isinstance(state, State) + orbit: Orbit = Orbit.circular(epoch, altitude, inclination, earth) + @pytest.mark.skip + def test_trajectory_orbit_equatorial(self, earth): + epoch = Instant.date_time(DateTime(2018, 1, 1, 0, 0, 0), Scale.UTC) + altitude = Length.kilometers(500.0) + eccentricity = 0.1 -def test_trajectory_orbit_circular(): - epoch = Instant.date_time(DateTime(2018, 1, 1, 0, 0, 0), Scale.UTC) - altitude = Length.kilometers(500.0) - inclination = Angle.degrees(45.0) + orbit: Orbit = Orbit.equatorial(epoch, altitude, eccentricity, earth) - orbit: Orbit = Orbit.circular(epoch, altitude, inclination, earth) + assert orbit is not None + assert isinstance(orbit, Orbit) + assert orbit.is_defined() + @pytest.mark.skip + def test_trajectory_orbit_circular_equatorial(self, earth): + epoch = Instant.date_time(DateTime(2018, 1, 1, 0, 0, 0), Scale.UTC) + altitude = Length.kilometers(500.0) -@pytest.mark.skip -def test_trajectory_orbit_equatorial(): - epoch = Instant.date_time(DateTime(2018, 1, 1, 0, 0, 0), Scale.UTC) - altitude = Length.kilometers(500.0) - eccentricity = 0.1 + orbit: Orbit = Orbit.circular_equatorial(epoch, altitude, earth) - orbit: Orbit = Orbit.equatorial(epoch, altitude, eccentricity, earth) + assert orbit is not None + assert isinstance(orbit, Orbit) + assert orbit.is_defined() - assert orbit is not None - assert isinstance(orbit, Orbit) - assert orbit.is_defined() + @pytest.mark.skip + def test_trajectory_orbit_sun_synchronous(self, earth): + epoch = Instant.date_time(DateTime(2018, 1, 1, 0, 0, 0), Scale.UTC) + altitude = Length.kilometers(500.0) + orbit: Orbit = Orbit.sun_synchronous(epoch, altitude, earth) -@pytest.mark.skip -def test_trajectory_orbit_circular_equatorial(): - epoch = Instant.date_time(DateTime(2018, 1, 1, 0, 0, 0), Scale.UTC) - altitude = Length.kilometers(500.0) - - orbit: Orbit = Orbit.circular_equatorial(epoch, altitude, earth) - - assert orbit is not None - assert isinstance(orbit, Orbit) - assert orbit.is_defined() - - -@pytest.mark.skip -def test_trajectory_orbit_sun_synchronous(): - epoch = Instant.date_time(DateTime(2018, 1, 1, 0, 0, 0), Scale.UTC) - altitude = Length.kilometers(500.0) - - orbit: Orbit = Orbit.sun_synchronous(epoch, altitude, earth) - - assert orbit is not None - assert isinstance(orbit, Orbit) - assert orbit.is_defined() + assert orbit is not None + assert isinstance(orbit, Orbit) + assert orbit.is_defined() diff --git a/include/OpenSpaceToolkit/Astrodynamics/Trajectory/Models/Tabulated.hpp b/include/OpenSpaceToolkit/Astrodynamics/Trajectory/Models/Tabulated.hpp index b2fd69569..89c4453b9 100644 --- a/include/OpenSpaceToolkit/Astrodynamics/Trajectory/Models/Tabulated.hpp +++ b/include/OpenSpaceToolkit/Astrodynamics/Trajectory/Models/Tabulated.hpp @@ -1,4 +1,4 @@ -/// Apache License 2.0 +/// Apache License 2.0 #ifndef __OpenSpaceToolkit_Astrodynamics_Trajectory_Models_Tabulated__ #define __OpenSpaceToolkit_Astrodynamics_Trajectory_Models_Tabulated__ @@ -50,8 +50,6 @@ using ostk::astro::trajectory::State; #define DEFAULT_TABULATED_INTERPOLATION_TYPE Tabulated::InterpolationType::Linear -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - /// @brief Tabulated trajectory model /// /// Interpolation is performed between states using the specified interpolation scheme. diff --git a/test/OpenSpaceToolkit/Astrodynamics/Trajectory/Orbit/Models/Tabulated.test.cpp b/test/OpenSpaceToolkit/Astrodynamics/Trajectory/Orbit/Models/Tabulated.test.cpp index e280050a1..aa067a148 100644 --- a/test/OpenSpaceToolkit/Astrodynamics/Trajectory/Orbit/Models/Tabulated.test.cpp +++ b/test/OpenSpaceToolkit/Astrodynamics/Trajectory/Orbit/Models/Tabulated.test.cpp @@ -1,23 +1,16 @@ -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -/// @project Open Space Toolkit ▸ Astrodynamics -/// @file OpenSpaceToolkit/Astrodynamics/Trajectory/Orbit/Models/Tabulated.test.cpp -/// @author Vishwa Shah -/// @license Apache License 2.0 - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +/// Apache License 2.0 #include #include #include +#include +#include #include #include -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - using ostk::core::types::Integer; using ostk::core::types::Size; using ostk::core::types::Index; @@ -31,6 +24,7 @@ using ostk::core::fs::File; using ostk::math::obj::VectorXd; +using ostk::physics::Environment; using ostk::physics::time::Instant; using ostk::physics::time::DateTime; using ostk::physics::time::Duration; @@ -40,11 +34,10 @@ using ostk::physics::coord::Velocity; using ostk::physics::coord::Frame; using ostk::astro::trajectory::State; +using ostk::astro::trajectory::Orbit; using ostk::astro::trajectory::orbit::Model; using ostk::astro::trajectory::orbit::models::Tabulated; -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - class OpenSpaceToolkit_Astrodynamics_Trajectory_Orbit_Models_Tabulated : public ::testing::Test { protected: @@ -94,6 +87,10 @@ class OpenSpaceToolkit_Astrodynamics_Trajectory_Orbit_Models_Tabulated : public TEST_F(OpenSpaceToolkit_Astrodynamics_Trajectory_Orbit_Models_Tabulated, Constructor) { const Tabulated tabulated(states_, 0, Tabulated::InterpolationType::Linear); + + Environment environment = Environment::Default(); + + const Orbit orbit = {tabulated, environment.accessCelestialObjectWithName("Earth")}; } TEST_F(OpenSpaceToolkit_Astrodynamics_Trajectory_Orbit_Models_Tabulated, CalculateStateAt) @@ -199,5 +196,3 @@ TEST_F(OpenSpaceToolkit_Astrodynamics_Trajectory_Orbit_Models_Tabulated, NotEqua EXPECT_TRUE(tabulated != anotherTabulated); } - -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////