API Reference¶
Core Functions¶
- sgp4jax.tle_to_satrec(line1, line2, gravity=None)¶
Parse TLE and initialize a SatRec ready for propagation.
- Parameters:
line1 (
str) – First TLE lineline2 (
str) – Second TLE linegravity (
GravityConstants|None) – Gravity constants (default WGS72)
- Return type:
- Returns:
SatRec NamedTuple
- sgp4jax.tles_to_satrec(tles, gravity=None)¶
Parse an array of TLEs and return a batched SatRec.
- Parameters:
tles (
list[list[str]]) – TLE lines with shape(n_sat, 2). Each row contains[line1, line2]as strings.gravity (
GravityConstants|None) – Gravity constants (default WGS72).
- Return type:
- Returns:
A single
SatRecwhose fields are stacked arrays with a leading dimension ofn_sat, ready for use withjax.vmap.
- sgp4jax.propagate(satrec, tsince)¶
Propagate satellite to time tsince (minutes from epoch).
- Parameters:
- Returns:
position vector (3,) in km (TEME frame) v: velocity vector (3,) in km/s (TEME frame) error: error code (0 = success)
- Return type:
- sgp4jax.propagate_jd(satrec, jd, fr)¶
Propagate satellite to Julian Date (jd + fr) in TEME.
Converts the Julian Date to minutes-since-epoch and calls
propagate().- Parameters:
satrec (
SatRec) – Initialized SatRec fromtle_to_satrec().jd (
Union[Array,ndarray,bool,number,bool,int,float,complex,TypedNdArray]) – Julian date (UTC), integer/whole part (scalar).fr (
Union[Array,ndarray,bool,number,bool,int,float,complex,TypedNdArray]) – Julian date (UTC), fractional part (scalar).
- Returns:
Position in TEME frame (3,) in km. v: Velocity in TEME frame (3,) in km/s. error: Error code (0 = success).
- Return type:
Specialized Propagators¶
These propagators are optimised for specific orbit families and are
significantly faster than propagate() for homogeneous
batches. Each eliminates the dead-branch computation present in the
general propagator:
propagate_leo()— near-earth orbits (method=0), removes the deep-space integrator entirely.propagate_sdp4_nr()— deep-space no-resonance orbits (method=1,irez=0, e.g. GPS/GLONASS/Galileo MEO), replaces the 64-step resonance scan with five scalar multiplications.propagate_mixed()— heterogeneous batches of any orbit type; groups satellites by type internally and dispatches each group to the appropriate specialised propagator.
- sgp4jax.propagate_leo(satrec, tsince)¶
Propagate a near-earth (LEO) satellite to time tsince (minutes from epoch).
This is a stripped-down version of sgp4 for near-earth satellites only. The deep-space resonance integrator (dspace) and lunar-solar periodic perturbations (dpper) are removed entirely, reducing XLA graph size and eliminating the dominant runtime cost for LEO orbits.
Warning: Do not use for deep-space satellites (orbital period > 225 min, mean motion < ~6.4 rev/day). Results will be incorrect for GEO/HEO/MEO objects because the deep-space secular and periodic corrections are skipped.
- Parameters:
- Returns:
position vector (3,) in km (TEME frame) v: velocity vector (3,) in km/s (TEME frame) error: error code (0 = success)
- Return type:
- sgp4jax.propagate_jd_leo(satrec, jd, fr)¶
Propagate a near-earth satellite to Julian Date (jd + fr) in TEME.
LEO/near-earth only variant — deep-space code paths are absent. See
propagate_leo()for the performance trade-offs and limitations.- Parameters:
satrec (
SatRec) – Initialized SatRec fromtle_to_satrec()(near-earth only).jd (
Union[Array,ndarray,bool,number,bool,int,float,complex,TypedNdArray]) – Julian date (UTC), integer/whole part (scalar).fr (
Union[Array,ndarray,bool,number,bool,int,float,complex,TypedNdArray]) – Julian date (UTC), fractional part (scalar).
- Returns:
Position in TEME frame (3,) in km. v: Velocity in TEME frame (3,) in km/s. error: Error code (0 = success).
- Return type:
- sgp4jax.propagate_sdp4_nr(satrec, tsince)¶
Propagate a deep-space, no-resonance (irez=0) satellite to time tsince.
This is a stripped-down version of sgp4 for deep-space satellites with irez=0 (no resonance). This captures MEO navigation satellites (GPS, GLONASS, Galileo, BeiDou MEO) and other deep-space objects that do not fall in the 24-hour synchronous (irez=1) or 12-hour Molniya (irez=2) resonance bands.
Simplifications over the full sgp4:
The resonance integrator (dspace / lax.scan) is removed entirely. For irez=0, dspace reduces to five scalar secular drift terms (dedt, didt, domdt, dnodt, dmdt), which are applied directly.
Deep-space satellites always have isimp=1, so the full-drag computation branch is omitted.
All
jnp.where(is_deep, ...)guards collapse to unconditional deep-space assignments.dpper (lunar-solar periodics) is retained unchanged.
Warning
Do not use for near-earth satellites (period < 225 min), irez=1 (GEO/synchronous), or irez=2 (Molniya/12h resonant) satellites — resonance and drag terms will be missing or zero.
- Parameters:
- Returns:
position vector (3,) in km (TEME frame) v: velocity vector (3,) in km/s (TEME frame) error: error code (0 = success)
- Return type:
- sgp4jax.propagate_jd_sdp4_nr(satrec, jd, fr)¶
Propagate a deep-space no-resonance (irez=0) satellite to Julian Date (jd + fr) in TEME.
Deep-space irez=0 only variant — resonance integrator is absent. See
propagate_sdp4_nr()for the performance trade-offs and limitations.- Parameters:
satrec (
SatRec) – Initialized SatRec fromtle_to_satrec()(deep-space, irez=0 only).jd (
Union[Array,ndarray,bool,number,bool,int,float,complex,TypedNdArray]) – Julian date (UTC), integer/whole part (scalar).fr (
Union[Array,ndarray,bool,number,bool,int,float,complex,TypedNdArray]) – Julian date (UTC), fractional part (scalar).
- Returns:
Position in TEME frame (3,) in km. v: Velocity in TEME frame (3,) in km/s. error: Error code (0 = success).
- Return type:
- sgp4jax.propagate_mixed(satrec_batch, times)¶
Propagate a heterogeneous batch of satellites over a shared array of times.
Groups satellites by type (near-earth / deep-space-no-resonance / deep-space-resonant) and dispatches each group to the appropriate specialized propagator, avoiding dead-branch computation for every group. Results are reassembled into the original satellite ordering.
Note
This function is not JIT-compilable as a whole and does not compose with
jax.gradorjax.vmap. For JIT / AD / vmap compatibility, group satellites by type and call the specialized propagators directly (propagate_leo(),propagate_sdp4_nr(),propagate()).- Parameters:
- Returns:
Positions in TEME frame, shape
(N, M, 3)in km. v: Velocities in TEME frame, shape(N, M, 3)in km/s. error: Error codes, shape(N, M)(0 = success).- Return type:
Frame Transformations¶
- sgp4jax.teme_to_gcrf(r_teme, v_teme, jd, fr)¶
Transform position/velocity from TEME to GCRF (≈ICRS).
Replicates Skyfield’s
EarthSatellite._at()transformation chain:M = N @ P @ B, thenR = rot_z(theta_GMST1982 - GAST) @ Mwith the final GCRF vectors obtained viaR^T @ r_TEME.The input Julian date
jd + fris treated as UT1 time (≈UTC). TT and TDB are derived internally using an approximate delta_T model.- Parameters:
r_teme (
Union[Array,ndarray,bool,number,bool,int,float,complex,TypedNdArray]) – Position in TEME frame (3,) in km.v_teme (
Union[Array,ndarray,bool,number,bool,int,float,complex,TypedNdArray]) – Velocity in TEME frame (3,) in km/s.jd (
Union[Array,ndarray,bool,number,bool,int,float,complex,TypedNdArray]) – Julian date, integer/whole part (scalar).fr (
Union[Array,ndarray,bool,number,bool,int,float,complex,TypedNdArray]) – Julian date, fractional part (scalar).
- Returns:
Position in GCRF frame (3,) in km. v_gcrf: Velocity in GCRF frame (3,) in km/s.
- Return type:
- sgp4jax.itrf_to_gcrf(r_itrf, jd, fr)¶
Transform position from ITRF (Earth-fixed) to GCRF (≈ICRS).
The rotation is
R = M^T @ rot_z(GAST)whereM = N @ P @ Bis the combined nutation-precession-bias matrix and GAST is the Greenwich Apparent Sidereal Time. Matches Skyfield’sITRS.rotation_at(t).Tto sub-millimetre precision.The input Julian date
jd + fris treated as UT1 (≈UTC).- Parameters:
r_itrf (
Union[Array,ndarray,bool,number,bool,int,float,complex,TypedNdArray]) – Position in ITRF frame (3,) in km.jd (
Union[Array,ndarray,bool,number,bool,int,float,complex,TypedNdArray]) – Julian date (UT1), integer/whole part (scalar).fr (
Union[Array,ndarray,bool,number,bool,int,float,complex,TypedNdArray]) – Julian date (UT1), fractional part (scalar).
- Returns:
Position in GCRF frame (3,) in km.
- Return type:
- sgp4jax.gcrf_to_itrf(r_gcrf, jd, fr)¶
Transform position from GCRF (≈ICRS) to ITRF (Earth-fixed).
Inverse of
itrf_to_gcrf(). The rotation isR = rot_z(-GAST) @ MwhereM = N @ P @ B. Matches Skyfield’sITRS.rotation_at(t)to sub-millimetre precision.The input Julian date
jd + fris treated as UT1 (≈UTC).- Parameters:
r_gcrf (
Union[Array,ndarray,bool,number,bool,int,float,complex,TypedNdArray]) – Position in GCRF frame (3,) in km.jd (
Union[Array,ndarray,bool,number,bool,int,float,complex,TypedNdArray]) – Julian date (UT1), integer/whole part (scalar).fr (
Union[Array,ndarray,bool,number,bool,int,float,complex,TypedNdArray]) – Julian date (UT1), fractional part (scalar).
- Returns:
Position in ITRF frame (3,) in km.
- Return type:
- sgp4jax.propagate_gcrf(satrec, tsince)¶
Propagate satellite and return GCRF position/velocity.
- Parameters:
- Returns:
Position in GCRF frame (3,) in km. v_gcrf: Velocity in GCRF frame (3,) in km/s. error: Error code (0 = success).
- Return type:
- sgp4jax.propagate_jd_gcrf(satrec, jd, fr)¶
Propagate satellite to Julian Date (jd + fr) and return GCRF.
The input time
jd + fris interpreted as UTC, matching the time scale of TLE epochs and Measurement Set timestamps. The same UTC value is used for SGP4 propagation and, as an approximation to UT1, for the TEME → GCRF frame transformation (the UT1 − UTC difference is at most 0.9 s, introducing < 1 m frame error).- Parameters:
satrec (
SatRec) – Initialized SatRec fromtle_to_satrec().jd (
Union[Array,ndarray,bool,number,bool,int,float,complex,TypedNdArray]) – Julian date (UTC), integer/whole part (scalar jnp.ndarray).fr (
Union[Array,ndarray,bool,number,bool,int,float,complex,TypedNdArray]) – Julian date (UTC), fractional part (scalar jnp.ndarray).
- Returns:
Position in GCRF frame (3,) in km. v_gcrf: Velocity in GCRF frame (3,) in km/s. error: Error code (0 = success).
- Return type:
Keplerian Propagation (no perturbations)¶
Pure two-body Keplerian motion using only the six classical TLE elements (inclination, RAAN, eccentricity, argument of perigee, mean anomaly, mean motion). All perturbations are ignored. Fully differentiable.
Note
TLE elements are Brouwer mean elements. Because SGP4 adds short-period corrections when converting to osculating elements, Keplerian positions will differ from SGP4 by O(1–50 km). This is expected behaviour, not a bug.
- sgp4jax.kepler_gcrf_positions(satrec, times_jd)¶
Propagate one satellite to multiple times using pure Keplerian motion.
No perturbations are applied. Only the six TLE orbital elements (
inclo,nodeo,ecco,argpo,mo,no_kozai) and the epoch (jdsatepoch,jdsatepochF) are used.The function is JIT-compiled and differentiable with respect to all fields of satrec and with respect to times_jd.
- Parameters:
- Returns:
GCRF positions, shape
(n_times, 3), in km. v_gcrf: GCRF velocities, shape(n_times, 3), in km/s.- Return type:
Note
The TEME → GCRF rotation uses the input Julian dates as UT1 (UTC is an approximation accurate to < 1 s). For sub-arcsecond frame accuracy call
utc_to_ut1()first and pass the UT1 dates.
- sgp4jax.kepler_gcrf_positions_multi(satrec, times_jd)¶
Propagate multiple satellites to multiple times using pure Keplerian motion.
No perturbations are applied. The outer
vmapiterates over satellites, the inner over times.The function is JIT-compiled and differentiable with respect to all fields of satrec and with respect to times_jd.
- Parameters:
- Returns:
GCRF positions, shape
(n_sat, n_times, 3), in km. v_gcrf: GCRF velocities, shape(n_sat, n_times, 3), in km/s.- Return type:
Note
The TEME → GCRF rotation uses the input Julian dates as UT1 (UTC is an approximation accurate to < 1 s). For sub-arcsecond frame accuracy call
utc_to_ut1()first and pass the UT1 dates.
Batch GCRF Convenience Functions¶
These functions propagate one or more satellites to an array of UTC Julian dates and return positions and velocities in the GCRF frame. Choose the variant that matches the orbit type of your satellite batch for best performance:
- sgp4jax.gcrf_positions(satrec, times_jd)¶
Propagate a single satellite to multiple UTC Julian dates.
- Parameters:
- Returns:
Positions in GCRF frame, shape
(n_times, 3)in km. v_gcrf: Velocities in GCRF frame, shape(n_times, 3)in km/s.- Return type:
- sgp4jax.gcrf_positions_multi(satrec, times_jd)¶
Propagate multiple satellites to multiple UTC Julian dates.
- Parameters:
- Returns:
Positions in GCRF, shape
(n_sat, n_times, 3)in km. v_gcrf: Velocities in GCRF, shape(n_sat, n_times, 3)in km/s.- Return type:
- sgp4jax.gcrf_positions_multi_leo(satrec, times_jd)¶
Propagate a near-earth (LEO) satellite batch to multiple UTC Julian dates in GCRF.
Use this for homogeneous batches of near-earth satellites (
method=0). For heterogeneous batches, usegcrf_positions_mixed().- Parameters:
- Returns:
Positions in GCRF, shape
(n_sat, n_times, 3)in km. v_gcrf: Velocities in GCRF, shape(n_sat, n_times, 3)in km/s.- Return type:
- sgp4jax.gcrf_positions_multi_sdp4_nr(satrec, times_jd)¶
Propagate a deep-space no-resonance satellite batch to multiple UTC Julian dates in GCRF.
Use this for homogeneous batches of deep-space irez=0 satellites (GPS/GLONASS/Galileo/BeiDou MEO constellations). For heterogeneous batches, use
gcrf_positions_mixed().- Parameters:
- Returns:
Positions in GCRF, shape
(n_sat, n_times, 3)in km. v_gcrf: Velocities in GCRF, shape(n_sat, n_times, 3)in km/s.- Return type:
- sgp4jax.gcrf_positions_mixed(satrec_batch, times_jd)¶
Propagate a heterogeneous satellite batch to multiple UTC Julian dates in GCRF.
Groups satellites by type and dispatches each group to its specialized propagator (near-earth / deep-space-no-resonance / deep-space-resonant), then rotates all results to the GCRF frame. Results are reassembled in the original satellite ordering.
Note
Like
propagate_mixed(), this function is not JIT-compilable as a whole.- Parameters:
- Returns:
Positions in GCRF frame, shape
(N, M, 3)in km. v_gcrf: Velocities in GCRF frame, shape(N, M, 3)in km/s.- Return type:
Earth Orientation (IERS)¶
These functions manage the IERS Bulletin A table used for UTC → UT1 conversion, which is needed for accurate ITRF ↔ GCRF frame transformations.
- sgp4jax.update_iers_table(cache_path=None, url=None)¶
Download the latest IERS finals2000A table and refresh the cache.
Fetches the file from the IERS data centre (falling back to USNO), parses the Bulletin A UT1-UTC values, writes a compact
.npzcache, and immediately loads the result into the module-level interpolation table used byutc_to_ut1().
- sgp4jax.load_iers_table(cache_path=None)¶
Load the IERS table from the local
.npzcache.Called automatically at module import if the default cache exists. Re-call with an explicit cache_path to load from a non-default location or to reload after
update_iers_table().- Parameters:
cache_path (
str|Path|None) – Path to the.npzcache file (default:~/.cache/sgp4jax/finals2000A.npz).- Raises:
FileNotFoundError – Cache file not found. Call
update_iers_table()to download it.- Return type:
- sgp4jax.utc_to_ut1(jd_utc, fr_utc)¶
Convert a UTC Julian date to UT1 using the IERS finals2000A table.
Interpolates DUT1 = UT1 − UTC (seconds) from the Bulletin A column of the loaded IERS table and adjusts the fractional Julian date. Matches Skyfield’s
t.dut1values to better than 1 µs for all dates within the table’s coverage (~1972 to ~1 year ahead).The function is JAX-traceable and works inside
jax.jitandjax.vmapafter the table has been loaded.- Parameters:
- Returns:
UT1 Julian date, whole part (same value as
jd_utc). fr_ut1: UT1 Julian date, fractional part.- Return type:
- Raises:
RuntimeError – IERS table not loaded — call
update_iers_table()orload_iers_table()first.
Data Structures¶
- class sgp4jax.SatRec(bstar: Array, ecco: Array, argpo: Array, inclo: Array, mo: Array, no_kozai: Array, nodeo: Array, ndot: Array, nddot: Array, j2: Array, j3: Array, j4: Array, j3oj2: Array, xke: Array, mu: Array, radiusearthkm: Array, tumin: Array, jdsatepoch: Array, jdsatepochF: Array, no_unkozai: Array, a: Array, alta: Array, altp: Array, con41: Array, cc1: Array, cc4: Array, cc5: Array, d2: Array, d3: Array, d4: Array, delmo: Array, eta: Array, argpdot: Array, omgcof: Array, sinmao: Array, t2cof: Array, t3cof: Array, t4cof: Array, t5cof: Array, x1mth2: Array, x7thm1: Array, mdot: Array, nodedot: Array, xlcof: Array, xmcof: Array, nodecf: Array, aycof: Array, gsto: Array, d2201: Array, d2211: Array, d3210: Array, d3222: Array, d4410: Array, d4422: Array, d5220: Array, d5232: Array, d5421: Array, d5433: Array, dedt: Array, del1: Array, del2: Array, del3: Array, didt: Array, dmdt: Array, dnodt: Array, domdt: Array, e3: Array, ee2: Array, peo: Array, pgho: Array, pho: Array, pinco: Array, plo: Array, se2: Array, se3: Array, sgh2: Array, sgh3: Array, sgh4: Array, sh2: Array, sh3: Array, si2: Array, si3: Array, sl2: Array, sl3: Array, sl4: Array, xfact: Array, xgh2: Array, xgh3: Array, xgh4: Array, xh2: Array, xh3: Array, xi2: Array, xi3: Array, xl2: Array, xl3: Array, xl4: Array, xlamo: Array, xli: Array, xni: Array, zmol: Array, zmos: Array, atime: Array, method: Array, isimp: Array, irez: Array)¶
JAX-compatible satellite record.
All fields are jnp.ndarray scalars (float64). String flags are encoded as floats:
method: 0.0 = near-earth, 1.0 = deep-space
isimp: 0.0 = full perturbations, 1.0 = simplified
irez: 0.0 = no resonance, 1.0 = synchronous, 2.0 = half-day
Gravity Constants¶
- class sgp4jax._constants.GravityConstants(tumin: float, mu: float, radiusearthkm: float, xke: float, j2: float, j3: float, j4: float, j3oj2: float)¶
Earth gravity model constants for use with SGP4.
tuminMinutes per canonical time unit (= 1 / xke).
muGravitational parameter (km³/s²).
radiusearthkmEarth equatorial radius (km).
xkeSquare root of gravitational parameter in canonical units (ER^1.5/min).
j2,j3,j4Zonal harmonics (dimensionless).
j3oj2Ratio j3 / j2 (precomputed for efficiency).
- sgp4jax.WGS84 = (13.446851082044981, 398600.5, 6378.137, 0.07436685316871385, 0.00108262998905, -2.53215306e-06, -1.61098761e-06, -0.0023388905587420003)¶
Earth gravity model constants for use with SGP4.
tuminMinutes per canonical time unit (= 1 / xke).
muGravitational parameter (km³/s²).
radiusearthkmEarth equatorial radius (km).
xkeSquare root of gravitational parameter in canonical units (ER^1.5/min).
j2,j3,j4Zonal harmonics (dimensionless).
j3oj2Ratio j3 / j2 (precomputed for efficiency).
- sgp4jax.WGS72 = (13.446839696959309, 398600.8, 6378.135, 0.07436691613317342, 0.001082616, -2.53881e-06, -1.65597e-06, -0.002345069720011528)¶
Earth gravity model constants for use with SGP4.
tuminMinutes per canonical time unit (= 1 / xke).
muGravitational parameter (km³/s²).
radiusearthkmEarth equatorial radius (km).
xkeSquare root of gravitational parameter in canonical units (ER^1.5/min).
j2,j3,j4Zonal harmonics (dimensionless).
j3oj2Ratio j3 / j2 (precomputed for efficiency).
- sgp4jax.WGS72OLD = (13.446839702957643, 398600.79964, 6378.135, 0.0743669161, 0.001082616, -2.53881e-06, -1.65597e-06, -0.002345069720011528)¶
Earth gravity model constants for use with SGP4.
tuminMinutes per canonical time unit (= 1 / xke).
muGravitational parameter (km³/s²).
radiusearthkmEarth equatorial radius (km).
xkeSquare root of gravitational parameter in canonical units (ER^1.5/min).
j2,j3,j4Zonal harmonics (dimensionless).
j3oj2Ratio j3 / j2 (precomputed for efficiency).