Skip to content

src/core/astro.js ​

text
Positional astronomy for the sky view: time scales, sidereal time, precession and nutation, coordinate
changes, refraction, and low-precision positions of the Sun, Moon and planets. No DOM, no three.js.

Conventions
  angles in radians unless a name ends in Deg; time as Unix milliseconds (UTC) or Julian centuries T of TT from J2000
  equatorial vectors: x to the equinox, z to the pole; "of date" = true equator and equinox of date
  horizontal vectors: [east, north, up]; azimuth from north through east; longitude east positive
  UT1 is taken equal to UTC (|UT1 - UTC| < 0.9 s, i.e. < 13.5" of sidereal time)

What each series claims, and what test/astro.test.mjs measures against astropy/ERFA with the JPL DE432s
ephemeris, 1975-2050 (run `node test/astro.test.mjs` for the current numbers):
  sidereal time    IAU 1982 GMST + 4-term nutation (Meeus, Astronomical Algorithms, ch. 12, 22)
  precession       IAU 1976 angles (Meeus ch. 21); no frame bias (17 mas)
  Sun              Meeus ch. 25 "low accuracy" (claimed 0.01 deg)
  Moon             the larger periodic terms of Meeus ch. 47 (ELP-2000/82 truncated; full table claims 10" in longitude)
  planets          Keplerian elements of E. M. Standish, "Keplerian Elements for Approximate Positions of the
                   Major Planets" (JPL Solar System Dynamics), table 1, valid 1800-2050. Claimed errors in
                   heliocentric longitude: Mercury 15", Venus 20", Earth-Moon 20", Mars 40", Jupiter 400",
                   Saturn 600", Uranus 50", Neptune 10".
  refraction       Bennett (1982) / Saemundsson (1986), 1010 hPa and 10 C unless scaled
  a night         twilight times by bisection on the Sun's altitude; rising, culmination and setting of a fixed
                   J2000 position from its hour angle (nightOf, fixedRiseSet, trackFixed). Against astropy:
                   see the "a target through a night" block of the test.
Not modelled: stellar proper motion and parallax, annual aberration of stars (20"), polar motion, UT1-UTC.

Import: import { … } from './src/core/astro.js' — no DOM, runs in Node and the browser.

RAD ​

js
const RAD
text
Positional astronomy for the sky view: time scales, sidereal time, precession and nutation, coordinate
changes, refraction, and low-precision positions of the Sun, Moon and planets. No DOM, no three.js.

Conventions
  angles in radians unless a name ends in Deg; time as Unix milliseconds (UTC) or Julian centuries T of TT from J2000
  equatorial vectors: x to the equinox, z to the pole; "of date" = true equator and equinox of date
  horizontal vectors: [east, north, up]; azimuth from north through east; longitude east positive
  UT1 is taken equal to UTC (|UT1 - UTC| < 0.9 s, i.e. < 13.5" of sidereal time)

What each series claims, and what test/astro.test.mjs measures against astropy/ERFA with the JPL DE432s
ephemeris, 1975-2050 (run `node test/astro.test.mjs` for the current numbers):
  sidereal time    IAU 1982 GMST + 4-term nutation (Meeus, Astronomical Algorithms, ch. 12, 22)
  precession       IAU 1976 angles (Meeus ch. 21); no frame bias (17 mas)
  Sun              Meeus ch. 25 "low accuracy" (claimed 0.01 deg)
  Moon             the larger periodic terms of Meeus ch. 47 (ELP-2000/82 truncated; full table claims 10" in longitude)
  planets          Keplerian elements of E. M. Standish, "Keplerian Elements for Approximate Positions of the
                   Major Planets" (JPL Solar System Dynamics), table 1, valid 1800-2050. Claimed errors in
                   heliocentric longitude: Mercury 15", Venus 20", Earth-Moon 20", Mars 40", Jupiter 400",
                   Saturn 600", Uranus 50", Neptune 10".
  refraction       Bennett (1982) / Saemundsson (1986), 1010 hPa and 10 C unless scaled
  a night         twilight times by bisection on the Sun's altitude; rising, culmination and setting of a fixed
                   J2000 position from its hour angle (nightOf, fixedRiseSet, trackFixed). Against astropy:
                   see the "a target through a night" block of the test.
Not modelled: stellar proper motion and parallax, annual aberration of stars (20"), polar motion, UT1-UTC.

AU_KM ​

js
const AU_KM

No description in the source.

wrap2pi ​

js
const wrap2pi

No description in the source.

wrapPi ​

js
const wrapPi

No description in the source.

julianDate ​

js
const julianDate

Julian date (UTC) of a Unix time in milliseconds.

fromJulianDate ​

js
const fromJulianDate

No description in the source.

ttMinusUtc ​

js
function ttMinusUtc(ms)

TT - UTC in seconds: 32.184 + leap seconds (table 1972-2017, the last value held after; 42.184 before 1972).

centuriesTT ​

js
const centuriesTT

Julian centuries of TT since J2000.0 for a Unix time in ms.

gmst ​

js
function gmst(jdUT)

Greenwich mean sidereal time (IAU 1982) for a Julian date of UT1.

nutation ​

js
function nutation(T)

Nutation in longitude and obliquity (four largest terms, about 0.5") and the obliquity of the ecliptic.

gast ​

js
function gast(jdUT, T = (jdUT - 2451545.0)

Greenwich apparent sidereal time: GMST plus the equation of the equinoxes. T defaults to UT-based centuries.

localSiderealTime ​

js
const localSiderealTime

Local apparent sidereal time for a Unix time and an east longitude in radians.

matMul ​

js
const matMul

---------------------------------------------------------------- 3x3 matrices (row-major arrays of 9) and vectors

matVec ​

js
const matVec

No description in the source.

transpose ​

js
const transpose

No description in the source.

sphToVec ​

js
const sphToVec

No description in the source.

vecToSph ​

js
const vecToSph

No description in the source.

separation ​

js
function separation(lon1, lat1, lon2, lat2)

Angle between two directions given as longitude, latitude pairs.

precessionMatrix ​

js
function precessionMatrix(T)

Precession matrix from the mean equator and equinox of J2000 to those of date (IAU 1976).

nutationMatrix ​

js
function nutationMatrix(T)

Nutation matrix from the mean to the true equator and equinox of date.

j2000ToDateMatrix ​

js
const j2000ToDateMatrix

J2000 (ICRS to 17 mas) to true equator and equinox of date.

precess ​

js
function precess(ra, dec, T)

Right ascension and declination of date for J2000 coordinates.

equatorialToHorizontalMatrix ​

js
function equatorialToHorizontalMatrix(lat, lst)

Matrix taking an equatorial-of-date unit vector to [east, north, up] for latitude and local sidereal time.

equatorialToHorizontal ​

js
function equatorialToHorizontal(ra, dec, lat, lst)

No description in the source.

horizontalToEquatorial ​

js
function horizontalToEquatorial(alt, az, lat, lst)

No description in the source.

refraction ​

js
function refraction(altTrue, pressure = 1010, tempC = 10)

Refraction to add to a true (airless) altitude: Saemundsson's formula. Returns 0 well below the horizon.

refractionFromApparent ​

js
function refractionFromApparent(altApparent, pressure = 1010, tempC = 10)

Refraction to subtract from an apparent (observed) altitude: Bennett's formula.

sunPosition ​

js
function sunPosition(T)

Geocentric apparent position of the Sun, true equator and equinox of date. dist in AU.

moonPosition ​

js
function moonPosition(T)

Geocentric apparent position of the Moon, true equator and equinox of date. dist in km.

PLANETS ​

js
const PLANETS

No description in the source.

solveKepler ​

js
function solveKepler(M, e)
text
Solve Kepler's equation E - e sin E = M.

heliocentric ​

js
function heliocentric(name, T)

Heliocentric position [AU] in the J2000 equatorial frame from the Keplerian elements. name may be 'emb'.

earthHeliocentric ​

js
function earthHeliocentric(T)

Heliocentric position of the Earth [AU], J2000 equatorial: the Earth-Moon barycentre minus the Moon's share.

planetPosition ​

js
function planetPosition(name, T)

Geocentric apparent position of a planet (light time and aberration to first order), true equator and equinox of date. dist and r (heliocentric) in AU; phase is the Sun-planet-Earth angle.

planetMagnitude ​

js
function planetMagnitude(name, r, dist, phase)

Apparent visual magnitude of a planet (Astronomical Almanac expressions as in Meeus ch. 41; Saturn without its rings, which add up to about -1 mag). r, dist in AU, phase in radians.

moonPhase ​

js
function moonPhase(sun, moon)

Phase of the Moon from the geocentric positions of the Sun and Moon: elongation, phase angle (Sun-Moon-Earth), illuminated fraction and an approximate visual magnitude.

observerVector ​

js
function observerVector(lat, lst, heightM = 0)

Geocentric position of an observer [km] in the equatorial frame of date (WGS84).

topocentric ​

js
function topocentric(ra, dec, distKm, lat, lst, heightM = 0)
text
Geocentric -> topocentric right ascension, declination and distance. distKm is the geocentric distance.

twilight ​

js
function twilight(sunAltDeg)

Day or twilight class from the true (unrefracted) altitude of the Sun's centre in degrees.

solarSystem ​

js
function solarSystem(ms, lat, lon, heightM = 0)

The Sun, Moon and planets as seen from a place: topocentric coordinates of date, airless altitude and azimuth, distance, magnitude. Returns { T, lst, sun, moon, planets[] , bodies[] }.

SIDEREAL_RATE ​

js
const SIDEREAL_RATE

Rotation of the Earth in radians per millisecond of UT (sidereal rate).

fixedAltAz ​

js
function fixedAltAz(ra, dec, ms, lat, lon)

Airless altitude and azimuth of a fixed J2000 position (radians) at a Unix time for a latitude and east longitude.

sunAltitude ​

js
function sunAltitude(ms, lat, lon, heightM = 0)

Airless topocentric altitude of the Sun's centre (radians).

crossings ​

js
function crossings(f, ms0, ms1, step = 600000)

Times in [ms0, ms1] at which f(ms) changes sign: sampled every step ms, refined by bisection to 0.1 s. Returns [{ t, rising }].

sunCrossings ​

js
const sunCrossings

Times at which the Sun's centre crosses the airless altitude alt (radians) between two Unix times.

noonBefore ​

js
const noonBefore

The last local mean noon at or before a Unix time, for an east longitude in radians.

SUN_LIMITS ​

js
const SUN_LIMITS

Altitudes of the Sun's centre (degrees) that bound day and the three twilights.

nightOf ​

js
function nightOf(ms, lat, lon, heightM = 0)

The night that contains a Unix time, or the one that follows it when the Sun is up: for each of sun (set and rise, -0.833 deg), civil, nautical and astronomical, { evening, morning } in Unix ms, null where the Sun does not reach that altitude between the local noon before and the one after (polar day or night).

fixedRiseSet ​

js
function fixedRiseSet(ra, dec, ms, lat, lon, alt0 = 0)

Rising, culmination and setting (through the airless altitude alt0, radians) of a fixed J2000 position, for the culmination nearest to a Unix time. Returns { culmination, rise, set, altMax, always, never }; rise and set are null when it is always or never above alt0.

trackFixed ​

js
function trackFixed(ra, dec, ms0, ms1, lat, lon, n = 96)

Airless altitude and azimuth of a fixed J2000 position at n + 1 equally spaced times: [{ t, alt, az }].

MIT licensed · Kyle A. Pearson