Overview
TheAstroEngine class provides high-precision astronomical calculations based on Meeus algorithms, implementing the ELP 2000-82 lunar theory and VSOP87 solar theory. It handles celestial body positioning, coordinate transformations, and topocentric corrections.
Location: widgets/sky_widget.py:68-439
Class: AstroEngine
Constants
| Constant | Value | Description |
|---|---|---|
DEG_TO_RAD | π / 180.0 | Degrees to radians conversion |
RAD_TO_DEG | 180.0 / π | Radians to degrees conversion |
AU_IN_KM | 149597870.7 | Astronomical Unit in kilometers |
EARTH_RADIUS_KM | 6378.14 | Earth’s equatorial radius |
Methods
get_julian_century()
Converts UTC datetime to Julian century (T) for astronomical calculations.dt_utc(datetime): UTC datetime object
tuple:(T, jd)where:T(float): Julian centuries from J2000.0 epoch (TDB)jd(float): Julian Day number (UTC)
- Calculate Julian Day using standard formula:
JD = day + ((153 * m + 2) // 5) + 365 * y + y // 4 - y // 100 + y // 400 - 32045
- Apply Delta T correction (~72s for 2026):
JD_TDB = JD + 72.0/86400.0 - Calculate centuries:
T = (JD_TDB - 2451545.0) / 36525.0
get_moon_position_elp()
Calculates geocentric lunar position using ELP 2000-82 truncated theory.T(float): Julian centuries from J2000.0
tuple:(longitude, latitude, distance)where:longitude(float): Geocentric ecliptic longitude (degrees)latitude(float): Geocentric ecliptic latitude (degrees)distance(float): Earth-Moon distance (kilometers)
L'= Mean longitude:218.3164477 + 481267.8812542 * TD= Mean elongation:297.8501921 + 445267.1114034 * TM= Sun’s mean anomaly:357.5291092 + 35999.0502909 * TM'= Moon’s mean anomaly:134.9633964 + 477198.8675055 * TF= Argument of latitude:93.2720950 + 483202.0175381 * T
+6288774 * sin(2D - M')- Major inequality-1274027 * sin(2D - 2M')- Evection+658314 * sin(2D)- Variation+213618 * sin(2M')- Annual equation-185116 * sin(M)- Solar anomaly term-114332 * sin(2F)- Reduction to ecliptic
+5128122 * sin(F)+280602 * sin(M' + F)+277693 * sin(M' - F)+173237 * sin(2D - F)
- Base:
385000.56 km -20905.355 * cos(M')-3699.111 * cos(2D - M')-2955.968 * cos(2D)-569.925 * cos(2M')
get_sun_position_vsop()
Calculates geocentric solar position using VSOP87 algorithm.T(float): Julian centuries from J2000.0
tuple:(longitude, latitude, distance)where:longitude(float): Geocentric ecliptic longitude (degrees)latitude(float): Always 0.0 (Sun’s ecliptic latitude)distance(float): Earth-Sun distance (kilometers)
- Mean geometric longitude:
L₀ = 280.46646 + 36000.76983 * T - Mean anomaly:
M = 357.52911 + 35999.05029 * T - Eccentricity:
e = 0.016708634 - 0.000042037 * T - Equation of center:
- True longitude:
λ = L₀ + C - Distance (AU to km):
ecliptic_to_equatorial()
Transforms ecliptic coordinates to equatorial (RA/Dec) coordinates.lon(float): Ecliptic longitude (degrees)lat(float): Ecliptic latitude (degrees)T(float): Julian centuries from J2000.0
tuple:(ra, dec)where:ra(float): Right ascension (degrees, 0-360)dec(float): Declination (degrees, -90 to +90)
- Calculate obliquity of ecliptic:
ε = 23.4392911° - 0.0130042*T - Convert to Cartesian:
- Convert to spherical:
get_topocentric_position()
Converts geocentric coordinates to topocentric (observer-based) coordinates, applying parallax correction.ra_geo(float): Geocentric right ascension (degrees)dec_geo(float): Geocentric declination (degrees)dist_km(float): Distance to object (kilometers)obs_lat(float): Observer latitude (degrees, -90 to +90)obs_lon(float): Observer longitude (degrees, -180 to +180)jd(float): Julian Day number
tuple:(ra_topo, dec_topo, lst)where:ra_topo(float): Topocentric right ascension (degrees)dec_topo(float): Topocentric declination (degrees)lst(float): Local Sidereal Time (degrees)
- Calculate GMST:
- Local Sidereal Time:
LST = GMST + λ(observer longitude) - Hour Angle:
H = LST - α - Horizontal parallax sine:
sin(π) = R_Earth / distance - WGS84 geocentric coordinates:
- Parallax corrections:
- Topocentric position:
get_planet_heliocentric()
Calculates heliocentric position of inner and outer planets using simplified Keplerian elements.name(str): Planet name -'mercury','venus','mars','jupiter','saturn'T(float): Julian centuries from J2000.0
tuple:(L_hel, B_hel, R_hel)where:L_hel(float): Heliocentric ecliptic longitude (degrees)B_hel(float): Heliocentric ecliptic latitude (degrees)R_hel(float): Heliocentric radius vector (AU)
L= Mean longitudeπ= Longitude of perihelione= Eccentricityi= Inclination to eclipticΩ= Longitude of ascending nodea= Semi-major axis (AU)
- Calculate mean anomaly:
M = L - π - Solve Kepler’s equation iteratively (3 iterations):
- True anomaly:
- Radius vector:
r = a * (1 - e * cos(E)) - Argument of latitude:
u = v + ωwhereω = π - Ω - Transform to ecliptic coordinates:
- Convert to spherical:
get_planet_geocentric()
Converts heliocentric planet position to geocentric position.p_L,p_B,p_R: Planet’s heliocentric longitude (°), latitude (°), radius (AU)earth_L,earth_B,earth_R: Earth’s heliocentric coordinates
tuple:(λ_geo, β_geo, Δ)where:λ_geo(float): Geocentric ecliptic longitude (degrees)β_geo(float): Geocentric ecliptic latitude (degrees)Δ(float): Earth-planet distance (AU)
- Convert planet to heliocentric Cartesian
- Convert Earth to heliocentric Cartesian
- Geocentric vector:
G = P - E - Convert back to spherical coordinates
calculate_satellite_magnitude()
Calculates apparent visual magnitude of satellites using phase function.sat_range_km(float): Distance to satellite (km)phase_angle_rad(float): Phase angle in radians (0 = full, π = new)std_mag(float): Standard magnitude at 1000 km, 0° phase (default: -1.8)
float: Apparent visual magnitude
normalize()
Normalizes angles to [0, 360) degree range.angle(float): Angle in degrees
float: Normalized angle (0 ≤ result < 360)
Usage Example
Accuracy Notes
- Moon position: ~1 arcminute accuracy (truncated ELP 2000-82)
- Sun position: ~0.01° accuracy (low-order VSOP87)
- Planet positions: ~1° accuracy for inner planets, ~0.5° for outer planets (1800-2050)
- Time range: Optimized for years 1900-2100
- Topocentric correction: Essential for Moon (parallax up to 1°), negligible for Sun/planets
References
- Meeus, Jean. Astronomical Algorithms, 2nd Edition, Willmann-Bell, 1998
- ELP 2000-82: Chapront-Touzé & Chapront lunar theory
- VSOP87: Bretagnon & Francou planetary theory