Python API

This page documents the main Python API exported by the rust_ephem extension module. The native extension is built with maturin and exposed under the module name rust_ephem.

Module Reference

API Overview

The module exposes the following primary classes and helper functions. If the compiled extension is not available at documentation build time these names may be mocked (see docs/README.md).

Classes

Ephemeris (Abstract Base Class)

Common interface for all ephemeris types. All concrete ephemeris classes (TLEEphemeris, SPICEEphemeris, GroundEphemeris, OEMEphemeris, FileEphemeris, ParquetEphemeris) implement this interface and can be used interchangeably where an Ephemeris is expected.

Use isinstance(obj, Ephemeris) to check if an object is any ephemeris type.

Common Properties:
  • timestamp — Array of UTC timestamps

  • gcrs_pv — Position/velocity in GCRS frame

  • itrs_pv — Position/velocity in ITRS frame

  • gcrs — GCRS coordinates as astropy SkyCoord

  • itrs — ITRS coordinates as astropy SkyCoord

  • sun, moon, earth — Celestial body SkyCoord objects

  • sun_pv, moon_pv — Celestial body position/velocity data

  • obsgeoloc, obsgeovel — Observer location/velocity in GCRS

  • latitude_deg, longitude_deg, height_m — Geodetic coordinates

  • sun_radius_deg, moon_radius_deg, earth_radius_deg — Angular radii

  • sun_ra_dec_deg, moon_ra_dec_deg, earth_ra_dec_deg — RA/Dec as Nx2 arrays (cached)

  • sun_ra_deg, sun_dec_deg, etc. — Individual RA or Dec as 1D arrays

  • begin, end, step_size, polar_motion — Time range properties

Common Methods:
  • index(time) — Find closest timestamp index

  • get_body(body, spice_kernel=None, use_horizons=False, *, apparent=False) — Get SkyCoord for a celestial body. Set apparent=True for reception light time, solar light deflection, and observer aberration (SPICE only, positions without velocity differentials). The default is geometric. If use_horizons=True, geometric queries fall back to JPL Horizons when the body is not found in SPICE kernels. See Using get_body for Celestial Bodies.

  • get_body_pv(body, spice_kernel=None, use_horizons=False, *, times=None, apparent=False) — Position/velocity (km, km/s, GCRS axes) of a celestial body relative to the observer. body may be a list or tuple of bodies: the result is then a dict keyed by the names as given, each entry what a call for that body alone returns, worked out from one sampling of the ephemeris. The result’s ra_deg, dec_deg and distance give the position as angles (degrees) and a length (km). If use_horizons=True, falls back to JPL Horizons when the body is not found in SPICE kernels. times evaluates at arbitrary time(s) instead of the ephemeris grid, handled as in gcrs_pv_at. apparent=True returns the body as it is seen (reception light time, solar light deflection, aberration of the observer’s barycentric velocity): the position points where constraints place the body with apparent=True and its length is the light-time distance; the velocity is the rate of change of that apparent position, which is not the geometric velocity.

  • gcrs_pv_at(times), itrs_pv_at(times), sun_pv_at(times), moon_pv_at(times) — Position/velocity (km, km/s, same frames as the matching *_pv property) at arbitrary time(s). times is a datetime, an iterable of datetimes, a NumPy datetime64 array (read as UTC) or an astropy Time (any scale; converted to UTC and rounded to the microsecond); rows follow input order (unsorted and duplicate times allowed). Grid times return the stored rows unchanged; times between grid points use the same cubic Hermite interpolation as constraint evaluation with times= (Sun and Moon are interpolated, not recomputed). Times outside the ephemeris span raise ValueError. See Using TLEEphemeris for an example.

  • apparent_target_at(ras, decs, times) — Unit vectors ((N, 3), GCRS axes) in which catalogue targets at ras/decs (degrees, ICRS) are seen at arbitrary time(s): the deflection and aberration correction that constraints apply to targets with apparent=True. The three arguments are paired row by row; any may be a single value. The angle between a row and get_body_pv(body, times=times, apparent=True).position is the angle a constraint reports for that body.

  • moon_illumination(time_indices=None) — Calculate Moon illumination fraction (0.0-1.0) as seen from observer

  • radec_to_altaz(ra_deg, dec_deg, time_indices=None) — Convert RA/Dec to Alt/Az coordinates

  • calculate_airmass(ra_deg, dec_deg, time_indices=None) — Calculate astronomical airmass for target

Type Alias:

EphemerisType = TLEEphemeris | SPICEEphemeris | OEMEphemeris | GroundEphemeris | FileEphemeris | ParquetEphemeris

TLEEphemeris

Propagate Two-Line Element (TLE) sets with SGP4 and convert to coordinate frames.

Constructor:

TLEEphemeris(tle1=None, tle2=None, begin=None, end=None, step_size=60, *, polar_motion=False, tle=None, norad_id=None, norad_name=None, spacetrack_username=None, spacetrack_password=None, epoch_tolerance_days=None, enforce_source=None)

Parameters:
  • tle1 (str, optional) — First line of TLE (legacy method)

  • tle2 (str, optional) — Second line of TLE (legacy method)

  • tle (str | TLERecord, optional) — Path to TLE file, URL to download TLE from, or a TLERecord object

  • norad_id (int, optional) — NORAD catalog ID to fetch TLE. If Space-Track credentials are available, Space-Track is tried first with failover to Celestrak.

  • norad_name (str, optional) — Satellite name to fetch TLE from Celestrak

  • begin (datetime) — Start time for ephemeris (required)

  • end (datetime) — End time for ephemeris (required)

  • step_size (int) — Time step in seconds (default: 60)

  • polar_motion (bool) — Apply polar motion corrections (default: False)

  • spacetrack_username (str, optional) — Space-Track.org username (or use SPACETRACK_USERNAME env var)

  • spacetrack_password (str, optional) — Space-Track.org password (or use SPACETRACK_PASSWORD env var)

  • epoch_tolerance_days (float, optional) — For Space-Track cache: how many days TLE epoch can differ from target epoch (default: 4.0 days)

  • enforce_source (str, optional) — Enforce use of specific source without failover. Must be "celestrak", "spacetrack", or None

Notes:
  • Must provide exactly one of: (tle1, tle2), tle, norad_id, or norad_name

  • begin and end parameters are required

  • File paths and URLs are cached locally for performance

  • Space-Track.org credentials can also be provided via .env file

Attributes (read-only):
  • tle_epoch — TLE epoch as Python datetime (extracted from line 1)

  • teme_pv — Position/velocity in TEME frame (PositionVelocityData)

  • itrs_pv — Position/velocity in ITRS frame (PositionVelocityData)

  • gcrs_pv — Position/velocity in GCRS frame (PositionVelocityData)

  • sun_pv — Sun position/velocity in GCRS frame (PositionVelocityData)

  • moon_pv — Moon position/velocity in GCRS frame (PositionVelocityData)

  • timestamp — List of Python datetime objects

  • itrs — ITRS coordinates as astropy SkyCoord

  • gcrs — GCRS coordinates as astropy SkyCoord

  • latitude — Observatory latitude as an astropy Quantity array (degrees), one per timestamp

  • latitude_deg — Observatory latitude as NumPy array (degrees), one per timestamp

  • latitude_rad — Observatory latitude as NumPy array (radians), one per timestamp

  • longitude — Observatory longitude as an astropy Quantity array (degrees), one per timestamp

  • longitude_deg — Observatory longitude as NumPy array (degrees), one per timestamp

  • longitude_rad — Observatory longitude as NumPy array (radians), one per timestamp

  • height — Observatory height as an astropy Quantity array (meters), one per timestamp

  • height_m — Observatory height as raw NumPy array (meters), one per timestamp

  • height_km — Observatory height as raw NumPy array (kilometers), one per timestamp

  • earth — Earth position as astropy SkyCoord

  • sun — Sun position as astropy SkyCoord

  • moon — Moon position as astropy SkyCoord

  • obsgeoloc — Observer geocentric location (alias for GCRS position)

  • obsgeovel — Observer geocentric velocity (alias for GCRS velocity)

  • sun_radius — Sun angular radius as astropy Quantity (degrees)

  • sun_radius_deg — Sun angular radius as NumPy array (degrees)

  • sun_radius_rad — Sun angular radius as NumPy array (radians)

  • moon_radius — Moon angular radius as astropy Quantity (degrees)

  • moon_radius_deg — Moon angular radius as NumPy array (degrees)

  • moon_radius_rad — Moon angular radius as NumPy array (radians)

  • earth_radius — Earth angular radius as astropy Quantity (degrees)

  • earth_radius_deg — Earth angular radius as NumPy array (degrees)

  • earth_radius_rad — Earth angular radius as NumPy array (radians)

  • sun_ra_dec_deg — Sun RA/Dec as Nx2 NumPy array (degrees), cached

  • sun_ra_dec_rad — Sun RA/Dec as Nx2 NumPy array (radians), cached

  • moon_ra_dec_deg — Moon RA/Dec as Nx2 NumPy array (degrees), cached

  • moon_ra_dec_rad — Moon RA/Dec as Nx2 NumPy array (radians), cached

  • earth_ra_dec_deg — Earth RA/Dec as Nx2 NumPy array (degrees), cached

  • earth_ra_dec_rad — Earth RA/Dec as Nx2 NumPy array (radians), cached

  • sun_ra_deg, sun_dec_deg — Sun RA and Dec as separate 1D arrays (degrees)

  • sun_ra_rad, sun_dec_rad — Sun RA and Dec as separate 1D arrays (radians)

  • moon_ra_deg, moon_dec_deg — Moon RA and Dec as separate 1D arrays (degrees)

  • moon_ra_rad, moon_dec_rad — Moon RA and Dec as separate 1D arrays (radians)

  • earth_ra_deg, earth_dec_deg — Earth RA and Dec as separate 1D arrays (degrees)

  • earth_ra_rad, earth_dec_rad — Earth RA and Dec as separate 1D arrays (radians)

