Astronomical engine methodology

Full calculation chain: how a date and a location become apparent equatorial coordinates, horizon altitude and rise times. Each layer documented with source paper and tolerance.

Pipeline overview

The engine processes a query in 9 sequential stages, each with an explicit scientific source. The stages are independent (layers), allowing you to swap one implementation without affecting the others.

1. Input sanitization                 [ObserverModel]
2. Time scales (UTC->UT1->TAI->TT->TDB)   [TimeScaleService + Espenak-Meeus]
3. Sun and Moon ephemerides (geocentric)  [VSOP87D + ELP-2000/82B]
4. Nutation + annual aberration           [IAU 1980 or IAU 2000A]
5. Ecliptic -> equatorial conversion      [Coordinates::eclipticToEquatorial]
6. Topocentric parallax                   [TopocentricTransformer + WGS84]
7. Atmospheric refraction                 [Bennett, Saemundsson or None]
8. Daily events (rise/set/transit)        [RiseSetTransitSolver]
9. Auxiliary predictions                  [Phases, eclipses, supermoons, libration]

1. Input sanitization and validation

Every input parameter has scientifically justified limits. Out-of-range values are rejected with HTTP 400 or replaced with a safe default, following the policy for each field.

Field Limit Justification
Latitude −90 to +90 degrees Geometric definition (pole to pole)
Longitude −180 to +180 degrees Geometric definition
Observer altitude −430 to +9000 meters Dead Sea −430m up to Everest 8849m. ICAO ISA standard atmosphere
Atmospheric pressure 0 to 1100 hPa ICAO ISA surface 1013.25 hPa, records up to ~1083 hPa
Temperature −100 to +70 °C Vostok −89.2 °C (1983), Lut +70.7 °C (2005)
Relative humidity 0 to 100 % Thermodynamic definition
Horizon refraction 0 to 1.5 degrees IAU standard 0.5667°, plausible maximum ~1.5°
Manual ΔT −100 to +200 seconds Window 1900-2100, Espenak-Meeus 2006
UT1−UTC −0.9 to +0.9 seconds IERS Conventions 2010, limit before leap second
TAI−UTC 10 to 50 seconds Currently 37s (since 2017), historical since 1972
Event step 60 to 3600 seconds Trade-off between precision and compute time
Datetime range 4000 BC to 3000 AD Theoretical window of Espenak-Meeus + ELP + VSOP

2. Time scales

Astronomy uses several distinct time scales, and confusing them produces errors of minutes. The engine keeps them all explicit and converts as needed at each stage:

  • UTC (Coordinated Universal Time): what your clock shows. Defined as TAI minus leap seconds.
  • UT1: tied to the real rotation of the Earth. UT1 − UTC published by IERS, varies ~0.9s.
  • TAI (International Atomic Time): atomic time, no leap seconds. TAI − UTC = 37 seconds in 2026.
  • TT (Terrestrial Time): TAI + 32.184 seconds. Uniform, primary scale for ephemerides.
  • TDB (Barycentric Dynamical Time): TT corrected for relativistic effects (~1.7 ms envelope).

The difference ΔT = TT − UT1 is not mathematically predictable because it depends on the actual Earth rotation (affected by tides, earthquakes, El Niño). We use the Espenak-Meeus 2006 polynomial:

// For 2026:
ΔT = 75.07 seconds
UT1 − UTC = 0 seconds (default case; IERS updates daily)
TAI − UTC = 37 seconds
TT − UTC = TAI − UTC + 32.184 = 69.184 seconds

Source: Espenak F., Meeus J., Five Millennium Canon of Solar Eclipses: -1999 to +3000, NASA Technical Publication 2006-214141 (2006). Polynomial in 9 historical branches covering 4000 BC to 3000 AD.

3. Geocentric ephemerides

3.1 Moon: ELP-2000/82B (Chapront-Touzé & Chapront)

The ELP-2000/82B theory (Ephemeride Lunaire Parisienne) was developed by Michelle Chapront-Touzé and Jean Chapront at Bureau des Longitudes (Observatoire de Paris) in the 1980s, and is the highest-precision analytical theory for the Moon.

36 total series, grouped by physical origin:

