Skip to main content

Python bindings for astroz - high-performance astrodynamics library

Project description

astroz Python Bindings

High-performance SGP4/SDP4 satellite propagation, powered by Zig with SIMD acceleration (AVX512/AVX2). Automatically handles both near-earth and deep-space satellites.

Platforms: macOS, Linux | Requires: Python 3.10+

Quick Start

python-sgp4 Compatible API (Recommended)

Drop-in replacement for python-sgp4:

from astroz.api import Satrec, SatrecArray, jday, WGS72
import numpy as np

# Single satellite (same syntax as python-sgp4)
sat = Satrec.twoline2rv(line1, line2, WGS72)
jd, fr = jday(2024, 5, 6, 12, 0, 0.0)
error, position, velocity = sat.sgp4(jd, fr)

# Batch propagation (270-330M props/sec with SIMD)
sat_array = SatrecArray(satrecs)
e, r, v = sat_array.sgp4(jd, fr)  # Scalars or arrays

# Skip velocities for 30% faster propagation
e, r, _ = sat_array.sgp4(jd_array, fr_array, velocities=False)

High-Level API

from astroz import propagate
import numpy as np

# Load and propagate - automatically optimized for 300M+ props/sec
positions = propagate("starlink", np.arange(1440))  # 1 day at 1-min intervals
# positions: (1440, num_satellites, 3) in km, ECEF coordinates

Loading Sources

from astroz import propagate, Constellation

# CelesTrak groups
positions = propagate("starlink", times)
positions = propagate("iss", times)
positions = propagate("gps", times)
positions = propagate("all", times)  # ~13k active satellites

# By NORAD ID
positions = propagate(None, times, norad_id=25544)  # ISS
positions = propagate(None, times, norad_id=[25544, 48274])  # Multiple

# Local file or URL
positions = propagate("satellites.tle", times)
positions = propagate("https://example.com/tles.txt", times)

# For repeated propagation, pre-parse to avoid overhead
c = Constellation("starlink")
positions1 = propagate(c, times1)
positions2 = propagate(c, times2)

Groups: all, starlink, oneweb, planet, spire, gps, glonass, galileo, beidou, stations/iss, weather, geo

Propagation

from astroz import propagate, Constellation
from datetime import datetime, timezone
import numpy as np

times = np.arange(1440)  # 1 day at 1-min intervals

# Simple (defaults: now UTC, ECEF output)
positions = propagate("starlink", times)

# With options
positions = propagate(
    "starlink",
    np.arange(14 * 1440),  # 2 weeks
    start_time=datetime(2024, 6, 1, tzinfo=timezone.utc),
    output="geodetic",  # "ecef" (default), "teme", or "geodetic"
)

# With velocities
positions, velocities = propagate("starlink", times, velocities=True)

Conjunction Screening

from astroz import screen
import numpy as np

times = np.arange(1440)

# Single target (fastest - uses fused propagate+screen, no full position array)
min_dists, min_t_indices = screen("starlink", times, threshold=50.0, target=0)
# Returns per-satellite minimum distance to target and time index

# All-vs-all screening
pairs, t_indices = screen("starlink", times, threshold=10.0)
# Returns all conjunction events within threshold

Migrating from python-sgp4

Step 1: Change the Import (2x faster)

# Before
from sgp4.api import Satrec, SatrecArray, jday

# After
from astroz.api import Satrec, SatrecArray, jday

That's it. Your existing code works unchanged and runs 2x faster.

Step 2: Use Batch Methods (5-12x faster)

If you have loops, switch to batch methods:

# Before: loop (1.3M props/sec)
results = []
for jd, fr in zip(jd_list, fr_list):
    e, r, v = sat.sgp4(jd, fr)
    results.append(r)

# After: batch (15M props/sec) - 12x faster
jd_array = np.array(jd_list)
fr_array = np.array(fr_list)
e, r, v = sat.sgp4_array(jd_array, fr_array)

Step 3: Use SatrecArray for Multiple Satellites (100x faster)

# Before: loop over satellites (1.3M props/sec)
for sat in satellites:
    e, r, v = sat.sgp4_array(jd, fr)

# After: batch all satellites (290M props/sec) - 100x faster
sat_array = SatrecArray(satellites)
e, r, v = sat_array.sgp4(jd, fr)

