Skip to content

Commit

Permalink
Merge pull request #22 from open-space-collective/users/lucas/improve…
Browse files Browse the repository at this point in the history
…-tle

Improve TLE
  • Loading branch information
lucas-bremond authored Jan 14, 2020
2 parents 747a868 + d211057 commit 7a4a501
Show file tree
Hide file tree
Showing 9 changed files with 7,563 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export jupyter_notebook_port := 9005
export open_space_toolkit_core_version := 0.3.2
export open_space_toolkit_io_version := 0.3.2
export open_space_toolkit_mathematics_version := 0.3.1
export open_space_toolkit_physics_version := 0.4.2
export open_space_toolkit_physics_version := 0.4.4

export open_space_toolkit_core_directory := $(project_directory)/../open-space-toolkit-core
export open_space_toolkit_io_directory := $(project_directory)/../open-space-toolkit-io
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@

################################################################################################################################################################

open-space-toolkit-physics>=0.4.2
open-space-toolkit-physics>=0.4.4

################################################################################################################################################################
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ inline void OpenSpaceToolkitAstrodynamicsPy_Trajectory_Orbit
.def("get_mean_anomaly", &TLE::getMeanAnomaly)
.def("get_mean_motion", &TLE::getMeanMotion)
.def("get_revolution_number_at_epoch", &TLE::getRevolutionNumberAtEpoch)
.def("get_second_line_checksum", &TLE::getSecondLineChecksum)

.def("undefined", &TLE::Undefined).staticmethod("undefined")
.def("can_parse", +[] (const String& aFirstLine, const String& aSecondLine) -> bool { return TLE::CanParse(aFirstLine, aSecondLine) ; })
Expand Down
2 changes: 1 addition & 1 deletion docker/development/debian/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ RUN mkdir -p /tmp/open-space-toolkit-mathematics \

## Open Space Toolkit ▸ Physics

ARG OSTK_PHYSICS_VERSION=0.4.2
ARG OSTK_PHYSICS_VERSION=0.4.4

RUN mkdir -p /tmp/open-space-toolkit-physics \
&& cd /tmp/open-space-toolkit-physics \
Expand Down
2 changes: 1 addition & 1 deletion docker/development/fedora/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ RUN mkdir -p /tmp/open-space-toolkit-mathematics \

## Open Space Toolkit ▸ Physics

ARG OSTK_PHYSICS_VERSION=0.4.2
ARG OSTK_PHYSICS_VERSION=0.4.4

RUN mkdir -p /tmp/open-space-toolkit-physics \
&& cd /tmp/open-space-toolkit-physics \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,12 @@ class TLE

Integer getRevolutionNumberAtEpoch ( ) const ;

/// @brief Get checksum of second line
///
/// @return Checksum of second line

Integer getSecondLineChecksum ( ) const ;

/// @brief Constructs an undefined TLE
///
/// @code
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,13 +356,25 @@ Integer TLE::getRevolutionNumberAtEpoch ( )
throw ostk::core::error::runtime::Undefined("TLE") ;
}

return Integer::Parse(secondLine_.getSubstring(63, 5)) ;
return Integer::Parse(secondLine_.getSubstring(63, 5).trim()) ;

}

Integer TLE::getSecondLineChecksum ( ) const
{

if (!this->isDefined())
{
throw ostk::core::error::runtime::Undefined("TLE") ;
}

return Integer::Parse(secondLine_.getSubstring(68, 1)) ;

}

TLE TLE::Undefined ( )
{
return TLE(String::Empty(), String::Empty(), String::Empty()) ;
return { String::Empty(), String::Empty(), String::Empty() } ;
}