SeriesContentSize
ELP1-3 Main problem (Sun-Earth-Moon) ~1500 terms
ELP4-6 Earth figure perturbations ~50 terms
ELP7-9 Earth figure × t (secular variation) ~10 terms
ELP10-21 Planetary perturbations (tables 1 and 2) ~13000 terms
ELP22-27 Tidal effects (×t⁰ and ×t¹) ~10 terms
ELP28-30 Moon figure perturbations ~30 terms
ELP31-33 Relativistic terms ~30 terms
ELP34-36 Planetary × solar eccentricity × t² ~50 terms

Raw total: ~37,872 terms. After truncation at 0.0001 arcsec (lon/lat) and 0.001 km (distance), we preserve 8467 terms, enough to reproduce Meeus 47.a with error < 0.02 arcsec.

Includes the DE200/LE200 adjustment correction (which links analytical ELP to JPL DE numerical ephemerides), full Delaunay arguments (D, ℓ′, ℓ, F) and planetary mean longitudes for 8 planets.

Sources:

  • Chapront-Touzé M., Chapront J. (1983). The lunar ephemeris ELP-2000. Astronomy & Astrophysics, 124, 50-62.
  • Chapront-Touzé M., Chapront J. (1988). ELP-2000/82B and the dynamical reference system. Astronomy & Astrophysics, 190, 342-352.
  • Original Fortran code: IMCCE Bureau des Longitudes, MCJCGF.9601 (elp82b_1.f).

3.2 Sun: VSOP87D (Bretagnon & Francou)

The VSOP87 theory (Variations Seculaires des Orbites Planetaires) is from the same team (Bretagnon and Francou, IMCCE/Bureau des Longitudes). VSOP87D is the variant that returns heliocentric ecliptic coordinates at the equinox of date, ideal for geocentric conversion.

We compute the heliocentric position of Earth (longitude L, latitude B, distance R) and invert to the geocentric Sun:

L_Sun_geo = L_Earth_helio + 180°
B_Sun_geo = -B_Earth_helio
R_Sun_geo = R_Earth_helio

Current truncation (Sun Lite): 35 terms for L, 7 for B, 16 for R = 58 total terms. Typical precision ~3 arcsec in solar longitude. Equivalent to Meeus Ch. 25.

Source: Bretagnon P., Francou G. (1988). Planetary theories in rectangular and spherical variables: VSOP87 solution. Astronomy & Astrophysics, 202, 309-315. VizieR catalogue VI/81.

3.3 IAU 2006 frames (opt-in)

For advanced scientific use, the engine implements the IAU 2006 P03 theory (Capitaine, Wallace & Chapront 2003) for precession and the Frame Bias B matrix (IERS Conventions 2010, Eq. 5.18) for the transformation between ICRS and the J2000.0 mean equator.

The full NPB chain (Nutation x Precession x Bias) lives at core/astro/frames/NPBChain.php and allows:

// ICRS (J2000 inertial) -> true equator of date
$M = NPBChain::icrsToTrueOfDate($tTt, $deltaPsiArcsec, $deltaEpsArcsec, $epsADeg);
$radec_apparent = NPBChain::transformIcrsToTrueOfDate(...)

Includes IAU 2006 mean obliquity (Capitaine et al. 2003 Eq. 39), polynomials zeta_A, z_A, theta_A for precession about the equatorial equator. Validated in test_phase12_iau2006_frames.php (21/21 passes, including orthogonality of the precession matrix, round-trip ICRS <-> of-date and 26-year precession magnitude).

4. Apparent corrections

4.1 Nutation

The Earth rotation axis oscillates on a short timescale (~18.6 years) due to the Moon-Sun gravitational torque. The IAU 1980 series (66 terms, Meeus Table 22.A) delivers precision < 0.001″ in Δψ and Δε, and is the default. For microarcsecond precision in advanced research, we offer the full IAU 2000A series (1365 terms, IERS Conventions 2010).

4.2 Annual aberration

Earth orbital speed (~30 km/s) shifts the apparent star position by up to 20.5 arcsec. For the Moon the effect is smaller (the Moon moves with the Earth) but non-zero. We apply:

Δλ = -20.4898 / 3600 / R_AU × cos(β)
(Meeus Eq. 23.1, simplified for the Moon)

