Parsing TLEs

This package contains functions to parse TLEs from strings and files.

Parsing TLEs from strings

The simplest way to parse one single TLE is using the macro @tle_str:

julia> tle = tle"""
           AMAZONIA 1
           1 47699U 21015A   23083.68657856 -.00000044  10000-8  43000-4 0  9990
           2 47699  98.4304 162.1097 0001247 136.2017 223.9283 14.40814394108652
           """TLE: AMAZONIA 1 (Epoch = 2023-03-24T16:28:40.388):
  ├─ Line 1
Satellite Number         : 47699
Classification           : U
International Designator : 21015A
Epoch Year               : 23
Epoch Day                : 83.68657856
ṅ/2                      : -4.4e-7 rev/day²
n̈/6                      : 1.0e-9 rev/day³
B*                       : 4.3e-5 1/ER
Ephemeris Type           : 0
Element Set Number       : 999
  └─ Line 2
       Inclination              : 98.4304°
       RA of the Ascending Node : 162.1097°
       Eccentricity             : 0.0001247
       Arg. of Perigee          : 136.2017°
       Mean Anomaly             : 223.9283°
       Mean Motion              : 14.40814394 rev/day
       Revolution Number        : 10865

This macro considers only one TLE, leading to an error if the string contains additional information:

julia> tle = tle"""
           AMAZONIA 1
           1 47699U 21015A   23083.68657856 -.00000044  10000-8  43000-4 0  9990
           2 47699  98.4304 162.1097 0001247 136.2017 223.9283 14.40814394108652
           CBERS 4A
           1 44883U 19093E   23087.54098578  .00002943  00000+0  38100-3 0  9997
           2 44883  97.8669 167.4611 0001705  77.3129 282.8275 14.81612352176856
           """ERROR: LoadError: TleParseError: The string must contain only one TLE (2 or 3 lines).
in expression starting at REPL[1]:1

Multiple TLEs can be parsed using the macro @tles_str:

julia> tles = tles"""
           AMAZONIA 1
           1 47699U 21015A   23083.68657856 -.00000044  10000-8  43000-4 0  9990
           2 47699  98.4304 162.1097 0001247 136.2017 223.9283 14.40814394108652
           CBERS 4A
           1 44883U 19093E   23087.54098578  .00002943  00000+0  38100-3 0  9997
           2 44883  97.8669 167.4611 0001705  77.3129 282.8275 14.81612352176856
           """2-element Vector{TLE}:
 TLE: AMAZONIA 1 [47699] (Epoch = 2023-03-24T16:28:40.388)
 TLE: CBERS 4A [44883] (Epoch = 2023-03-28T12:59:01.171)

In this case, the result will always be a Vector{TLE}.

Note

We distinguished the parsing algorithm of one or multiple TLEs to avoid unnecessary allocations in the former.

@tle_str and @tles_str will always check the checksum of the two lines. If this verification is not desired, use the versions @tle_nc_str and @tles_nc_str.

If the TLE is programmatically added to a string, it can be parsed using the functions read_tle and read_tles for one or multiple TLEs, respectively.

julia> tle_str = """
           AMAZONIA 1
           1 47699U 21015A   23083.68657856 -.00000044  10000-8  43000-4 0  9990
           2 47699  98.4304 162.1097 0001247 136.2017 223.9283 14.40814394108652
           """"AMAZONIA 1\n1 47699U 21015A   23083.68657856 -.00000044  10000-8  43000-4 0  9990\n2 47699  98.4304 162.1097 0001247 136.2017 223.9283 14.40814394108652\n"
julia> read_tle(tle_str)TLE: AMAZONIA 1 (Epoch = 2023-03-24T16:28:40.388): ├─ Line 1 Satellite Number : 47699 Classification : U International Designator : 21015A Epoch Year : 23 Epoch Day : 83.68657856 ṅ/2 : -4.4e-7 rev/day² n̈/6 : 1.0e-9 rev/day³ B* : 4.3e-5 1/ER Ephemeris Type : 0 Element Set Number : 999 └─ Line 2 Inclination : 98.4304° RA of the Ascending Node : 162.1097° Eccentricity : 0.0001247 Arg. of Perigee : 136.2017° Mean Anomaly : 223.9283° Mean Motion : 14.40814394 rev/day Revolution Number : 10865
julia> tles_str = """ AMAZONIA 1 1 47699U 21015A 23083.68657856 -.00000044 10000-8 43000-4 0 9990 2 47699 98.4304 162.1097 0001247 136.2017 223.9283 14.40814394108652 CBERS 4A 1 44883U 19093E 23087.54098578 .00002943 00000+0 38100-3 0 9997 2 44883 97.8669 167.4611 0001705 77.3129 282.8275 14.81612352176856 """"AMAZONIA 1\n1 47699U 21015A 23083.68657856 -.00000044 10000-8 43000-4 0 9990\n2 47699 98.4304 162.1097 0001247 136.2017 223.9283 14.40814394108652\nCBERS 4A\n1 44883U 19093E 23087.54098578 .00002943 00000+0 38100-3 0 9997\n2 44883 97.8669 167.4611 0001705 77.3129 282.8275 14.81612352176856\n"
julia> tles = read_tles(tles_str)2-element Vector{TLE}: TLE: AMAZONIA 1 [47699] (Epoch = 2023-03-24T16:28:40.388) TLE: CBERS 4A [44883] (Epoch = 2023-03-28T12:59:01.171)

If the user does not want checksum verification, pass the keyword verify_checksum = false.

Parsing TLEs from files

We can parse TLEs in files using the function read_tles_from_file:

julia> tles = read_tles_from_file("samples.tle")2-element Vector{TLE}:
 TLE: AMAZONIA 1 [47699] (Epoch = 2023-03-24T16:28:40.388)
 TLE: CBERS 4A [44883] (Epoch = 2023-03-28T12:59:01.171)

This function will always return a Vector{TLE}.

Errors

If a single TLE cannot be parsed, the functions read_tle, @tle_str, and @tle_nc_str throw a TleParseError describing the problem and, when known, the line of the input where it was found:

julia> read_tle("""
           AMAZONIA 1
           1 47699U 21015A   23083.68657856 -.00000044  10000-8  43000-4 0  9991
           2 47699  98.4304 162.1097 0001247 136.2017 223.9283 14.40814394108652
           """)ERROR: TleParseError: Wrong checksum in TLE line 1 (expected = 0, found = 1).

When parsing multiple TLEs, the invalid ones are skipped with a warning, and the valid ones are returned:

julia> tles = read_tles("""
           AMAZONIA 1
           1 47699U 21015A   23083.68657856 -.00000044  10000-8  43000-4 0  9991
           2 47699  98.4304 162.1097 0001247 136.2017 223.9283 14.40814394108652
           CBERS 4A
           1 44883U 19093E   23087.54098578  .00002943  00000+0  38100-3 0  9997
           2 44883  97.8669 167.4611 0001705  77.3129 282.8275 14.81612352176856
           """)┌ Warning: [Line 2]: Wrong checksum in TLE line 1 (expected = 0, found = 1). The TLE was skipped.
@ SatelliteToolboxTle ~/work/SatelliteToolboxTle.jl/SatelliteToolboxTle.jl/src/parse.jl:194
1-element Vector{TLE}:
 TLE: CBERS 4A [44883] (Epoch = 2023-03-28T12:59:01.171)