Skyfield

1.54 · active · verified Mon Apr 13

Skyfield is an elegant Python library for high-precision astronomy calculations. It allows users to compute the positions of planets, satellites, stars, and other celestial bodies from any point on Earth or in space, at any moment in time. It leverages JPL ephemeris data to achieve high accuracy. It's actively maintained with regular releases, often several per year, reflecting ongoing development and bug fixes.

Warnings

Install

Imports

Quickstart

This quickstart calculates the astrometric position of Mars as seen from Greenwich, UK, on Christmas Day 2024. It demonstrates loading ephemeris data, defining an observer's location, specifying a time, and performing an observation to retrieve celestial coordinates.

from skyfield.api import load, Topos

# Load the ephemeris data; downloads if not present.
eph = load('de421.bsp')

# Get the timescale object for precise time calculations.
ts = load.timescale()

# Define an observer's location (e.g., Greenwich, UK)
greenwich = Topos(latitude_degrees=51.478, longitude_degrees=0.0)

# Define a specific moment in time (UTC)
t = ts.utc(2024, 12, 25, 12, 0, 0) # Christmas Day 2024, Noon UTC

# Observe Mars from Earth, as seen from Greenwich
astrometric = greenwich.at(t).observe(eph['mars'])

# Get the astrometric position (Right Ascension, Declination, Distance)
ra, dec, distance = astrometric.radec()

print(f"Time (UTC): {t.utc_datetime()}")
print(f"Mars Right Ascension: {ra}")
print(f"Mars Declination: {dec}")
print(f"Distance to Mars: {distance}")

view raw JSON →