API Reference: Retrograde Module
Overview
This module provides functions to detect and track planetary retrograde motion from any location on Earth.
Functions
retrograde
Provides functions to determine if a planet is in retrograde motion.
RetrogradeFunction
A class to determine if a planet is in retrograde motion from a given location on Earth.
Attributes:
| Name | Type | Description |
|---|---|---|
astronomical_code |
str
|
The astronomical code of the planet to observe. |
latitude |
float
|
The latitude of the observer's location. |
longitude |
float
|
The longitude of the observer's location. |
step_days |
int
|
The number of days to step back for comparison (default is 7). |
Methods:
| Name | Description |
|---|---|
__call__ |
Time) -> bool:
Determines if the planet is in retrograde motion at the given time |
Source code in ndastro_engine/retrograde.py
__call__(t)
Determine if the planet is in retrograde motion at a given time.
This method calculates the ecliptic longitude of the planet at the given time t
and compares it with the ecliptic longitude of the planet at the previous time t-1.
If the longitude decreases, the planet is in retrograde motion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
Time
|
The time at which to check for retrograde motion. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the planet is in retrograde motion, False otherwise. |
Source code in ndastro_engine/retrograde.py
__init__(astronomical_code, latitude, longitude)
Initialize a new instance of the retrograde class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
astronomical_code
|
AstronomicalCode
|
The astronomical code of the planet. |
required |
latitude
|
float
|
The latitude coordinate. |
required |
longitude
|
float
|
The longitude coordinate. |
required |
Source code in ndastro_engine/retrograde.py
__get_retrograde_function(astronomical_code, latitude, longitude)
Create a RetrogradeFunction instance for a given planet and location.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
astronomical_code
|
AstronomicalCode
|
The astronomical code of the planet. |
required |
latitude
|
float
|
The latitude of the location. |
required |
longitude
|
float
|
The longitude of the location. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
RetrogradeFunction |
RetrogradeFunction
|
An instance of RetrogradeFunction for the specified planet and location. |
Source code in ndastro_engine/retrograde.py
find_retrograde_periods(start_date, end_date, astronomical_code, latitude, longitude)
Calculate the retrograde periods for a given planet within a specified date range and location.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_date
|
datetime
|
The start date of the period to check for retrograde motion. |
required |
end_date
|
datetime
|
The end date of the period to check for retrograde motion. |
required |
astronomical_code
|
AstronomicalCode
|
The astronomical code of the planet to check for retrograde motion. |
required |
latitude
|
float
|
The latitude of the observation location. |
required |
longitude
|
float
|
The longitude of the observation location. |
required |
Returns:
| Type | Description |
|---|---|
list[tuple[datetime, datetime]]
|
list[tuple[datetime, datetime]]: A list of tuples, each containing the start and end datetime of a retrograde period. |
Source code in ndastro_engine/retrograde.py
is_planet_in_retrograde(check_date, astronomical_code, latitude, longitude)
Check if a planet is in retrograde motion on a specific date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
check_date
|
datetime
|
The date to check for retrograde motion. |
required |
astronomical_code
|
AstronomicalCode
|
The astronomical code of the planet to check. |
required |
latitude
|
float
|
The latitude in decimal degrees of the observation location. |
required |
longitude
|
float
|
The longitude in decimal degrees of the observation location. |
required |
Returns:
| Type | Description |
|---|---|
tuple[bool, datetime | None, datetime | None]
|
tuple[bool, datetime | None, datetime | None]: A tuple containing: - bool: True if the planet is in retrograde motion on the given date, otherwise False. - datetime | None: The start date of the retrograde period (None if not in retrograde). - datetime | None: The end date of the retrograde period (None if not in retrograde). |
Source code in ndastro_engine/retrograde.py
RetrogradeFunction Class
RetrogradeFunction
A class to determine if a planet is in retrograde motion from a given location on Earth.
Attributes:
| Name | Type | Description |
|---|---|---|
astronomical_code |
str
|
The astronomical code of the planet to observe. |
latitude |
float
|
The latitude of the observer's location. |
longitude |
float
|
The longitude of the observer's location. |
step_days |
int
|
The number of days to step back for comparison (default is 7). |
Methods:
| Name | Description |
|---|---|
__call__ |
Time) -> bool:
Determines if the planet is in retrograde motion at the given time |
Source code in ndastro_engine/retrograde.py
__call__(t)
Determine if the planet is in retrograde motion at a given time.
This method calculates the ecliptic longitude of the planet at the given time t
and compares it with the ecliptic longitude of the planet at the previous time t-1.
If the longitude decreases, the planet is in retrograde motion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
Time
|
The time at which to check for retrograde motion. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the planet is in retrograde motion, False otherwise. |
Source code in ndastro_engine/retrograde.py
__init__(astronomical_code, latitude, longitude)
Initialize a new instance of the retrograde class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
astronomical_code
|
AstronomicalCode
|
The astronomical code of the planet. |
required |
latitude
|
float
|
The latitude coordinate. |
required |
longitude
|
float
|
The longitude coordinate. |
required |
Source code in ndastro_engine/retrograde.py
Examples
Check if a Planet is Retrograde
from datetime import datetime
from skyfield.units import Angle
from ndastro_engine.utils import is_planet_in_retrograde
from ndastro_engine.enums import Planets
# Location: Chennai, India
latitude = Angle(degrees=13.0827)
longitude = Angle(degrees=80.2707)
# Check Mercury retrograde on a specific date
check_date = datetime(2023, 12, 20, 12, 0, 0)
is_retro, start_date, end_date = is_planet_in_retrograde(
check_date,
Planets.MERCURY.astronomical_code,
latitude,
longitude
)
if is_retro:
print(f"Mercury is retrograde from {start_date} to {end_date}")
else:
print("Mercury is in direct motion")
Get Retrograde Period for Multiple Planets
from datetime import datetime
from skyfield.units import Angle
from ndastro_engine.utils import is_planet_in_retrograde
from ndastro_engine.enums import Planets
latitude = Angle(degrees=28.6139) # New Delhi
longitude = Angle(degrees=77.2090)
check_date = datetime(2026, 4, 18, 12, 0, 0)
planets_to_check = [
Planets.MERCURY,
Planets.VENUS,
Planets.MARS,
Planets.JUPITER,
Planets.SATURN
]
for planet in planets_to_check:
is_retro, start, end = is_planet_in_retrograde(
check_date,
planet.astronomical_code,
latitude,
longitude
)
status = "Retrograde" if is_retro else "Direct"
print(f"{planet.name}: {status}")
if is_retro and start and end:
print(f" Period: {start.date()} to {end.date()}")
See Also
- Retrograde Periods Guide - Detailed guide on retrograde motion
- Core Module - Core astronomical calculations
- Planets Enum - Planet definitions and codes