What is astronomia?
The astronomia npm package provides a collection of algorithms and functions for astronomical calculations. It includes tools for computing positions of celestial bodies, converting between different time scales, and performing various other astronomical computations.
What are astronomia's main functionalities?
Compute Positions of Celestial Bodies
This feature allows you to compute the positions of planets. The code sample demonstrates how to compute the position of Earth on a given date.
const { planetposition, data } = require('astronomia');
const earth = new planetposition.Planet(data.earth);
const jupiter = new planetposition.Planet(data.jupiter);
const date = new Date('2023-10-01');
const pos = earth.position(date);
console.log(pos);
Convert Between Time Scales
This feature allows you to convert between different time scales, such as Julian Date and Gregorian Calendar. The code sample shows how to convert a Gregorian date to Julian Date and back.
const { julian, cal } = require('astronomia');
const jd = julian.CalendarGregorianToJD(2023, 10, 1);
const date = cal.JDToCalendarGregorian(jd);
console.log(date);
Compute Rise, Transit, and Set Times
This feature allows you to compute the rise, transit, and set times of celestial bodies. The code sample demonstrates how to compute these times for the Sun as observed from Berlin on a given date.
const { rise } = require('astronomia');
const observer = { lat: 52.5200, lon: 13.4050 }; // Berlin
const date = new Date('2023-10-01');
const times = rise.times(observer, date, 'sun');
console.log(times);
Other packages similar to astronomia
astronomy-engine
The astronomy-engine package provides similar functionalities for astronomical calculations, including positions of celestial bodies, rise/set times, and more. It is known for its high precision and ease of use.
meeusjs
The meeusjs package is a JavaScript implementation of the algorithms described in Jean Meeus' 'Astronomical Algorithms'. It offers a wide range of astronomical calculations, similar to astronomia, but is based on a different set of algorithms.
suncalc
The suncalc package focuses on calculating sun and moon positions, phases, and rise/set times. While it offers fewer features compared to astronomia, it is highly optimized for solar and lunar calculations.
astronomia
An astronomical library
This library is a translation of meeus from Go to Javascript and contains
selected algorithms from the book "Astronomical Algorithms" by Jean Meeus,
following the second edition, copyright 1998, with corrections as of
August 10, 2009.
Additional algorithms not covered in the book have been added.
Installation
npm install --save astronomia
Browser usage
Make sure you add <meta charset="UTF-8">
to your HTML or at least include your
bundle with <script src="your-bundle.js" charset="UTF-8"></script>
then
this package runs in modern browsers.
- Chrome: >=45
- Firefox: >= 45
- Safari: >=10
- Mobile Safari: >=10
- Edge: >=13
- IE: >=10 (needs
core-js/es6
polyfill)
Usage
For documentation of the different packages please take a look at the source code as well as at the tests.
Packages
- angle: Angular Separation.
- apparent: Apparent Place of a Star.
- apsis: Perigee and apogee of the Moon.
- base: Basic constants and methods
- binary: Binary Stars.
- circle: Smallest Circle containing three Celestial Bodies.
- conjunction: Planetary Conjunctions.
- coord: Transformation of Coordinates. Ecliptic, Equatorial, Horizontal, Galactic coordinates.
- deltat: Dynamical Time and Universal Time.
- eclipse: Eclipses.
- elliptic: Elliptic Motion.
- elementequinox: Reduction of ecliptical Elements from one Equinox to another one.
- eqtime: Equation of time.
- fit: Curve Fitting.
- globe: Ellipsoid, Globe, Coordinates of Earth Observer.
- illum: Illuminated Fraction of the Disk and Magnitude of a Planet.
- interpolation: Interpolation of equidistant values (linear, len3, len5); Lagrange Polynoms
- iterate: Iteration.
- jm: Jewish and Moslem Calendars.
- julian: Julian Days, Gregorian, Julian calendar functions.
- jupiter: Ephemeris for Physical Observations of Jupiter.
- jupitermoons: Positions of the Satellites of Jupiter.
- kepler: Equation of Kepler.
- line: Bodies in Straight Line
- mars: Ephemeris for Physical Observations of Mars.
- moon: Ephemeris for Physical Observations of the Moon.
- moonillum: Illuminated Fraction of the Moon's Disk.
- moonmaxdec: Maximum Declinations of the Moon.
- moonnode: Passages of the Moon through the Nodes.
- moonphase: Phases of the Moon.
- moonposition: Position of the Moon.
- nearparabolic: Near-parabolic Motion.
- node: Passages through the Nodes.
- nutation: Nutation and the Obliquity of the Ecliptic.
- parabolic: Parabolic Motion.
- parallactic: The Parallactic Angle, and three other Topics.
- parallax: Correction for Parallax.
- perihelion: Planets in Perihelion and Aphelion.
- planetelements: Elements of Planetary Orbits.
- planetposition: Ecliptic position of planets by full VSOP87 theory.
- pluto: Pluto.
- precess: Precession.
- refraction: Atmospheric Refraction.
- rise: Rising, Transit, and Setting.
- saturnmoons: Positions of the Satellites of Saturn.
- saturnring: The Ring of Saturn.
- semidiameter: Semidiameters of the Sun, Moon, and Planets.
- sexagesimal: Sexagesimal classes.
- sidereal: Sidereal Time at Greenwich.
- solar: Solar Coordinates.
- solardisk: Ephemeris for Physical Observations of the Sun.
- solarxyz: Rectangular Coordinates of the Sun.
- solstice: Equinoxes, Solstices and Solarterms.
- stellar: Stellar Magnitudes.
- sundial: Calculation of a Planar Sundial.
- sunrise: Compute rise, noon, set of the Sun for an earth observer.
Using a single package
If you require a small footprint in your final application, each of the provided
packages can be used as a single one:
const base = require('astronomia').base
const base = require('astronomia/base')
ES6 Syntax
import {base} from 'astronomia'
import base from 'astronomia/base'
To access dedicated VSOP87 data sets use e.g.
const {vsop87Bvenus} = require('astronomia').data
const vsop87Bvenus = require('astronomia/data/vsop87Bvenus')
Running tests
npm test
to even run very long lasting tests, do
SLOWTESTS=1 npm test
In local browser
npm run zuul -- --local 3000
Contribution and License Agreement
If you contribute code to this project, you are implicitly allowing your code to be distributed under the MIT license.
You are also implicitly verifying that all code is your original work or correctly attributed with the source of its origin and licence.
License
MIT Licensed
See LICENSE for more info.
References
- LICENSE
- meeus
- VSOP87 dataset ftp://cdsarc.u-strasbg.fr/pub/cats/VI/81