PyMeeus
PyMeeus is a Python library that implements astronomical algorithms described in the classical book 'Astronomical Algorithms, 2nd Edition' by Jean Meeus. It provides routines for celestial mechanics, ephemerides, and time conversions. The library is known for its simplicity, ease of use, minimal dependencies, and abundant documentation. The current version is 0.5.12, with an irregular release cadence focused on bug fixes and new functionality.
Warnings
- gotcha Incorrect Import Pattern: Importing `pymeeus` directly and expecting sub-modules or classes to be available in its top-level namespace (e.g., `pymeeus.Epoch`) will result in an `AttributeError`. Each specific class or module must be imported directly from its path within `pymeeus` (e.g., `from pymeeus.Epoch import Epoch`).
- gotcha Outdated Leap Seconds Table in `Epoch` Class: The `Epoch` class uses an internal table for leap seconds. As leap seconds are added irregularly, this table can become outdated. Using an outdated table when converting between UTC and TT can lead to inaccuracies.
- gotcha Time Resolution Limitations: The `Epoch` class stores time as Julian Ephemeris Day (JDE). For computers with 15-digit accuracy, the final time resolution is approximately 10 milliseconds. This level of precision might be insufficient for extremely high-precision astronomical calculations.
- gotcha Alternative Library `PyPlanets`: While PyMeeus is active, a refactored version called `pyplanets` exists, which aims for a more object-oriented design and improved maintainability. Users starting new projects might consider `pyplanets` if these design principles are preferred, although `pymeeus` remains functional and well-documented.
Install
-
pip install pymeeus
Imports
- Epoch
from pymeeus.Epoch import Epoch
- Angle
from pymeeus.Angle import Angle
Quickstart
from pymeeus.Epoch import Epoch
from pymeeus.Sun import Sun
# Create an Epoch object for a specific date and time
my_epoch = Epoch(1992, 10, 13, 0, 0, 0)
# Get the Julian Ephemeris Day (JDE)
jde = my_epoch.get_jde()
print(f"Julian Ephemeris Day for 1992-10-13: {jde}")
# Calculate the Sun's geocentric apparent longitude for this epoch
sun = Sun(my_epoch)
longitude = sun.geocentric_apparent_longitude().degrees
print(f"Sun's Geocentric Apparent Longitude: {longitude:.4f} degrees")