Methods:
  • index(time) — Find the index of the closest timestamp to the given datetime

    • time — Python datetime object

    • Returns: int index that can be used to access ephemeris arrays

    • Example: idx = eph.index(datetime(2024, 1, 1, 12, 0, 0)) then position = eph.gcrs_pv.position[idx]

  • get_body_pv(body) — Get position/velocity of a solar system body relative to observer

    • body — Body name (e.g., “Sun”, “Moon”, “Mars”) or NAIF ID as string (e.g., “10”, “301”)

    • Returns: PositionVelocityData with position/velocity in GCRS frame

    • Requires: ensure_planetary_ephemeris() called first

  • get_body(body) — Get SkyCoord for a solar system body with observer location set

    • body — Body name or NAIF ID as string

    • Returns: astropy.coordinates.SkyCoord in GCRS frame with obsgeoloc/obsgeovel set

    • Requires: ensure_planetary_ephemeris() called first

SPICEEphemeris

Spacecraft ephemeris from SPICE SPK (Spacecraft and Planet Kernel) files. Use this for missions that provide trajectory data in SPICE format.

Constructor:

SPICEEphemeris(spk_path, naif_id, begin, end, step_size=60, center_id=399, *, polar_motion=False)

  • spk_path — Path to the SPICE SPK file containing spacecraft trajectory

  • naif_id — NAIF ID of the spacecraft (typically negative, e.g., -82 for Cassini)

  • center_id — NAIF ID of the observer center (default: 399 = Earth)

Attributes (read-only):
  • gcrs_pv — Position/velocity in GCRS frame (PositionVelocityData)

  • itrs_pv — Position/velocity in ITRS frame (PositionVelocityData)

  • sun_pv — Sun position/velocity in GCRS frame (PositionVelocityData)

  • moon_pv — Moon position/velocity in GCRS frame (PositionVelocityData)

  • timestamp — List of Python datetime objects

  • itrs — ITRS coordinates as astropy SkyCoord

  • gcrs — GCRS coordinates as astropy SkyCoord

  • earth — Earth position as astropy SkyCoord

  • sun — Sun position as astropy SkyCoord

  • moon — Moon position as astropy SkyCoord

  • latitude — Geodetic latitude as an astropy Quantity array (degrees), one per timestamp

  • latitude_deg — Geodetic latitude as NumPy array (degrees), one per timestamp

  • latitude_rad — Geodetic latitude as NumPy array (radians), one per timestamp

  • longitude — Geodetic longitude as an astropy Quantity array (degrees), one per timestamp

  • longitude_deg — Geodetic longitude as NumPy array (degrees), one per timestamp

  • longitude_rad — Geodetic longitude as NumPy array (radians), one per timestamp

  • height — Height as an astropy Quantity array (meters), one per timestamp

  • height_m — Height as raw NumPy array (meters), one per timestamp

  • height_km — Height as raw NumPy array (kilometers), one per timestamp

  • obsgeoloc — Observer geocentric location (alias for GCRS position)

  • obsgeovel — Observer geocentric velocity (alias for GCRS velocity)

  • sun_radius — Sun angular radius as astropy Quantity (degrees)

  • sun_radius_deg — Sun angular radius as NumPy array (degrees)

  • sun_radius_rad — Sun angular radius as NumPy array (radians)

  • moon_radius — Moon angular radius as astropy Quantity (degrees)

  • moon_radius_deg — Moon angular radius as NumPy array (degrees)

  • moon_radius_rad — Moon angular radius as NumPy array (radians)

  • earth_radius — Earth angular radius as astropy Quantity (degrees)

  • earth_radius_deg — Earth angular radius as NumPy array (degrees)

  • earth_radius_rad — Earth angular radius as NumPy array (radians)

  • sun_ra_dec_deg — Sun RA/Dec as Nx2 NumPy array (degrees), cached

  • sun_ra_dec_rad — Sun RA/Dec as Nx2 NumPy array (radians), cached

  • moon_ra_dec_deg — Moon RA/Dec as Nx2 NumPy array (degrees), cached

  • moon_ra_dec_rad — Moon RA/Dec as Nx2 NumPy array (radians), cached

  • earth_ra_dec_deg — Earth RA/Dec as Nx2 NumPy array (degrees), cached

  • earth_ra_dec_rad — Earth RA/Dec as Nx2 NumPy array (radians), cached

  • sun_ra_deg, sun_dec_deg — Sun RA and Dec as separate 1D arrays (degrees)

  • sun_ra_rad, sun_dec_rad — Sun RA and Dec as separate 1D arrays (radians)

  • moon_ra_deg, moon_dec_deg — Moon RA and Dec as separate 1D arrays (degrees)

  • moon_ra_rad, moon_dec_rad — Moon RA and Dec as separate 1D arrays (radians)

  • earth_ra_deg, earth_dec_deg — Earth RA and Dec as separate 1D arrays (degrees)

  • earth_ra_rad, earth_dec_rad — Earth RA and Dec as separate 1D arrays (radians)

Methods:
  • index(time) — Find the index of the closest timestamp to the given datetime

    • time — Python datetime object

    • Returns: int index that can be used to access ephemeris arrays

    • Example: idx = eph.index(datetime(2024, 1, 1, 12, 0, 0)) then position = eph.gcrs_pv.position[idx]

  • get_body_pv(body) — Get position/velocity of a solar system body relative to observer

    • body — Body name (e.g., “Sun”, “Moon”, “Mars”) or NAIF ID as string

    • Returns: PositionVelocityData with position/velocity in GCRS frame

  • get_body(body) — Get SkyCoord for a solar system body with observer location set

    • body — Body name or NAIF ID as string

    • Returns: astropy.coordinates.SkyCoord in GCRS frame

GroundEphemeris

Ground-based observatory ephemeris for a fixed point on Earth’s surface.

Constructor:

GroundEphemeris(latitude, longitude, height, begin, end, step_size=60, *, polar_motion=False)

  • latitude — Geodetic latitude in degrees (-90 to 90)

  • longitude — Geodetic longitude in degrees (-180 to 180)

  • height — Altitude in meters above WGS84 ellipsoid

