GithubHelp home page GithubHelp logo

gmarty / vsop87 Goto Github PK

View Code? Open in Web Editor NEW
7.0 2.0 0.0 6.83 MB

๐Ÿช A fast implementation of the VSOP87 theory in JavaScript.

License: MIT License

JavaScript 66.59% Shell 0.01% C 33.41%
vsop87 astronomy planets ephemeris

vsop87's Introduction

VSOP87 ๐Ÿช

A fast implementation of the VSOP87 theory in JavaScript.

What?

A JavaScript library that implements series A and C of the VSOP87 theory.

It's big: ~719 Kb to ~826 Kb gzipped depending on the series (~2.08 Mb to ~2.29 Mb unzipped).

Install

$ yarn add vsop87

Usage

JavaScript version

In node:

// Can also be 'vsop87/dist/vsop87a'.
const vsop87c = require('vsop87/dist/vsop87c');

// Get an object with the (x,y,z) coordinates of each planet.
const coords = vsop87c(2451545);

In browsers, we recommend to load the script asynchronously:

// Can also be 'vsop87/dist/vsop87a'.
import('vsop87/dist/vsop87c').then((vsop87c) => {
  // Get an object with the (x,y,z) coordinates of each planet.
  const coords = vsop87c(2451545);
});

WebAssembly version

In browsers:

import vsop87cLoader from 'vsop87/dist/vsop87c-wasm';

vsop87cLoader.then((vsop87c) => {
  // Get an object with the (x,y,z) coordinates of each planet.
  const coords = vsop87c(2451545);
});

About the precision

According to the doc:

  • Mercury, Venus, Earth-Moon barycenter and Mars: precision of 1" for 4000 years before and after J2000.
  • Jupiter and Saturn: precision of 1" for over 2000 years before and after J2000.
  • Uranus and Neptune: precision of 1" for over 6000 years before and after J2000.

Why?

There are already tons of other implementations in JavaScript of the VSOP87 theory out there.

This one differs from the other ones by being statically compiled and optimised so it can run as fast as possible. Other implementations usually use the original VSOP87 files, or arrays containing the terms, and then apply the operations successively. This is less efficient that inlining the operations directly.

By doing so, a few optimisations are possible:

  • Remove terms multiplying by 0
  • Remove entire terms of specific order resulting in 0
  • Avoid calls to cosine when the value is 0
  • Avoid calls to cosine when the value is Pi
  • The result code ensures good level of minifiability.

Unlike other ports, this one is incomplete as it only support VSOP87 series A and C. But it is fully tested and compliant with the official check values.

I accept PR for extending support to other series.

Contribute

Build the JavaScript version

$ yarn build

If a RangeError: Maximum call stack size exceeded error message occurs at build time, try to increase the maximum stack size of node:

$ node --stack-size=1968 node_modules/.bin/rollup --config

Build the WebAssembly version

Install emscripten, then:

$ ./build && yarn build

Using Prettier

If Prettier struggles to work on the big files, try the following:

$ node --stack-size=1968 node_modules/.bin/prettier --write "{src,test}/**/*.js"

Run the unit tests

Make sure to run the build script first, then:

$ yarn test

vsop87's People

Contributors

dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

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.