Git Product home page Git Product logo

onekiloparsec / aa-js Goto Github PK

View Code? Open in Web Editor NEW
39.0 6.0 5.0 4.55 MB

The most comprehensive collection of accurate astronomical algorithms in JavaScript (TypeScript).

Home Page: https://onekiloparsec.dev/aa-js/

License: MIT License

JavaScript 12.25% TypeScript 87.75%
astronomy astronomy-astrophysics astronomy-library astronomy-software coordinates-transformations moon planets sun transit

aa-js's Introduction

aa-js

build and test codecov

The most comprehensive collection of accurate astronomical algorithms (AA) in JavaScript (TypeScript).

The v3 offered arbitrary-precision computations, thanks to decimal.js. But it was thousands (if not millions) of times slower than the original implementation, making its usage in a browser very difficult. After some nightly hours to optimise it and having most of both implementations side-by-side, we decided to remove decimal.js entirely.

Other AA implementations: Swift (SwiftAA), C# (AASharp).

At the beginning, aa-js is the port in javascript of the C++ implementation of Astronomical Algorithms by J.P. Naughter, called AA+, based on the reference text book by Jean Meeus. It is written in TypeScript, and covered as much as possible with tests validating the correctness of the algorithms. Tests are inspired from Jean Meeus' book and those written in SwiftAA, and are much more extended than what is available in AA+.

aa-js is the backbone of scientific algorithms used in Arcsecond.io.

Main Changes in V4

No big API changes, except there are no more Decimal.js at all, and thus no highPrecision parameter. The method signatures have not changed, but all return types are based on number.

Small changes:

  • The return type of getJulianDay is now always JulianDay and not JulianDay | undefined. If really the build of a JD is not correct, J2000 is returned with a warning.

Main Changes in V3

  • All algorithms based on arbitrary-precision operations thanks to decimal.js.
  • BREAKING (since v3.2) Equatorial coordinates uses right ascension expressed in Degree not Hour.
  • BREAKING (since v3.2) Input parameters of the coordinates modules now use complete coordinates objects, rather than individual members to reduce the number of parameters in the functions.
  • BREAKING (since v3.4) The precision of Decimal.js is not set to a default value. It is left to the consumer.
  • Moved all (non-Earth) planets modules inside a planets folder.
  • Addition of numerous orbital getters for planets (mean longitude, semi-major axis, inclination, eccentricity...)
  • Much easier and cleaner distinction between heliocentric and geocentric coordinates of planets.
  • Added easy accessor for apparent geocentric equatorial coordinates of planets.
  • Added a transformation from equatorial to topocentric coordinates.
  • Important bugfix on getPositionAngle and getPhaseAngle in the Moon module.
  • Added easy accessors for rise, transit and set times for every planet.
  • Numerous bugfixes, and added methods for dates, julian days

Available Modules

  • Planets: all the (static and dynamic) details, coordinates, quantities about Mercury, Venus, Mars, Jupiter, Saturn, Neptune and of course Pluto: planet constants, aphelion, perihelion, phase angle, illuminated fraction, magnitude, semi-diameters, heliocentric & geocentric coordinates, distance from earth, velocities, orbital details etc.
  • In addition, for Mars: the planetocentric declination of the Sun and the Earth.
  • In addition, for Jupiter: the planetocentric declination of the Sun and the Earth.
  • In addition, for Saturn: the details of the rings system.
  • Sun: mean & true anomaly, coordinates.
  • Earth: all the coordinates, mean anomaly, radius vector (distance) etc.
  • Inside Earth module: nutation: in longitude, for obliquity, true & mean obliquity of the ecliptic.
  • Inside Earth module: aberration: ecliptic and equatorial.
  • Earth.Moon: phases, age, apparent coordinates etc.
  • juliandays: creation, transformation, local mean sidereal time.
  • times: transformation between UTC, TT, AI, UT1...
  • cosmology: the cosmology calculator from Ned Wright's, but re-implemented, and tested.
  • distances: all the conversions of small and extra-galactic distances.
  • coordinates: all computation of parallactic angle, great circle angle, precessions, transformations (equatorial to ecliptic, galactic, topocentric, and inverse etc.).
  • sexagesimal: utilities for transforming values between decimal and sexagesimal.
  • risetransitset: get rise, transit and set hours, dates, julian days, as well as altitude.
  • exoplanets: WIP module to hold exoplanet transit details calculations. as altitude.

Installation

npm install aa-js

Usage

import { juliandays, Earth } from 'aa-js'

const jd = juliandays.getJulianDay(new Date())
const coords = Earth.Moon.getEquatorialCoordinates(jd)

Documentation

Almost every method is documented (quite sparingly sometimes). A good knowledge of basic astronomy helps very much. A copy of the Astronomical Algorithms textbook, by Jean Meeus (amazon) would also help, since many methods refer to it.

The documentation is published in onekiloparsec.dev/aa-js.

Benchmarks

To run benchmarks, install vite-node globally (npm i -g vite-node), then run individual benchmark like this:

npx vite-node benchmark/planets/jupiter/apparent-equatorial-coordinates.js

aa-js's People

Contributors

cedric-foellmi avatar coffee-converter avatar dependabot[bot] avatar onekiloparsec avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

aa-js's Issues

MapTo0To360Range causing loss of precision

Thank you for this awesome library! I use it to make an app that calculates precise age.

However I noticed that precision wasn't great. Specifically because of the function MapTo0To360Range, so I removed it in a local version. This also made my code simpler because I was reimplementing the lost information anyway (number of orbital cycles between dates).

Could This be removed and have this function be available to be used independently by developers? This is a breaking change so I suggest a whole new function, but without MapTo0To360Range, while the current function would become a wrapper.

I can make a PR if this sounds good!

Add a license

Did you have a particular license in mind when making this work available? Would you mind adding one to help ensure the future availability of these tools? I recommend GPL v3. It's what I use myself.

Can't consume AA.js from nom

Hey, excellent project! I'm trying to integrate in a personal project built on node.js.
I can't do that out of the box because only the src/ folder is distributed via npm (node doesn't support es modules at this time). So I have to build it using rollup:

$ rollup node_modules/aa.js/src/index.js --file aa.js/index.js --format cjs

Then I can import it doing:

const { moon } = require("./aa.js");

It's obviously not ideal. I can see a webpack configuration, but the resulting files should be added to npm and a new version of the package published.

Introduce Mars details and coordinates

Hi I'm trying to see if I can use this library, I tried your basic example:

import { julianday, moon } from 'astronomical-algorithms'

...

const jd = julianday.getJulianDay(new Date()),
const coords = moon.equatorialCoordinates(jd)

but at compile I get this error:

"export 'julianday' was not found in 'astronomical-algorithms'

I know it's still a wip, I'm just trying to understand if i'm making mistakes on my side, thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.