Attributes (read-only):
  • latitude — Observatory latitude as an astropy Quantity array (degrees), one per timestamp

  • longitude — Observatory longitude as an astropy Quantity array (degrees), one per timestamp

  • height — Observatory height as an astropy Quantity array (meters), one per timestamp

  • height_m — Observatory height raw numpy array (meters), one per timestamp

  • gcrs_pv — Position/velocity in GCRS frame (PositionVelocityData)

  • itrs_pv — Position/velocity in ITRS frame (PositionVelocityData)

  • sun_pv — Sun position/velocity in GCRS frame (PositionVelocityData)

  • moon_pv — Moon position/velocity in GCRS frame (PositionVelocityData)

  • timestamp — List of Python datetime objects

  • itrs — ITRS coordinates as astropy SkyCoord

  • gcrs — GCRS coordinates as astropy SkyCoord

  • earth — Earth position as astropy SkyCoord

  • sun — Sun position as astropy SkyCoord

  • moon — Moon position as astropy SkyCoord

  • latitude — Geodetic latitude as an astropy Quantity array (degrees), one per timestamp

  • latitude_deg — Geodetic latitude as NumPy array (degrees), one per timestamp

  • latitude_rad — Geodetic latitude as NumPy array (radians), one per timestamp

  • longitude — Geodetic longitude as an astropy Quantity array (degrees), one per timestamp

  • longitude_deg — Geodetic longitude as NumPy array (degrees), one per timestamp

  • longitude_rad — Geodetic longitude as NumPy array (radians), one per timestamp

  • height — Height as an astropy Quantity array (meters), one per timestamp

  • height_m — Height as raw NumPy array (meters), one per timestamp

  • height_km — Height as raw NumPy array (kilometers), one per timestamp

  • obsgeoloc — Observer geocentric location (alias for GCRS position)

  • obsgeovel — Observer geocentric velocity (alias for GCRS velocity)

  • sun_radius — Sun angular radius as astropy Quantity (degrees)

  • sun_radius_deg — Sun angular radius as NumPy array (degrees)

  • sun_radius_rad — Sun angular radius as NumPy array (radians)

  • moon_radius — Moon angular radius as astropy Quantity (degrees)

  • moon_radius_deg — Moon angular radius as NumPy array (degrees)

  • moon_radius_rad — Moon angular radius as NumPy array (radians)

  • earth_radius — Earth angular radius as astropy Quantity (degrees)

  • earth_radius_deg — Earth angular radius as NumPy array (degrees)

  • earth_radius_rad — Earth angular radius as NumPy array (radians)

  • sun_ra_dec_deg — Sun RA/Dec as Nx2 NumPy array (degrees), cached

  • sun_ra_dec_rad — Sun RA/Dec as Nx2 NumPy array (radians), cached

  • moon_ra_dec_deg — Moon RA/Dec as Nx2 NumPy array (degrees), cached

  • moon_ra_dec_rad — Moon RA/Dec as Nx2 NumPy array (radians), cached

  • earth_ra_dec_deg — Earth RA/Dec as Nx2 NumPy array (degrees), cached

  • earth_ra_dec_rad — Earth RA/Dec as Nx2 NumPy array (radians), cached

  • sun_ra_deg, sun_dec_deg — Sun RA and Dec as separate 1D arrays (degrees)

  • sun_ra_rad, sun_dec_rad — Sun RA and Dec as separate 1D arrays (radians)

  • moon_ra_deg, moon_dec_deg — Moon RA and Dec as separate 1D arrays (degrees)

  • moon_ra_rad, moon_dec_rad — Moon RA and Dec as separate 1D arrays (radians)

  • earth_ra_deg, earth_dec_deg — Earth RA and Dec as separate 1D arrays (degrees)

  • earth_ra_rad, earth_dec_rad — Earth RA and Dec as separate 1D arrays (radians)

Methods:
  • index(time) — Find the index of the closest timestamp to the given datetime

    • time — Python datetime object

    • Returns: int index that can be used to access ephemeris arrays

    • Example: idx = eph.index(datetime(2024, 1, 1, 12, 0, 0)) then sun_position = eph.sun_pv.position[idx]

  • get_body_pv(body) — Get position/velocity of a solar system body relative to observer

    • body — Body name (e.g., “Sun”, “Moon”, “Mars”) or NAIF ID as string

    • Returns: PositionVelocityData with position/velocity in GCRS frame

    • Requires: ensure_planetary_ephemeris() called first

  • get_body(body) — Get SkyCoord for a solar system body with observer location set

    • body — Body name or NAIF ID as string

    • Returns: astropy.coordinates.SkyCoord in GCRS frame

OEMEphemeris

Load and interpolate CCSDS Orbit Ephemeris Message (OEM) files for spacecraft ephemeris.

The OEM file must use a GCRS-compatible reference frame such as J2000, EME2000, GCRF, or ICRF. Earth-fixed frames (e.g., ITRF) are not supported and will raise a ValueError.

Constructor:

OEMEphemeris(oem_file_path, begin, end, step_size=60, *, polar_motion=False)

  • oem_file_path — Path to CCSDS OEM file (.oem)

  • begin — Start time for ephemeris (Python datetime)

  • end — End time for ephemeris (Python datetime)

  • step_size — Time step in seconds for interpolated ephemeris (default: 60)

  • polar_motion — Enable polar motion corrections (default: False)

Raises:
  • ValueError — If reference frame is missing or incompatible with GCRS

Attributes (read-only):
  • oem_pv — Original OEM state vectors (PositionVelocityData) without interpolation

  • oem_timestamp — Original OEM timestamps (list of datetime) without interpolation

  • gcrs_pv — Interpolated position/velocity in GCRS frame (PositionVelocityData)

  • itrs_pv — Position/velocity in ITRS frame (PositionVelocityData)

  • sun_pv — Sun position/velocity in GCRS frame (PositionVelocityData)

  • moon_pv — Moon position/velocity in GCRS frame (PositionVelocityData)

  • timestamp — List of Python datetime objects for interpolated ephemeris

  • itrs — ITRS coordinates as astropy SkyCoord

  • gcrs — GCRS coordinates as astropy SkyCoord

  • earth — Earth position as astropy SkyCoord

  • sun — Sun position as astropy SkyCoord

  • moon — Moon position as astropy SkyCoord

  • latitude — Geodetic latitude as an astropy Quantity array (degrees), one per timestamp

  • latitude_deg — Geodetic latitude as NumPy array (degrees), one per timestamp

  • latitude_rad — Geodetic latitude as NumPy array (radians), one per timestamp

  • longitude — Geodetic longitude as an astropy Quantity array (degrees), one per timestamp

  • longitude_deg — Geodetic longitude as NumPy array (degrees), one per timestamp

  • longitude_rad — Geodetic longitude as NumPy array (radians), one per timestamp

  • height — Height as an astropy Quantity array (meters), one per timestamp

  • height_m — Height as raw NumPy array (meters), one per timestamp

  • height_km — Height as raw NumPy array (kilometers), one per timestamp

  • obsgeoloc — Observer geocentric location (alias for GCRS position)

  • obsgeovel — Observer geocentric velocity (alias for GCRS velocity)

  • sun_radius — Sun angular radius as astropy Quantity (degrees)

  • sun_radius_deg — Sun angular radius as NumPy array (degrees)

  • sun_radius_rad — Sun angular radius as NumPy array (radians)

  • moon_radius — Moon angular radius as astropy Quantity (degrees)

  • moon_radius_deg — Moon angular radius as NumPy array (degrees)

  • moon_radius_rad — Moon angular radius as NumPy array (radians)

  • earth_radius — Earth angular radius as astropy Quantity (degrees)

  • earth_radius_deg — Earth angular radius as NumPy array (degrees)

  • earth_radius_rad — Earth angular radius as NumPy array (radians)

  • sun_ra_dec_deg — Sun RA/Dec as Nx2 NumPy array (degrees), cached

  • sun_ra_dec_rad — Sun RA/Dec as Nx2 NumPy array (radians), cached

  • moon_ra_dec_deg — Moon RA/Dec as Nx2 NumPy array (degrees), cached

  • moon_ra_dec_rad — Moon RA/Dec as Nx2 NumPy array (radians), cached

  • earth_ra_dec_deg — Earth RA/Dec as Nx2 NumPy array (degrees), cached

  • earth_ra_dec_rad — Earth RA/Dec as Nx2 NumPy array (radians), cached

  • sun_ra_deg, sun_dec_deg — Sun RA and Dec as separate 1D arrays (degrees)

  • sun_ra_rad, sun_dec_rad — Sun RA and Dec as separate 1D arrays (radians)

  • moon_ra_deg, moon_dec_deg — Moon RA and Dec as separate 1D arrays (degrees)

  • moon_ra_rad, moon_dec_rad — Moon RA and Dec as separate 1D arrays (radians)

  • earth_ra_deg, earth_dec_deg — Earth RA and Dec as separate 1D arrays (degrees)

  • earth_ra_rad, earth_dec_rad — Earth RA and Dec as separate 1D arrays (radians)