Step 4: Skip Velocities If Not Needed (30% faster)

# If you only need positions
e, r, _ = sat_array.sgp4(jd, fr, velocities=False)

Performance Summary

Pattern python-sgp4 astroz Speedup
sat.sgp4() loop 1.3M/s 2.5M/s 2x
sat.sgp4_array() 2.7M/s 15M/s 5x
SatrecArray.sgp4() 3M/s 290M/s 100x

Compatibility Notes

astroz supports the core python-sgp4 API for satellite propagation. Some rarely-used attributes are not implemented:

  • TLE metadata: classification, intldesg, elnum, revnum, ephtype
  • Intermediate elements: Om, am, em, im, mm, nm, om (osculating elements after propagation)
  • Element rates: argpdot, mdot, nodedot
  • Gravity constants: j2, j3, j4, mu, etc. (available via astroz.constants)

For typical satellite tracking and visualization, astroz is a full drop-in replacement.

Performance

Constellation (13,478 sats x 1,440 steps) Throughput
1 thread 37.7M props/sec
16 threads 303M props/sec

Benchmarked on AMD Ryzen 7 7840U with AVX512.

Set ASTROZ_THREADS to control thread count (defaults to all cores).

Orbital Mechanics

from astroz import (
    hohmann_transfer, bi_elliptic_transfer, lambert,
    orbital_velocity, orbital_period, escape_velocity,
    EARTH_MU,
)

# Hohmann transfer: LEO (400 km) to GEO
result = hohmann_transfer(EARTH_MU, 6778, 42164)
print(f"Total ΔV: {result['total_dv']:.3f} km/s")
print(f"Transfer time: {result['transfer_time_days']:.2f} days")

# Bi-elliptic transfer (more efficient for large radius ratios)
result = bi_elliptic_transfer(EARTH_MU, 6778, 42164, 100000)
print(f"Total ΔV: {result['total_dv']:.3f} km/s")

# Lambert solver: find transfer orbit between two positions
r1 = (7000.0, 0.0, 0.0)
r2 = (0.0, 7000.0, 0.0)
tof = 3600.0  # 1 hour
result = lambert(EARTH_MU, r1, r2, tof)
print(f"Departure velocity: {result['departure_velocity']}")

# Orbital velocity, period, escape velocity
v = orbital_velocity(EARTH_MU, 6778)          # Circular orbit at 400 km
T = orbital_period(EARTH_MU, 6778)            # Period in seconds
v_esc = escape_velocity(EARTH_MU, 6778)       # Escape velocity

Numerical Propagation

Propagate orbits with perturbation models (J2, atmospheric drag) using RK4 or Dormand-Prince 8(7) adaptive integrators. r_eq is required when using J2 or drag perturbations. Drag uses an exponential Earth atmosphere model (sea-level density 1.225 kg/m^3, scale height 7.249 km, cutoff altitude 1500 km). drag_area is in m^2 and drag_mass in kg.

from astroz import propagate_numerical, EARTH_MU, EARTH_J2, EARTH_R_EQ

# Initial state: LEO circular orbit [x, y, z, vx, vy, vz] (km, km/s)
state = (6778.0, 0.0, 0.0, 0.0, 7.668, 0.0)

# Two-body propagation (1 orbit, 60s steps)
times, states = propagate_numerical(state, 0.0, 5554.0, 60.0, EARTH_MU)

# With J2 perturbation
times, states = propagate_numerical(
    state, 0.0, 5554.0, 60.0, EARTH_MU,
    j2=EARTH_J2, r_eq=EARTH_R_EQ,
)

# With J2 + atmospheric drag
times, states = propagate_numerical(
    state, 0.0, 86400.0, 60.0, EARTH_MU,
    j2=EARTH_J2, r_eq=EARTH_R_EQ,
    drag_cd=2.2, drag_area=10.0, drag_mass=500.0,
    integrator="dp87",  # or "rk4"
)

Constants

from astroz import EARTH_MU, EARTH_R_EQ, EARTH_J2, SUN_MU, MOON_MU

print(f"Earth μ: {EARTH_MU} km³/s²")
print(f"Earth radius: {EARTH_R_EQ} km")
print(f"Earth J2: {EARTH_J2}")
print(f"Sun μ: {SUN_MU} km³/s²")
print(f"Moon μ: {MOON_MU} km³/s²")