bool TLE::CanParse ( const String& aString )
Expand Down Expand Up @@ -461,11 +473,11 @@ TLE TLE::Parse (

if (lines.getSize() == 2)
{
return TLE(lines.at(0), lines.at(1)) ;
return TLE { lines.at(0), lines.at(1) } ;
}
else if (lines.getSize() >= 3)
{
return TLE(lines.at(0), lines.at(1), lines.at(2)) ;
return TLE { lines.at(0), lines.at(1), lines.at(2) } ;
}

throw ostk::core::error::runtime::Wrong("String", aString) ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

#include <OpenSpaceToolkit/Astrodynamics/Trajectory/Orbit/Models/SGP4/TLE.hpp>

#include <sstream>

#include <Global.test.hpp>

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -399,6 +401,17 @@ TEST (OpenSpaceToolkit_Astrodynamics_Trajectory_Orbit_Models_SGP4_TLE, getFirstL

}

{

const String firstLine = "1 43020U 98067NH 20013.27161098 .00059259 00000-0 26371-3 0 9991" ;
const String secondLine = "2 43020 51.6414 326.1073 0001865 145.5478 214.5646 15.83723373122744" ;

const TLE tle { firstLine, secondLine } ;

EXPECT_EQ(1, tle.getFirstLineChecksum()) ;

}

{

EXPECT_ANY_THROW(TLE::Undefined().getFirstLineChecksum()) ;
Expand Down Expand Up @@ -601,6 +614,43 @@ TEST (OpenSpaceToolkit_Astrodynamics_Trajectory_Orbit_Models_SGP4_TLE, getRevolu

}

TEST (OpenSpaceToolkit_Astrodynamics_Trajectory_Orbit_Models_SGP4_TLE, getSecondLineChecksum)
{

using ostk::core::types::String ;

using ostk::astro::trajectory::orbit::models::sgp4::TLE ;

{

const String firstLine = "1 25544U 98067A 08264.51782528 -.00002182 00000-0 -11606-4 0 2927" ;
const String secondLine = "2 25544 51.6416 247.4627 0006703 130.5360 325.0288 15.72125391563537" ;

const TLE tle { firstLine, secondLine } ;

EXPECT_EQ(7, tle.getSecondLineChecksum()) ;

}

{

const String firstLine = "1 43020U 98067NH 20013.27161098 .00059259 00000-0 26371-3 0 9991" ;
const String secondLine = "2 43020 51.6414 326.1073 0001865 145.5478 214.5646 15.83723373122744" ;

const TLE tle { firstLine, secondLine } ;

EXPECT_EQ(4, tle.getSecondLineChecksum()) ;

}

{

EXPECT_ANY_THROW(TLE::Undefined().getSecondLineChecksum()) ;

}

}

TEST (OpenSpaceToolkit_Astrodynamics_Trajectory_Orbit_Models_SGP4_TLE, Undefined)
{

Expand All @@ -618,7 +668,10 @@ TEST (OpenSpaceToolkit_Astrodynamics_Trajectory_Orbit_Models_SGP4_TLE, Undefined
TEST (OpenSpaceToolkit_Astrodynamics_Trajectory_Orbit_Models_SGP4_TLE, CanParse)
{

using ostk::core::types::Integer ;
using ostk::core::types::String ;
using ostk::core::fs::Path ;
using ostk::core::fs::File ;

using ostk::astro::trajectory::orbit::models::sgp4::TLE ;

Expand Down Expand Up @@ -683,12 +736,63 @@ TEST (OpenSpaceToolkit_Astrodynamics_Trajectory_Orbit_Models_SGP4_TLE, CanParse)

}

{

const File activeTlesFile = File::Path(Path::Parse("/app/test/OpenSpaceToolkit/Astrodynamics/Trajectory/Orbit/Models/SGP4/TLE/active.txt")) ;

const String allTles = activeTlesFile.getContents() ;

std::istringstream allTlesStream { allTles } ;

String satelliteName = String::Empty() ;
String firstLine = String::Empty() ;
String secondLine = String::Empty() ;

Integer count = 0 ;

String line ;

while (std::getline(allTlesStream, line))
{

if (satelliteName.isEmpty())
{
satelliteName = line ;
}
else if (firstLine.isEmpty())
{
firstLine = line ;
}
else
{

secondLine = line ;

EXPECT_TRUE(TLE::CanParse(firstLine, secondLine)) ;

satelliteName = String::Empty() ;
firstLine = String::Empty() ;
secondLine = String::Empty() ;

count++ ;

}

}

EXPECT_EQ(2458, count) ;

}

}

TEST (OpenSpaceToolkit_Astrodynamics_Trajectory_Orbit_Models_SGP4_TLE, Parse)
{

using ostk::core::types::Integer ;
using ostk::core::types::String ;
using ostk::core::fs::Path ;
using ostk::core::fs::File ;

using ostk::physics::units::Time ;
using ostk::physics::units::Angle ;
Expand Down Expand Up @@ -718,6 +822,7 @@ TEST (OpenSpaceToolkit_Astrodynamics_Trajectory_Orbit_Models_SGP4_TLE, Parse)
EXPECT_EQ(Angle::Degrees(325.0288), tle.getMeanAnomaly()) ;
EXPECT_EQ(Derived(15.72125391, Derived::Unit::AngularVelocity(Angle::Unit::Revolution, Time::Unit::Day)), tle.getMeanMotion()) ;
EXPECT_EQ(56353, tle.getRevolutionNumberAtEpoch()) ;
EXPECT_EQ(7, tle.getSecondLineChecksum()) ;

}

Expand All @@ -743,6 +848,7 @@ TEST (OpenSpaceToolkit_Astrodynamics_Trajectory_Orbit_Models_SGP4_TLE, Parse)
EXPECT_EQ(Angle::Degrees(325.0288), tle.getMeanAnomaly()) ;
EXPECT_EQ(Derived(15.72125391, Derived::Unit::AngularVelocity(Angle::Unit::Revolution, Time::Unit::Day)), tle.getMeanMotion()) ;
EXPECT_EQ(56353, tle.getRevolutionNumberAtEpoch()) ;
EXPECT_EQ(7, tle.getSecondLineChecksum()) ;

}

Expand Down Expand Up @@ -780,6 +886,60 @@ TEST (OpenSpaceToolkit_Astrodynamics_Trajectory_Orbit_Models_SGP4_TLE, Parse)

}

{

const File activeTlesFile = File::Path(Path::Parse("/app/test/OpenSpaceToolkit/Astrodynamics/Trajectory/Orbit/Models/SGP4/TLE/active.txt")) ;

const String allTles = activeTlesFile.getContents() ;

std::istringstream allTlesStream { allTles } ;

String satelliteName = String::Empty() ;
String firstLine = String::Empty() ;
String secondLine = String::Empty() ;

Integer count = 0 ;

String line ;

while (std::getline(allTlesStream, line))
{

if (satelliteName.isEmpty())
{
satelliteName = line ;
}
else if (firstLine.isEmpty())
{
firstLine = line ;
}
else
{

secondLine = line ;

const String tleString = String::Format("{}\n{}\n{}\n", satelliteName, firstLine, secondLine) ;

const TLE tle = TLE::Parse(tleString) ;

EXPECT_EQ(satelliteName, tle.getSatelliteName()) ;
EXPECT_EQ(firstLine, tle.getFirstLine()) ;
EXPECT_EQ(secondLine, tle.getSecondLine()) ;

satelliteName = String::Empty() ;
firstLine = String::Empty() ;
secondLine = String::Empty() ;

count++ ;

}

}

EXPECT_EQ(2458, count) ;

}

}