Methods:
  • index(time) — Find the index of the closest timestamp to the given datetime

    • time — Python datetime object

    • Returns: int index that can be used to access ephemeris arrays

    • Example: idx = eph.index(datetime(2032, 7, 1, 12, 0, 0)) then position = eph.gcrs_pv.position[idx]

  • get_body_pv(body) — Get position/velocity of a solar system body relative to observer

    • body — Body name (e.g., “Sun”, “Moon”, “Mars”) or NAIF ID as string

    • Returns: PositionVelocityData with position/velocity in GCRS frame

    • Requires: ensure_planetary_ephemeris() called first

  • get_body(body) — Get SkyCoord for a solar system body with observer location set

    • body — Body name or NAIF ID as string

    • Returns: astropy.coordinates.SkyCoord in GCRS frame

FileEphemeris

Load pre-computed state vectors from a simulator output file and resample to a uniform output grid via Hermite interpolation. Supports offset-based simulator output, simple CSV/TSV layouts, and any file where data rows contain seven whitespace-separated values: <time>  <x>  <y>  <z>  <vx>  <vy>  <vz>.

The coordinate frame, reference epoch, and units are auto-detected from header key-value pairs and may be overridden via constructor parameters.

Constructor:

FileEphemeris(file_path, begin, end, step_size=60, *, polar_motion=False, position_unit=None, velocity_unit=None, frame=None, epoch=None, time_format=None)

  • file_path — Path to the ephemeris file

  • begin — Start time for the output grid (Python datetime, UTC)

  • end — End time for the output grid (Python datetime, UTC)

  • step_size — Output time step in seconds (default: 60)

  • polar_motion — Apply polar motion correction (default: False)

  • position_unit — Override detected position unit: "km" (default), "m", "cm"

  • velocity_unit — Override detected velocity unit: "km/s", "m/s", "cm/s". When neither given nor stated in the file, it follows the position unit (position_unit="m" means velocities in m/s)

  • frame — Override detected coordinate frame. GCRS-compatible: "J2000", "EME2000", "GCRF", "GCRS", "ICRF". Earth-fixed: "ITRS", "ECEF", "ECF", "FIXED", "TERRESTRIAL"

  • epoch — Reference epoch (T0) for numeric time offsets; overrides any epoch found in the file header

  • time_format — How to interpret the time column: "auto" (default), "seconds", "days", "iso8601"

Raises:
  • IOError — If the file cannot be opened or read

  • ValueError — If no state vectors are found, the requested time range exceeds the file data range, units are unrecognised, or the frame is unsupported

Alternate constructor (in-memory data):

FileEphemeris.from_arrays(times, positions, velocities=None, begin=None, end=None, step_size=60, *, polar_motion=False, position_unit="km", velocity_unit=None, frame="J2000")

  • times — Strictly increasing sample times: sequence of datetimes (naive = UTC) or NumPy datetime64 array

  • positions, velocities — (N, 3) array-likes in position_unit / velocity_unit (velocity_unit defaults to the position unit per second)

  • begin, end — Output grid bounds (default: first / last sample time)

  • Remaining arguments as for the file constructor; file_path is None on the result

  • Raises ValueError for wrong shapes, mismatched lengths, fewer than two samples, non-finite values, non-increasing times, or a range outside the samples

Attributes (read-only):
  • file_path — Path to the source file (None when built with from_arrays)

  • source_frame — Coordinate frame as detected/specified

  • source_position_unit — Position unit as detected/specified (before km conversion)

  • source_velocity_unit — Velocity unit as detected/specified (before km/s conversion)

  • file_pv — Raw state vectors from the file (km, km/s) before resampling (PositionVelocityData)

  • file_timestamp — Raw timestamps from the file before resampling (list of datetime)

  • gcrs_pv — Interpolated position/velocity in GCRS frame (PositionVelocityData)

  • itrs_pv — Position/velocity in ITRS frame (PositionVelocityData)

  • sun_pv, moon_pv — Sun/Moon position/velocity in GCRS frame (PositionVelocityData)

  • timestamp — Output grid timestamps (NumPy datetime64 array)

  • gcrs, itrs, earth, sun, moon — astropy SkyCoord objects

  • latitude_deg, longitude_deg, height_m — Geodetic coordinates

  • All other standard Ephemeris properties (angular radii, RA/Dec arrays, etc.)

Methods:
  • index(time) — Find the index of the closest output-grid timestamp to the given datetime

  • get_body_pv(body), get_body(body) — Solar system body position/velocity and SkyCoord

  • moon_illumination(time_indices=None) — Moon illumination fraction (0–1) as seen from spacecraft

  • radec_to_altaz(ra_deg, dec_deg, time_indices=None) — Convert RA/Dec to Alt/Az

  • calculate_airmass(ra_deg, dec_deg, time_indices=None) — Astronomical airmass

See Using FileEphemeris for worked examples.

ParquetEphemeris

Load pre-computed state vectors from a Parquet file via DuckDB and resample to a uniform output grid via Hermite interpolation. Supports local files, globs, and cloud object stores (S3, DigitalOcean Spaces, GCS, R2, HTTPS).

Reads with the duckdb Python package. Without it, local files, globs and directories are read with pyarrow; remote sources and where_clause need duckdb.

Constructor:

ParquetEphemeris(source, begin=None, end=None, step_size=60, *, polar_motion=False, time_col=None, pos_cols=None, vel_cols=None, position_unit=None, velocity_unit=None, frame=None, s3_endpoint=None, s3_region=None, where_clause=None)

  • source — Path or URI to the Parquet file. Supports local paths and globs, s3://, gcs://, r2://, http(s)://

  • begin — Start time for the output grid (Python datetime, UTC). Default: the first row of the data

  • end — End time for the output grid (Python datetime, UTC). Default: the last row of the data

  • step_size — Output time step in seconds (default: 60)

  • polar_motion — Apply polar motion correction (default: False)

  • time_col — Name of the timestamp column (default: "time")

  • pos_cols — Names of the three position columns (default: ("x", "y", "z"))

  • vel_cols — Names of the three velocity columns (default: ("vx", "vy", "vz"))

  • position_unit — Position unit in the source: "km" (default), "m", "cm"

  • velocity_unit — Velocity unit in the source: "km/s" (default), "m/s", "cm/s"

  • frame — Coordinate frame of the source. Default "GCRS". GCRS-compatible: "J2000", "EME2000", "GCRF", "GCRS", "ICRF". Earth-fixed: "ITRS", "ECEF", "ECF", "FIXED", "TERRESTRIAL"

  • s3_endpoint — Custom S3 endpoint host for S3-compatible services (e.g. "nyc3.digitaloceanspaces.com" for DigitalOcean Spaces)

  • s3_region — Override S3 region. Falls back to AWS_REGION env var.

  • where_clause — Extra SQL WHERE predicate to apply to the Parquet (e.g. "sat_id = 42"). Combined via AND with the time-range filter.

Authentication:

Cloud access uses DuckDB’s credential_chain SECRET, which transparently picks up the standard AWS environment variables: AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION, AWS_SESSION_TOKEN.

Raises:
  • ImportError — If neither duckdb nor pyarrow is installed, or the request needs duckdb (remote source, where_clause) and it is missing

  • ValueError — If column names are not safe identifiers, the requested time range exceeds the Parquet’s data range (with a 1 hour margin), units are unrecognised, or the frame is unsupported

Attributes (read-only):
  • source — Path or URI for the Parquet data

  • file_path — Alias for source (matches FileEphemeris for consistency)

  • source_frame — Coordinate frame as specified

  • source_position_unit — Position unit as specified (before km conversion)

  • source_velocity_unit — Velocity unit as specified (before km/s conversion)

  • file_pv — Raw state vectors loaded from the Parquet (km, km/s) before resampling (PositionVelocityData)

  • file_timestamp — Raw timestamps from the Parquet before resampling (list of datetime)

  • gcrs_pv — Interpolated position/velocity in GCRS frame (PositionVelocityData)

  • itrs_pv — Position/velocity in ITRS frame (PositionVelocityData)

  • sun_pv, moon_pv — Sun/Moon position/velocity in GCRS frame (PositionVelocityData)

  • timestamp — Output grid timestamps (NumPy datetime64 array)

  • gcrs, itrs, earth, sun, moon — astropy SkyCoord objects

  • latitude_deg, longitude_deg, height_m — Geodetic coordinates

  • All other standard Ephemeris properties (angular radii, RA/Dec arrays, etc.)

