spacetrack¶
Interface to Space-Track.org for retrieving Two-Line Element (TLE) data.
This module provides access to Space-Track.org, the official source for orbital element sets for Earth-orbiting objects tracked by the U.S. Space Surveillance Network.
Classes¶
|
Handles queries to the Space-Track.org API for retrieving TLEs and other space data. |
|
Stateless utility class for working with OMM (Orbit Mean-Elements Message) records in dictionary form. |
- class SpaceTrackQuery(username: str | None = None, password: str | None = None, spacetrack_url: str = 'https://www.space-track.org', tle_data_folder: str = '/home/docs/.tudat/resource/tle_data', timeout: int = 60)[source]¶
Bases:
objectHandles queries to the Space-Track.org API for retrieving TLEs and other space data. Manages authentication, session persistence, and local caching to minimise API usage.
For working with the retrieved OMM records, see
OMMUtils.- __init__(username: str | None = None, password: str | None = None, spacetrack_url: str = 'https://www.space-track.org', tle_data_folder: str = '/home/docs/.tudat/resource/tle_data', timeout: int = 60) None[source]¶
- Parameters:
username (str | None, optional) – Space-Track.org username. Prompted interactively if not provided.
password (str | None, optional) – Space-Track.org password. Prompted interactively if not provided.
spacetrack_url (str, optional) – Base URL. Defaults to
'https://www.space-track.org'.tle_data_folder (str, optional) – Directory for locally cached TLE files.
- descending_epoch(N: int | None = None, update_existing: bool = False, filename: str | None = None) list | None[source]¶
Retrieves GP data ordered by epoch (most recent first).
- filtered_by_oe_dict(filter_oe_dict: dict[str, tuple[float | None, float | None]], limit: int = 100, output_file: str = 'filtered_results.json', update_existing: bool = False) list | None[source]¶
Retrieves payloads filtered by orbital element bounds.
- Parameters:
- Returns:
List of OMM records or None if the request failed.
- Return type:
list | None
- get_tles_by_norad_ids(norad_ids: int | list[int], history: bool = False, orderby: str = 'epoch desc', limit_per_object: int = 1, update_existing: bool = False, filename: str | None = None) list | None[source]¶
Retrieves TLEs for one or more specific NORAD IDs.
- Parameters:
- Returns:
List of OMM records or None if the request failed.
- Return type:
list | None
- get_tles_for_date_range(norad_id: int | str, start_date: str, end_date: str, override_last_api_hit: bool = False) list[dict] | None[source]¶
Retrieves TLEs for a single satellite over a date range.
Respects a 1.5-hour API cooldown to avoid hammering the server when data is absent (e.g. the satellite had not yet launched).
- Parameters:
- Returns:
OMM records within the requested window.
- Return type:
- latest_on_orbit(update_existing: bool = False, filename: str | None = None) list | None[source]¶
Retrieves the newest propagable element set for all on-orbit payloads.
- query_from_query_builder_url(query: str, output_file: str = 'custom_query.json', update_existing: bool = False) list | None[source]¶
Executes a user-provided Space-Track query URL or query path.
The input may be: - a full URL copied from the Space-Track ‘Query Builder’ - only the query path starting from ‘basicspacedata/query/…’
- class OMMUtils[source]¶
Bases:
objectStateless utility class for working with OMM (Orbit Mean-Elements Message) records in dictionary form.
This class has no dependency on Space-Track.org or any particular data source — it operates on plain OMM dicts regardless of where they came from. All methods are static; instantiation is not required.
- static clean_file(filepath: str) None[source]¶
Removes duplicate TLE entries from a cache file in-place.
Supports both legacy (plain list) and current (dict with metadata) formats. When two records share the same EPOCH, the one with the later
CREATION_DATEis kept.- Parameters:
filepath (str) – Absolute path to the cache file.
- Return type:
None
- static get_tles(json_data: list[dict] | dict) defaultdict[str, list[tuple[str, str]]][source]¶
Extracts TLE line pairs from a list of OMM records.
- static get_tudat_keplerian_element_set(omm: dict) tuple[float, float, float, float, float, float][source]¶
Extracts and converts Keplerian elements from a single OMM record into SI units suitable for Tudat.
- Parameters:
omm (dict) – A single OMM record (km and degrees, as returned by Space-Track or any compliant source).
- Returns:
(a, e, i, omega, RAAN, true_anomaly)where distances are in metres and angles are in radians.- Return type:
- Raises:
TypeError – If
ommis a list rather than a single dict.ValueError – If
ommis empty or falsy.
- static save_batch_to_individual_files(json_data: list[dict], output_folder: str) list[str] | None[source]¶
Splits a batch list of OMM records into one JSON file per NORAD ID.