4.3 Ecliptic → equatorial conversion

Applied with the true obliquity ε = ε₀ + Δε:

α (RA)  = atan2(sin(λ) cos(ε) − tan(β) sin(ε), cos(λ))
δ (Dec) = asin(sin(β) cos(ε) + cos(β) sin(ε) sin(λ))
(Meeus Eq. 13.3 and 13.4)

5. Topocentric parallax

The Moon sits only 60 Earth radii away, so its apparent position shifts by up to 1 degree depending on the observer on Earth (lunar horizontal parallax). For the Sun it is only ~8.8 arcsec.

The engine computes topocentric coordinates treating the observer as a point on the WGS84 ellipsoid surface (more accurate than approximating Earth as a sphere):

e² = 2f − f² (squared eccentricity)
N = a / sqrt(1 − e² sin²(φ))
x_obs = (N + h) cos(φ) cos(L_solar)
y_obs = (N + h) cos(φ) sin(L_solar)
z_obs = (N(1 − e²) + h) sin(φ)
(WGS84: a=6378137 m, f=1/298.257223563)

The topocentric vector is subtracted from the body geocentric vector, corrected for local sidereal time. Result: real RA, Dec, distance and altitude/azimuth for the observer.

6. Atmospheric refraction

The atmosphere bends light rays, lifting objects near the horizon by up to 35 arcmin (the effect that makes the Sun look bigger and higher at sunrise/sunset). The engine offers three models:

ModelRangeFeatures
Bennett 1982 (default) −0.9° to +90° Classical, simple formula, good for visual observation
Saemundsson 1986 −2° to +90° Inverse of Bennett (apparent → true), more accurate at low altitude
None (astrometrico) No refraction. Used for validation against stellar catalogues

Each model accepts pressure (hPa) and temperature (°C) as inputs to tune the real refraction of the day.

Source: Bennett G.G. (1982). The calculation of astronomical refraction in marine navigation. Journal of Navigation, 35(2), 255-259. Saemundsson Th. (1986). Sky & Telescope, 72, 70.

7. Daily events (rise / set / transit)

The Moon has a horizontal parallax of ~1 degree and moves fast across the sky (~13°/day), so the simple formula cos(H) = -tan(φ)tan(δ) is off by up to 15 minutes for the rise/set time. We use a more robust approach:

  1. Dynamic horizon threshold considering: disc mode (center or upper limb), horizon dip (0.0293·√altitude_m), horizon refraction (0.5667° default), lunar horizontal parallax.
  2. Adaptive scan of apparent altitude in 5-min steps (configurable) along the local day.
  3. Bisection to refine to error < 1 second on zero crossings of altitude − threshold.
  4. Ternary search for the transit (max altitude).

Result: rise, transit (culmination) and set times with typical precision ±5 seconds at the zenith and ±30 seconds near the horizon. Plenty for amateur, observational and educational use.

8. Auxiliary predictions

The engine also computes (when applicable):

  • Main phases: New, First Quarter, Full, Last Quarter. Bisection of Sun-Moon elongation.
  • Apsides: lunar perigee and apogee via the anomalistic month (27.55 days).
  • Solar and lunar eclipses: heuristic detection via Moon proximity to nodes + Earth-Moon-Sun distance.
  • Supermoons and Micromoons: classification by syzygy distance (≤360,000 km super, ≥405,000 km micro).
  • Blue / Black Moon: phase counting per calendar month.
  • Lunar Standstill: maximum lunar declination (18.6-year cycle).
  • Optical libration: visible fraction of the lunar disc (first order, Meeus Ch. 53).
  • Apparent magnitude: Allen 1976 formula (with phase angle).
  • Orbital speed: vis-viva (accurate for the instant distance).
  • Light-time: Earth-Moon distance divided by the speed of light (~1.3 seconds).

9. Multicultural calendars

In parallel with the scientific output, the engine converts the date to 5 calendars: Gregorian, Julian, Hijri (Islamic), Hebrew, Chinese. Useful for history teachers, comparative religion, anthropology and cultural studies.

Quick references

Full bibliography at /laboratorio/fontes. Glossary at /laboratorio/glossario. Numerical validation at /laboratorio/precisao. Engine versioning at /laboratorio/changelog.