Methods:
  • index(time) — Find the index of the closest output-grid timestamp to the given datetime

  • get_body_pv(body), get_body(body) — Solar system body position/velocity and SkyCoord

  • moon_illumination(time_indices=None) — Moon illumination fraction (0–1) as seen from spacecraft

  • radec_to_altaz(ra_deg, dec_deg, time_indices=None) — Convert RA/Dec to Alt/Az

  • calculate_airmass(ra_deg, dec_deg, time_indices=None) — Astronomical airmass

See Using ParquetEphemeris for worked examples.

Constraint

Evaluate astronomical observation constraints against ephemeris data.

Static Methods:
  • Constraint.sun_proximity(min_angle, max_angle=None) — Create Sun proximity constraint

  • Constraint.moon_proximity(min_angle, max_angle=None, from_limb=False) — Create Moon proximity constraint (from_limb=True measures from the Moon’s limb)

  • Constraint.earth_limb(min_angle, max_angle=None) — Create Earth limb avoidance constraint * Constraint.earth_limb(min_angle, max_angle=None, include_refraction=False, horizon_dip=False) — Create Earth limb avoidance constraint

  • Constraint.body_proximity(body, min_angle, max_angle=None) — Create solar system body proximity constraint

  • Constraint.eclipse(umbra_only=True) — Create eclipse constraint

  • Constraint.and_(*constraints) — Combine constraints with logical AND

  • Constraint.or_(*constraints) — Combine constraints with logical OR

  • Constraint.xor_(*constraints) — Combine constraints with logical XOR (violation when exactly one sub-constraint is violated)

  • Constraint.at_least(min_violated, constraints) — Threshold combinator (violation when at least min_violated sub-constraints are violated)

  • Constraint.not_(constraint) — Negate a constraint with logical NOT

  • Constraint.boresight_offset(constraint, roll_deg=0.0, roll_clockwise=False, roll_reference="north", pitch_deg=0.0, yaw_deg=0.0) — Wrap a constraint with fixed boresight Euler-angle offsets - roll_deg — Fixed instrument roll offset (degrees) relative to the spacecraft frame. Default 0.0. Spacecraft roll at observation time is a separate concept applied via target_roll on evaluation methods. - roll_reference — Roll-zero reference axis. Default is "north" (celestial-north-projected +Z zero-roll). Use "sun" for Sun-projected +Z zero-roll when needed.

  • Constraint.from_json(json_str) — Create constraint from JSON configuration

Methods:
  • evaluate(ephemeris, target_ra, target_dec, times=None, indices=None) — Evaluate constraint against ephemeris data

    • ephemeris — Any Ephemeris object (TLEEphemeris, SPICEEphemeris, GroundEphemeris, OEMEphemeris, FileEphemeris, or ParquetEphemeris)

    • target_ra — Target right ascension in degrees (ICRS/J2000)

    • target_dec — Target declination in degrees (ICRS/J2000)

    • times — Optional: specific datetime(s) to evaluate (must exist in ephemeris)

    • indices — Optional: specific time index/indices to evaluate

    • Returns: ConstraintResult object

  • evaluate_batch(ephemeris, target_ras, target_decs, times=None, indices=None, target_rolls=None) — Convenience batch API returning one ConstraintResult per target

    • ephemeris — Any Ephemeris object (TLEEphemeris, SPICEEphemeris, GroundEphemeris, OEMEphemeris, FileEphemeris, or ParquetEphemeris)

    • target_ras — List of target right ascensions in degrees (ICRS/J2000)

    • target_decs — List of target declinations in degrees (ICRS/J2000)

    • times — Optional: specific datetime(s) to evaluate (must exist in ephemeris)

    • indices — Optional: specific time index/indices to evaluate

    • target_rolls — Optional: per-target spacecraft roll angles in degrees, one value per target. Each entry may be None to evaluate that target without a fixed spacecraft roll (default: None for all targets)

    • Returns: list of ConstraintResult objects, one per target

    • Best when you want the same per-target summary shape as evaluate() without writing the loop yourself

  • in_constraint_batch(ephemeris, target_ras, target_decs, times=None, indices=None, target_rolls=None) — [Recommended] Vectorized batch evaluation for multiple targets

    • ephemeris — Any Ephemeris object (TLEEphemeris, SPICEEphemeris, GroundEphemeris, OEMEphemeris, FileEphemeris, or ParquetEphemeris)

    • target_ras — List/array of target right ascensions in degrees (ICRS/J2000)

    • target_decs — List/array of target declinations in degrees (ICRS/J2000)

    • times — Optional: specific datetime(s) to evaluate (must exist in ephemeris)

    • indices — Optional: specific time index/indices to evaluate

    • target_rolls — Optional: per-target spacecraft roll angles in degrees, one value per target. Each entry may be None to evaluate that target without a fixed spacecraft roll. When an entry is None and the constraint has boresight offsets with non-zero pitch/yaw, evaluates the target as violated only if it violates at every possible roll angle (default: None for all targets)

    • Returns: 2D NumPy boolean array of shape (n_targets, n_times) where True indicates constraint violation

    • Performance: 3-50x faster than calling evaluate() in a loop

    • Optimized: Uses vectorized operations for batch RA/Dec conversion and constraint evaluation

    • All constraint types supported: Sun/Moon proximity, Earth limb, Eclipse, Body proximity, boresight offsets, and logical combinators (AND, OR, XOR, AT_LEAST, NOT)

  • in_constraint_elementwise(ephemeris, target_ras, target_decs, times=None, target_rolls=None, n_roll_samples=DEFAULT_N_ROLL_SAMPLES, apparent=False, roll_offsets=None) — Paired evaluation: element i is target (target_ras[i], target_decs[i]) at times[i]

    • Equals the diagonal of in_constraint_batch over all targets and times, at O(N) cost (no N x N grid)

    • times — One datetime per element; may be unsorted, duplicated and between ephemeris samples (interpolated, as in in_constraint), but must lie within the ephemeris range. None pairs element i with ephemeris timestamp i

    • target_rolls — Optional per-element roll (degrees); None entries sweep rolls for roll-dependent constraints, as in in_constraint_batch

    • roll_offsets — Optional per-element roll in degrees from the element’s nominal roll (body +Y toward the Sun), in place of target_rolls

    • Returns: 1D NumPy boolean array of shape (N,), True where the constraint is violated

  • violated_count(ephemeris, target_ras, target_decs, times=None, indices=None, target_rolls=None, n_roll_samples=DEFAULT_N_ROLL_SAMPLES, apparent=False, fraction=False) — Number (or, with fraction=True, fraction) of the times at which each target is in-constraint: the row sums of in_constraint_batch without the (n_targets, n_times) mask

  • visibility_windows(ephemeris, target_ras, target_decs, times=None, indices=None, target_rolls=None, n_roll_samples=DEFAULT_N_ROLL_SAMPLES, apparent=False) — Per target, an (n_windows, 2) integer array of the first and last time index of each run of times at which it is not in-constraint, again without the mask

  • evaluate_grid(ephemeris, target_ras, target_decs, times=None, indices=None, target_rolls=None, n_roll_samples=DEFAULT_N_ROLL_SAMPLES, apparent=False) — As evaluate_batch, returning the whole grid as (n_targets, n_times) arrays instead of one result per target

    • Returns: GridResult object

  • evaluate_elementwise(ephemeris, target_ras, target_decs, times=None, target_rolls=None, n_roll_samples=DEFAULT_N_ROLL_SAMPLES, apparent=False, roll_offsets=None) — Same pairing as in_constraint_elementwise, plus per-element values

    • Returns: ElementwiseResult object

  • in_constraint(time, ephemeris, target_ra, target_dec, target_roll=None, n_roll_samples=DEFAULT_N_ROLL_SAMPLES, apparent=False) — Check if target is in-constraint at one or more times

    • time — Python datetime, list of datetimes or NumPy datetime64 array, within the ephemeris range

    • apparent — Measure apparent rather than geometric angles (see Geometric and Apparent Angles)

    • Returns: bool (True if constraint is violated / target is blocked, False if satisfied)

  • instantaneous_field_of_regard(ephemeris, time=None, index=None, n_points=DEFAULT_N_POINTS, n_roll_samples=DEFAULT_N_ROLL_SAMPLES, target_roll=None, apparent=False) — Compute instantaneous visible sky solid angle. When target_roll is not specified, sweeps n_roll_samples spacecraft roll angles for boresight-offset constraints with non-zero pitch/yaw, giving the total accessible sky over all roll states.

    • ephemeris — Any Ephemeris object (TLEEphemeris, SPICEEphemeris, GroundEphemeris, OEMEphemeris, FileEphemeris, or ParquetEphemeris)

    • time — Optional datetime to evaluate (must exist in ephemeris)

    • index — Optional ephemeris index to evaluate

    • n_points — Number of sky samples (Fibonacci sphere integration, default DEFAULT_N_POINTS)

    • target_roll — Spacecraft roll angle (degrees) to evaluate at. When None (default), sweeps all roll angles for boresight-offset FoR.

    • n_roll_samples — Spacecraft roll angles to sweep when target_roll is None and pitch/yaw offsets are present (default DEFAULT_N_ROLL_SAMPLES = 360, i.e. 1° resolution). Can be reduced (e.g., 72 for 5° resolution) for faster evaluation. Ignored otherwise.

    • Returns: float steradians in [0, 4π]

    • Requirement: exactly one of time or index must be provided

    • Semantics: constraints are violated when True; this method integrates visible sky where constraint is False

  • evaluate_moving_body(ephemeris, target_ras=None, target_decs=None, times=None, body=None, use_horizons=False, spice_kernel=None, apparent=False) — Evaluate against a body whose RA/Dec varies over time (comet, asteroid, planet), instead of a single fixed sky position

    • Provide either explicit target_ras/target_decs (optionally with times), or a body name/NAIF ID to look up via SPICE (or JPL Horizons if use_horizons=True)

    • Returns: MovingBodyResult object

  • to_json() — Get constraint configuration as JSON string

  • to_dict() — Get constraint configuration as Python dictionary