Building

Requires Zig and Python 3.10+.

cd bindings/python
pip install -e .

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

astroz-0.12.0-cp314-cp314-manylinux_2_36_x86_64.whl (3.9 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.36+ x86-64

astroz-0.12.0-cp314-cp314-macosx_15_0_universal2.whl (809.6 kB view details)

Uploaded CPython 3.14macOS 15.0+ universal2 (ARM64, x86-64)

astroz-0.12.0-cp313-cp313-manylinux_2_36_x86_64.whl (3.7 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.36+ x86-64

astroz-0.12.0-cp313-cp313-macosx_15_0_universal2.whl (810.1 kB view details)

Uploaded CPython 3.13macOS 15.0+ universal2 (ARM64, x86-64)

astroz-0.12.0-cp312-cp312-manylinux_2_36_x86_64.whl (3.7 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.36+ x86-64

astroz-0.12.0-cp312-cp312-macosx_15_0_universal2.whl (810.1 kB view details)

Uploaded CPython 3.12macOS 15.0+ universal2 (ARM64, x86-64)

astroz-0.12.0-cp311-cp311-manylinux_2_36_x86_64.whl (3.9 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.36+ x86-64

astroz-0.12.0-cp311-cp311-macosx_15_0_universal2.whl (808.9 kB view details)

Uploaded CPython 3.11macOS 15.0+ universal2 (ARM64, x86-64)

astroz-0.12.0-cp310-cp310-manylinux_2_36_x86_64.whl (3.9 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.36+ x86-64

File details

Details for the file astroz-0.12.0-cp314-cp314-manylinux_2_36_x86_64.whl.

File metadata

File hashes

Hashes for astroz-0.12.0-cp314-cp314-manylinux_2_36_x86_64.whl
Algorithm Hash digest
SHA256 6738313b35c693d18206de28bf3fb53f74ffe1731564cea027b07a80afab24de
MD5 f931e71fde7e5faac8ed46c1a3c30419
BLAKE2b-256 c1b1aed7491953fa62878905341d5ce1526147c9ee03998f07756bab2d905acf

See more details on using hashes here.

Provenance

The following attestation bundles were made for astroz-0.12.0-cp314-cp314-manylinux_2_36_x86_64.whl:

Publisher: python.yaml on ATTron/astroz

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file astroz-0.12.0-cp314-cp314-macosx_15_0_universal2.whl.

File metadata

File hashes

Hashes for astroz-0.12.0-cp314-cp314-macosx_15_0_universal2.whl
Algorithm Hash digest
SHA256 59904103f104c266fa5632ed4bea634a1fbfa54ab6890b5fbc1ca78efaeaf3ee
MD5 dde4b3ffef39e921700f3f1b412c1a30
BLAKE2b-256 6cc055d1c21b3af6bb076a41550951e4b0c91852829d317f4c304ef21f2ab994

See more details on using hashes here.

Provenance

The following attestation bundles were made for astroz-0.12.0-cp314-cp314-macosx_15_0_universal2.whl:

Publisher: python.yaml on ATTron/astroz

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file astroz-0.12.0-cp313-cp313-manylinux_2_36_x86_64.whl.

File metadata

File hashes

Hashes for astroz-0.12.0-cp313-cp313-manylinux_2_36_x86_64.whl
Algorithm Hash digest
SHA256 45e6cf370467ae7193d33be438be44380b6eb376aa35b8afb51c06f5c2f39568
MD5 2f04b27cd5d694ae1a53ae19a1088a32
BLAKE2b-256 4b7089c5eb0c650d034cf30259a11db99e3456e9e5e6c0bec0cb04069994d029

See more details on using hashes here.

Provenance

The following attestation bundles were made for astroz-0.12.0-cp313-cp313-manylinux_2_36_x86_64.whl:

Publisher: python.yaml on ATTron/astroz

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file astroz-0.12.0-cp313-cp313-macosx_15_0_universal2.whl.

File metadata

File hashes

Hashes for astroz-0.12.0-cp313-cp313-macosx_15_0_universal2.whl
Algorithm Hash digest
SHA256 54c58a7cdc548d0fc96c7b6a332ff97c81ca2e8a15b41a581df6397f1c11fc6c
MD5 05327be18a6c2fced5ba50d097a610ce
BLAKE2b-256 598efa17198d69cceb5a496a81ea337b7035000bd7c0d4f048aec006fdb180ab

See more details on using hashes here.

Provenance

The following attestation bundles were made for astroz-0.12.0-cp313-cp313-macosx_15_0_universal2.whl:

Publisher: python.yaml on ATTron/astroz

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file astroz-0.12.0-cp312-cp312-manylinux_2_36_x86_64.whl.

File metadata

File hashes

Hashes for astroz-0.12.0-cp312-cp312-manylinux_2_36_x86_64.whl
Algorithm Hash digest
SHA256 1838facef8821a064191949338c566722e06d0468a98770a7e3547cafbee96fc
MD5 e783f9fe4f4889552575d5fc785816ad
BLAKE2b-256 5521e269096a36f9af0fe207d9b03903fe5576a0770b5e9e2baebebd476b0abc

See more details on using hashes here.

Provenance

The following attestation bundles were made for astroz-0.12.0-cp312-cp312-manylinux_2_36_x86_64.whl:

Publisher: python.yaml on ATTron/astroz

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file astroz-0.12.0-cp312-cp312-macosx_15_0_universal2.whl.

File metadata

File hashes

Hashes for astroz-0.12.0-cp312-cp312-macosx_15_0_universal2.whl
Algorithm Hash digest
SHA256 ce71bb2f6a328b5d0328b0f033c5130f72303cb1d346d7cc957f2c9debb073f6
MD5 102160a797dc98521f0be6e83b0b4965
BLAKE2b-256 ebdfc7b8c6dbe01e3bb8dde0a872ed3b6607f4dffa0af73b0966c82cc699a42a

See more details on using hashes here.

Provenance

The following attestation bundles were made for astroz-0.12.0-cp312-cp312-macosx_15_0_universal2.whl:

Publisher: python.yaml on ATTron/astroz

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file astroz-0.12.0-cp311-cp311-manylinux_2_36_x86_64.whl.

File metadata

File hashes

Hashes for astroz-0.12.0-cp311-cp311-manylinux_2_36_x86_64.whl
Algorithm Hash digest
SHA256 71a1b69011ba386a6ba9b6246351471885bc296a2e91066d4a6257d0a0ce6a4d
MD5 664401fb5ec50e51ba66f52cd7a9a638
BLAKE2b-256 8b97b92753b040f0416db1216f7e4de1b215b38ecfb09ea604e556f471cfab7d

See more details on using hashes here.

Provenance

The following attestation bundles were made for astroz-0.12.0-cp311-cp311-manylinux_2_36_x86_64.whl:

Publisher: python.yaml on ATTron/astroz

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file astroz-0.12.0-cp311-cp311-macosx_15_0_universal2.whl.

File metadata

File hashes

Hashes for astroz-0.12.0-cp311-cp311-macosx_15_0_universal2.whl
Algorithm Hash digest
SHA256 6ca805f7fa452ba08dd2369af401ea8516d5971c2de728b3a779503f4c7cb227
MD5 5ca89f44549dfcbb1bcf33e3c82328d4
BLAKE2b-256 c68cd4ce650c3b40e8ba2f470aa81add9288bfededb618ec04dcaa9ab427811a

See more details on using hashes here.

Provenance

The following attestation bundles were made for astroz-0.12.0-cp311-cp311-macosx_15_0_universal2.whl:

Publisher: python.yaml on ATTron/astroz

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file astroz-0.12.0-cp310-cp310-manylinux_2_36_x86_64.whl.

File metadata

File hashes

Hashes for astroz-0.12.0-cp310-cp310-manylinux_2_36_x86_64.whl
Algorithm Hash digest
SHA256 12b52e7292ed80658f92a48f910efa3c8ef6d924f5eddec700ed21d059d8873d
MD5 56da8da428ae3dedaab03e039a0f1276
BLAKE2b-256 916f1278af2b8b9281410454715fbf588683da296793f40099f70f3100acc0c4

See more details on using hashes here.

Provenance

The following attestation bundles were made for astroz-0.12.0-cp310-cp310-manylinux_2_36_x86_64.whl:

Publisher: python.yaml on ATTron/astroz

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page