TEST (OpenSpaceToolkit_Astrodynamics_Trajectory_Orbit_Models_SGP4_TLE, Load)
Expand Down Expand Up @@ -842,6 +1002,7 @@ TEST (OpenSpaceToolkit_Astrodynamics_Trajectory_Orbit_Models_SGP4_TLE, Load)
EXPECT_EQ(Angle::Degrees(325.0288), tle.getMeanAnomaly()) ;
EXPECT_EQ(Derived(15.72125391, Derived::Unit::AngularVelocity(Angle::Unit::Revolution, Time::Unit::Day)), tle.getMeanMotion()) ;
EXPECT_EQ(56353, tle.getRevolutionNumberAtEpoch()) ;
EXPECT_EQ(7, tle.getSecondLineChecksum()) ;

}

Expand All @@ -867,6 +1028,7 @@ TEST (OpenSpaceToolkit_Astrodynamics_Trajectory_Orbit_Models_SGP4_TLE, Load)
EXPECT_EQ(Angle::Degrees(325.0288), tle.getMeanAnomaly()) ;
EXPECT_EQ(Derived(15.72125391, Derived::Unit::AngularVelocity(Angle::Unit::Revolution, Time::Unit::Day)), tle.getMeanMotion()) ;
EXPECT_EQ(56353, tle.getRevolutionNumberAtEpoch()) ;
EXPECT_EQ(7, tle.getSecondLineChecksum()) ;

}

Expand Down
Loading

0 comments on commit 7a4a501

Please sign in to comment.