ConstraintResult

Result of constraint evaluation containing violation information.

Attributes (read-only):
  • violations — List of ConstraintViolation objects

  • all_satisfied — Boolean indicating if constraint was satisfied for entire time range

  • constraint_name — String name/description of the constraint

  • timestamp — NumPy array of Python datetime objects (optimized with caching)

  • constraint_array — NumPy boolean array where True means constraint violated / target blocked (optimized with caching)

  • constraint_values — dict[str, numpy.ndarray] (read-only float arrays, built once) of named continuous values computed during evaluation (e.g. sun_angle_deg, the angle a SunConstraint thresholds), one array per key, aligned with timestamp. Empty for constraints with no natural scalar (e.g. SAAConstraint, polygon-mode BodyConstraint/BrightStarConstraint). Combinators (AND/OR/XOR/AT_LEAST) namespace each child’s keys under a short type-tag prefix (e.g. sun.sun_angle_deg, moon.moon_angle_deg); a repeated type gets a numeric suffix (body_2.body_angle_deg, …). See Constraint Values in the Constraints API reference for the full key-name table.

  • cause_value_keys — dict[str, list[str]] mapping a VisibilityWindow.start_cause/ end_cause tag to the constraint_values key(s) it corresponds to. Needed because the two namespaces use different conventions — cause tags are flat and stay stable regardless of nesting depth, while constraint_values keys are hierarchical and encode the full nesting path — so a cause tag’s value key(s) can’t be found by string-matching a prefix once a constraint type is nested and repeated. See Visibility Window Causes for details.

  • visibility — List of VisibilityWindow objects for contiguous satisfied periods

Methods:
  • total_violation_duration() — Get total duration of violations in seconds

  • in_constraint(time) — Check if constraint is violated at a given time

    • time — Python datetime object (must exist in result timestamps)

    • Returns: bool (True if violated / target blocked, False if satisfied)

MovingBodyResult

Result of evaluate_moving_body(): the same evaluation information as ConstraintResult, plus the moving body’s per-timestamp sky position.

Attributes (read-only):
  • violations, all_satisfied, constraint_name, timestamp, constraint_array, constraint_values, cause_value_keys, visibility — same meaning as on ConstraintResult (see above)

  • ras — NumPy array of the body’s right ascension in degrees at each timestamp

  • decs — NumPy array of the body’s declination in degrees at each timestamp

GridResult

Result of evaluate_grid(): every target at every time.

Attributes (read-only):
  • constraint_array — (n_targets, n_times) NumPy bool array, True where the constraint is violated

  • visibility_flags — the inverse of constraint_array

  • constraint_values — dict[str, numpy.ndarray] of (n_targets, n_times) float arrays

  • component_violated — dict[str, numpy.ndarray] of (n_targets, n_times) bool arrays keyed by cause tag

  • component_order — the cause tags in the order the rules were written

  • first_violated — (n_targets, n_times) NumPy str array: the first rule in that order violated where the constraint is, "" elsewhere

  • cause_value_keys, constraint_name, shape

  • timestamp — (n_times,) array of datetimes; ras, decs — (n_targets,) arrays

Methods:
  • target(index) — The ConstraintResult of one target, built on demand

ElementwiseResult

Result of evaluate_elementwise(): one entry per input element, in input order.

Attributes (read-only):
  • constraint_array — (N,) NumPy bool array, True where the constraint is violated

  • visibility_flags — (N,) NumPy bool array, the inverse of constraint_array

  • constraint_values — dict[str, numpy.ndarray] of (N,) float arrays with exactly the keys evaluate()/evaluate_batch() report for the same constraint (including combinator namespacing such as sun.sun_angle_deg)

  • component_violated — dict[str, numpy.ndarray] of (N,) per-leaf violation masks keyed by cause tag (sun, not.moon, …)

  • component_order — the cause tags in the order the rules were written

  • first_violated — (N,) NumPy str array: the first rule in that order violated where the constraint is, "" elsewhere

  • cause_value_keys — cause tag to constraint_values key(s), as on ConstraintResult

  • timestamp — (N,) NumPy object array of the UTC datetime each element was evaluated at

  • ras, decs — (N,) NumPy float arrays of the input coordinates

  • constraint_name — String name/description of the constraint

ConstraintViolation

Information about a specific constraint violation time window.

Attributes (read-only):
  • start_time — Start time of violation window (ISO 8601 string)

  • end_time — End time of violation window (ISO 8601 string)

  • max_severity — Maximum severity of violation (0.0 = just violated, 1.0+ = severe)

  • description — Human-readable description of the violation

VisibilityWindow

Time window when observation target is not constrained (visible).

Attributes (read-only):
  • start_time — Start time of visibility window (Python datetime)

  • end_time — End time of visibility window (Python datetime)

  • duration_seconds — Duration of the window in seconds (computed property)

  • start_cause — list[str] | None: tag(s) of the leaf constraint(s) whose own pass/fail state changed between the sample before this window and its first sample. None at the start of the evaluated range (no prior sample to compare against).

  • end_cause — list[str] | None: tag(s) of the leaf constraint(s) whose own pass/fail state changed between this window’s last sample and the one after it. None at the end of the evaluated range. Under NOT, the tag reports the wrapped leaf’s own (un-negated) transition, prefixed not. (e.g. not.sun) so it is never mistaken for its non-negated counterpart.

See Visibility Window Causes in the Constraints API reference for the full semantics, including why start_cause/end_cause tags cannot be cross-referenced against ConstraintResult.constraint_values keys by string prefix — use ConstraintResult.cause_value_keys instead.

PositionVelocityData

Container for position and velocity data returned by ephemeris calculations.

Attributes (read-only):
  • position — NumPy array of positions (N × 3), in km

  • velocity — NumPy array of velocities (N × 3), in km/s

  • position_unit — String “km”

  • velocity_unit — String “km/s”

Functions

Planetary Ephemeris Management

  • init_planetary_ephemeris(py_path) — Initialize an already-downloaded planetary SPK file.

  • download_planetary_ephemeris(url, dest) — Download a planetary SPK file from a URL.

  • ensure_planetary_ephemeris(py_path=None, download_if_missing=True, spk_url=None) — Download (if missing) and initialize planetary SPK lazily. Uses default de440s.bsp if no path provided.

  • is_planetary_ephemeris_initialized() — Check if planetary ephemeris is initialized. Returns bool.

