Creating TLEs

We can create a TLE using the function:

TLE(; kwargs...)

where kwargs... are keywords arguments with the same name as in the TLE fields, as explained here. The following elements are required:

  • inclination, raan, eccentricity, argument_of_perigee, mean_anomaly, and mean_motion.

The epoch must be provided either by the keywords epoch_year and epoch_day, or by the keyword epoch with a DateTime, from which the former are computed. The algorithm assigns default values for the other fields if they are not present.

julia> tle = TLE(
           name = "My satellite",
           epoch_year = 23,
           epoch_day = 1.5,
           inclination = 98.405,
           raan = 220.19,
           eccentricity = 0.001,
           argument_of_perigee = 90,
           mean_anomaly = 0.0,
           mean_motion = 14.4
       )TLE: My satellite (Epoch = 2023-01-01T12:00:00):
  ├─ Line 1
Satellite Number         : 0
Classification           : U
International Designator : 00000
Epoch Year               : 23
Epoch Day                : 1.5
ṅ/2                      : 0.0 rev/day²
n̈/6                      : 0.0 rev/day³
B*                       : 0.0 1/ER
Ephemeris Type           : 0
Element Set Number       : 0
  └─ Line 2
       Inclination              : 98.405°
       RA of the Ascending Node : 220.19°
       Eccentricity             : 0.001
       Arg. of Perigee          : 90.0°
       Mean Anomaly             : 0.0°
       Mean Motion              : 14.4 rev/day
       Revolution Number        : 0
julia> using Dates
julia> tle = TLE( name = "My satellite", epoch = DateTime(2023, 1, 1, 12), inclination = 98.405, raan = 220.19, eccentricity = 0.001, argument_of_perigee = 90, mean_anomaly = 0.0, mean_motion = 14.4 )TLE: My satellite (Epoch = 2023-01-01T12:00:00): ├─ Line 1 Satellite Number : 0 Classification : U International Designator : 00000 Epoch Year : 23 Epoch Day : 1.5 ṅ/2 : 0.0 rev/day² n̈/6 : 0.0 rev/day³ B* : 0.0 1/ER Ephemeris Type : 0 Element Set Number : 0 └─ Line 2 Inclination : 98.405° RA of the Ascending Node : 220.19° Eccentricity : 0.001 Arg. of Perigee : 90.0° Mean Anomaly : 0.0° Mean Motion : 14.4 rev/day Revolution Number : 0

The constructor validates that every field can be represented in the TLE format. For example, an eccentricity outside the interval [0, 1) or a satellite number above 339999 throws an ArgumentError:

julia> TLE(
           epoch_year = 23,
           epoch_day = 1.5,
           inclination = 98.405,
           raan = 220.19,
           eccentricity = 1.2,
           argument_of_perigee = 90,
           mean_anomaly = 0.0,
           mean_motion = 14.4
       )ERROR: ArgumentError: The eccentricity must be in the interval [0, 1).

Writing TLEs

The functions write_tle and write_tles write one or multiple TLEs to a stream or to a file:

julia> write_tle(stdout, tle)My satellite            
1 00000U 00000    23001.50000000  .00000000  00000+0  00000+0 0    02
2 00000  98.4050 220.1900 0010000  90.0000   0.0000 14.40000000    01
julia> write_tles(stdout, [tle, tle])My satellite 1 00000U 00000 23001.50000000 .00000000 00000+0 00000+0 0 02 2 00000 98.4050 220.1900 0010000 90.0000 0.0000 14.40000000 01 My satellite 1 00000U 00000 23001.50000000 .00000000 00000+0 00000+0 0 02 2 00000 98.4050 220.1900 0010000 90.0000 0.0000 14.40000000 01

If the first argument is the type String, the text representation is returned instead:

julia> write_tle(String, tle)"My satellite            \n1 00000U 00000    23001.50000000  .00000000  00000+0  00000+0 0    02\n2 00000  98.4050 220.1900 0010000  90.0000   0.0000 14.40000000    01\n"

The angles are normalized to the interval [0, 360)° before being written. If the magnitude of dn_o2, ddn_o6, or bstar cannot be represented in its TLE field, the field is saturated and a warning is emitted.