Time System Conversions

  • get_tai_utc_offset(py_datetime) — Get TAI-UTC offset (leap seconds) for a given datetime. Returns Optional[float] (seconds).

  • get_ut1_utc_offset(py_datetime) — Get UT1-UTC offset for a given datetime. Returns float (seconds).

  • is_ut1_available() — Check if UT1 data is available. Returns bool.

  • init_ut1_provider() — Initialize UT1 provider. Returns bool indicating success.

Earth Orientation Parameters (EOP)

  • get_polar_motion(py_datetime) — Get polar motion parameters (x_p, y_p) for a given datetime. Returns Tuple[float, float] (arcseconds).

  • is_eop_available() — Check if EOP data is available. Returns bool.

  • init_eop_provider() — Initialize EOP provider. Returns bool indicating success.

  • get_eop_provenance() — Return source URL, SHA-256, load source, and stale status for the exact EOP2 data loaded by the UT1 and polar-motion providers.

Cache Management

  • get_cache_dir() — Get the path to the cache directory used by rust_ephem. Returns str.

Orbital Element Conversion

  • osculating_elements_from_state(position_km, velocity_km_s, mu_km3_s2=WGS72_EARTH_MU_KM3_S2) — Derive instantaneous classical osculating elements from one inertial Cartesian state.

    The position and velocity must describe the same epoch in the same central-body-centered inertial frame. Position is in kilometers, velocity is in kilometers per second, and mu_km3_s2 is in km^3/s^2. Returned angles are normalized to the range [0, 360) degrees. The returned Pydantic OsculatingElements model contains:

    • semimajor_axis_km

    • eccentricity

    • inclination_deg

    • right_ascension_of_ascending_node_deg

    • argument_of_periapsis_deg

    • true_anomaly_deg

    • gravitational_parameter_km3_s2

    Access fields as attributes and use model_dump() or model_dump_json() when serializing the result.

    The epoch and frame are properties of the supplied state and are not inferred by this function. Store them alongside serialized elements. For a GCRS state, for example, the returned orientation angles are relative to the GCRS axes.

    These are instantaneous two-body osculating elements. They are not interchangeable with the mean elements in a TLE, and a later state should not be generated by changing only the anomaly under a perturbed propagator.

    For singular classical-element cases, undefined angles use stable conventions: circular inclined states report argument of periapsis as zero and true anomaly as argument of latitude; eccentric equatorial states report right ascension of the ascending node as zero and argument of periapsis as longitude of periapsis; circular equatorial states report both undefined orientation angles as zero and true anomaly as true longitude.

TLE Fetching

  • fetch_tle(*, tle=None, norad_id=None, norad_name=None, epoch=None, spacetrack_username=None, spacetrack_password=None, epoch_tolerance_days=None, enforce_source=None) — Fetch a TLE from various sources.

    This function provides a unified interface for retrieving TLE data from local files, URLs, Celestrak, or Space-Track.org. Returns a TLERecord object containing the TLE data and metadata.

    Parameters:
    • tle (str, optional) — Path to TLE file or URL to download TLE from

    • norad_id (int, optional) — NORAD catalog ID to fetch TLE. If Space-Track credentials are available, Space-Track is tried first with failover to Celestrak.

    • norad_name (str, optional) — Satellite name to fetch TLE from Celestrak

    • epoch (datetime, optional) — Target epoch for Space-Track queries. If not specified, current time is used. Space-Track will fetch the TLE with epoch closest to this time.

    • spacetrack_username (str, optional) — Space-Track.org username (or use SPACETRACK_USERNAME env var)

    • spacetrack_password (str, optional) — Space-Track.org password (or use SPACETRACK_PASSWORD env var)

    • epoch_tolerance_days (float, optional) — For Space-Track cache: how many days TLE epoch can differ from target epoch (default: 4.0 days)

    • enforce_source (str, optional) — Enforce use of specific source without failover. Must be "celestrak", "spacetrack", or None (default behavior with failover)

    Returns:

    TLERecord — A Pydantic model containing the TLE data and metadata

    Raises:

    ValueError — If no valid TLE source is specified or fetching fails

    Examples:

    import rust_ephem
    
    # Fetch from Celestrak by NORAD ID
    tle = rust_ephem.fetch_tle(norad_id=25544)  # ISS
    print(tle.name)
    print(tle.line1)
    print(tle.line2)
    
    # Fetch from file
    tle = rust_ephem.fetch_tle(tle="path/to/satellite.tle")
    
    # Fetch from URL
    tle = rust_ephem.fetch_tle(tle="https://celestrak.org/NORAD/elements/gp.php?CATNR=25544")
    
    # Fetch from Space-Track with explicit credentials
    from datetime import datetime, timezone
    tle = rust_ephem.fetch_tle(
        norad_id=25544,
        spacetrack_username="your_username",
        spacetrack_password="your_password",
        epoch=datetime(2020, 1, 1, tzinfo=timezone.utc)
    )
    
    # Use TLERecord with TLEEphemeris
    ephem = rust_ephem.TLEEphemeris(
        tle=tle,  # Pass TLERecord directly
        begin=datetime(2024, 1, 1, tzinfo=timezone.utc),
        end=datetime(2024, 1, 2, tzinfo=timezone.utc),
        step_size=60
    )
    
    Notes:
    • Must provide exactly one of: tle, norad_id, or norad_name

    • File paths and URLs are cached locally for improved performance

    • Space-Track.org requires free account registration at https://www.space-track.org

    • Credentials can be provided via:

      1. Explicit parameters: spacetrack_username and spacetrack_password

      2. Environment variables: SPACETRACK_USERNAME and SPACETRACK_PASSWORD

      3. .env file in the current directory or home directory (~/.env) containing the same environment variables

Data Models

TLERecord

A Pydantic model representing a Two-Line Element (TLE) record with metadata. Can be passed directly to TLEEphemeris via the tle parameter. Supports JSON serialization for storage and transmission.

Attributes:
  • line1 (str) — First line of the TLE (starts with ‘1’)

  • line2 (str) — Second line of the TLE (starts with ‘2’)

  • name (str | None) — Optional satellite name (from 3-line TLE format)

  • epoch (datetime) — TLE epoch timestamp (extracted from line1)

  • source (str | None) — Source of the TLE data (e.g., ‘celestrak’, ‘spacetrack’, ‘file’, ‘url’)

Derived Fields:
  • norad_id (int) — NORAD catalog ID extracted from line1

  • classification (str) — Classification from line1 (U=unclassified, C=classified, S=secret)

  • international_designator (str) — International designator extracted from line1

  • mean_motion_dot_rev_per_day2 (float) — First derivative of mean motion from line1

  • mean_motion_ddot_rev_per_day3 (float) — Second derivative of mean motion from line1

  • bstar_drag (float) — BSTAR drag term from line1

  • ephemeris_type (int) — Ephemeris type from line1

  • element_set_number (int) — Element set number from line1

  • revolution_number_at_epoch (int) — Revolution number at epoch from line2

  • inclination_deg (float) — Inclination extracted from line2

  • right_ascension_deg (float) — RAAN extracted from line2

  • eccentricity (float) — Eccentricity extracted from line2

  • arg_periapsis_deg (float) — Argument of periapsis extracted from line2

  • mean_anomaly_deg (float) — Mean anomaly extracted from line2

  • mean_motion_rev_per_day (float) — Mean motion extracted from line2

  • mean_motion_rad_s (float) — Mean motion in radians/second

  • true_anomaly_deg (float) — True anomaly derived from mean anomaly and eccentricity

  • semimajor_axis_m (float) — Semimajor axis derived using WGS72 gravitational parameter

Methods:
  • to_tle_string() — Convert to a 2-line or 3-line TLE string format

  • classical_elements(mu_m3_s2=WGS72_EARTH_MU_M3_S2) — Return a dictionary of mean classical elements with keys SemimajorAxis_m, Eccentricity, Inclination_deg, RightAscension_deg, ArgPeriapsis_deg, TrueAnomaly_deg, MeanAnomaly_deg, MeanMotion_rev_per_day, and GravitationalParameter_m3_s2. If mu_m3_s2 is overridden, SemimajorAxis_m is recomputed with the supplied value.

  • model_dump() — Convert to dictionary (Pydantic)

  • model_dump_json() — Convert to JSON string (Pydantic)

Example:

import rust_ephem

tle = rust_ephem.fetch_tle(norad_id=25544)

# Access TLE data
print(f"Satellite: {tle.name}")
print(f"NORAD ID: {tle.norad_id}")
print(f"Epoch: {tle.epoch}")
print(f"Source: {tle.source}")

# Get TLE as string
print(tle.to_tle_string())

# Serialize to JSON
json_str = tle.model_dump_json()

# Pass directly to TLEEphemeris
ephem = rust_ephem.TLEEphemeris(
    tle=tle,
    begin=datetime(2024, 1, 1, tzinfo=timezone.utc),
    end=datetime(2024, 1, 2, tzinfo=timezone.utc)
)

Constraint Configuration Classes

The following Pydantic models are used to configure constraints. These can be serialized to/from JSON and support logical combinations using Python operators.

SunConstraint

Sun proximity constraint.

Constructor:

SunConstraint(min_angle=45.0)

Attributes:
  • type — Always “sun”

  • min_angle — Minimum angular separation from Sun in degrees (0-180)

  • max_angle — Maximum angular separation from Sun in degrees (0-180), optional

MoonConstraint

Moon proximity constraint.

Constructor:

MoonConstraint(min_angle=30.0)

Attributes:
  • type — Always “moon”

  • min_angle — Minimum angular separation from Moon in degrees (0-180)

  • max_angle — Maximum angular separation from Moon in degrees (0-180), optional

  • from_limb — If True, measure angles from the Moon’s limb (adds its apparent angular radius) instead of its centre; default False

MoonLimbConstraint

Moon limb avoidance constraint (equivalent to MoonConstraint(..., from_limb=True)).

Constructor:

MoonLimbConstraint(min_angle=10.0)

Attributes:
  • type — Always “moon_limb”

  • min_angle — Minimum angular separation from the Moon’s limb in degrees (0-180)

  • max_angle — Maximum angular separation from the Moon’s limb in degrees (0-180), optional

EarthLimbConstraint

Earth limb avoidance constraint.

Constructor:

EarthLimbConstraint(min_angle=10.0, include_refraction=False, horizon_dip=False)

Attributes:
  • type — Always “earth_limb”

  • min_angle — Minimum angular separation from Earth’s limb in degrees (0-180)

  • max_angle — Maximum angular separation from Earth’s limb in degrees (0-180), optional * include_refraction — Include atmospheric refraction correction (~0.57°) for ground observers (default: False) * horizon_dip — Include geometric horizon dip correction for ground observers (default: False)

BodyConstraint

Solar system body proximity constraint.

Constructor:

BodyConstraint(body="Mars", min_angle=15.0)

Attributes:
  • type — Always “body”

  • body — Name of the solar system body (e.g., “Mars”, “Jupiter”)

  • min_angle — Minimum angular separation from body in degrees (0-180)

  • max_angle — Maximum angular separation from body in degrees (0-180), optional

EclipseConstraint

Eclipse constraint (Earth shadow). Assumes an Earth-centered ephemeris (Earth at origin).

Constructor:

EclipseConstraint(umbra_only=True)

Attributes:
  • type — Always “eclipse”

  • umbra_only — If True, only umbra counts. If False, includes penumbra.

AndConstraint

Logical AND combination of constraints.

Constructor:

AndConstraint(constraints=[constraint1, constraint2])

Attributes:
  • type — Always “and”

  • constraints — List of constraints to combine with AND

OrConstraint

Logical OR combination of constraints.

Constructor:

OrConstraint(constraints=[constraint1, constraint2])

Attributes:
  • type — Always “or”

  • constraints — List of constraints to combine with OR

XorConstraint

Logical XOR combination of constraints.

Violation semantics: The XOR constraint is violated when exactly one sub-constraint is violated; it is satisfied otherwise (i.e., when either none or more than one sub-constraints are violated). This mirrors boolean XOR over “violation” states.

Constructor:

XorConstraint(constraints=[constraint1, constraint2, ...])

Attributes:
  • type — Always “xor”

  • constraints — List of constraints (minimum 2) evaluated with XOR violation semantics

AtLeastConstraint

Threshold (k-of-n) combination of constraints.

Violation semantics: The AT_LEAST constraint is violated when the number of violated sub-constraints is greater than or equal to min_violated.

Constructor:

AtLeastConstraint(min_violated=2, constraints=[constraint1, constraint2, ...])

Attributes:
  • type — Always “at_least”

  • min_violated — Minimum number of violated sub-constraints required (>=1)

  • constraints — List of constraints (minimum 1)

NotConstraint

Logical NOT (negation) of a constraint.

Constructor:

NotConstraint(constraint=some_constraint)

Attributes:
  • type — Always “not”

  • constraint — Constraint to negate

Common Constraint Methods

All constraint configuration classes (SunConstraint, MoonConstraint, etc.) inherit these methods from RustConstraintMixin:

  • evaluate(ephemeris, target_ra, target_dec, times=None, indices=None) — Evaluate constraint for a single target

    • Returns: ConstraintResult object

    • See Constraint.evaluate() above for parameter details

  • in_constraint(time, ephemeris, target_ra, target_dec) — Check if target satisfies constraint at a single time

    • Returns: bool

  • at_least(min_violated, *others) — Build an AtLeastConstraint from this constraint plus additional constraints

    • Returns: AtLeastConstraint

Constraint Operators

Constraint configurations support Python bitwise operators for convenient combination:

  • constraint1 & constraint2 — Logical AND (equivalent to AndConstraint)

  • constraint1 | constraint2 — Logical OR (equivalent to OrConstraint)

  • constraint1 ^ constraint2 — Logical XOR (equivalent to XorConstraint)

  • ~constraint — Logical NOT (equivalent to NotConstraint)

Usage examples are provided in the examples section of the docs.

Type Aliases

ConstraintConfig

Union type for all constraint configuration classes:

ConstraintConfig = (
    SunConstraint | MoonConstraint | MoonLimbConstraint | EclipseConstraint |
    EarthLimbConstraint | BodyConstraint | AndConstraint |
  OrConstraint | XorConstraint | AtLeastConstraint | NotConstraint
)
CombinedConstraintConfig

Pydantic TypeAdapter for parsing constraint configurations from JSON.

Performance Notes

Constraint Evaluation Optimizations

The constraint system includes several performance optimizations for efficient evaluation:

  • Property Caching: The timestamp and constraint_array properties on ephemeris and constraint result objects are cached for repeated access (90x+ speedup on subsequent accesses)

  • Subset Evaluation: Use times or indices parameters in evaluate() to compute constraints for specific times only, avoiding full ephemeris evaluation

  • Single Time Checks: For checking a single time, use Constraint.in_constraint() which is optimized for single-point evaluation

  • Vectorized Batch Evaluation: For checking multiple targets, use in_constraint_batch() which evaluates all targets in a single call, eliminating Python call overhead

  • Optimal Usage Patterns:

    • FASTEST (Multiple Targets): Use batch evaluation for multiple targets:

      target_ras = [0.0, 90.0, 180.0, 270.0]
      target_decs = [0.0, 30.0, -30.0, 60.0]
      violations = constraint.in_constraint_batch(eph, target_ras, target_decs)
      # violations is (n_targets, n_times) array
      # violations[i, j] = True if target i violates constraint at time j
      
    • FAST (Single Target): Evaluate once, then use constraint_array property:

      result = constraint.evaluate(eph, ra, dec)
      for i in range(len(result.timestamp)):
          if result.constraint_array[i]:  # ~1000x faster than alternatives
              # Target is visible at this time
              pass
      
    • OK: Evaluate once, then loop over result:

      result = constraint.evaluate(eph, ra, dec)
      for i, time in enumerate(result.timestamp):
          if result.in_constraint(time):  # ~100x faster than evaluating each time
              # Target is visible
              pass
      
    • SLOW (avoid): Calling in_constraint() in a loop:

      # Don't do this - evaluates ephemeris 1000s of times!
      for time in eph.timestamp:
          if constraint.in_constraint(time, eph, ra, dec):
              pass
      

Timestamp Access

All ephemeris and constraint result objects return NumPy arrays for the timestamp property, which is significantly faster than Python lists for indexing operations.