Giter Club home page Giter Club logo

sweph-wasm's Introduction

Sweph-Wasm

Using Sweph (Swiss Ephemeris) with Wasm (Emscripten)

Based on code written by @randogoth sublunar.almanac.
I extrapolated the sweph part with wasm and I created this web application that allows you to query the functions of the Swiss Ephemeris to generate ephemeris.

The application is ready to run.
The compiled files are:

astro.data (contains sweph files - virtual file system)
astro.js (browser readable file)
astro.wasm (binaries)

To use the application run the index.html file using a local web server (localhost).

If you run the index.html file (file://) directly, browsers create a Cors error.
If you don't have a local web server you can use the emrun command (see below).

Virtual file system

The most important change was the creation of a virtual file system.
Emscripten allows you to embed files that will be used within an application. Specifically, it creates a file with the ".data" extension which will contain all of the additional files.
To create a vfs you need to pass a parameter to the compiler (in the Makefile) indicating the directory containing the files, in our case "eph"

--preload-file eph
The compiler will create a ".data" file containing all the files in the folder.

From code just make sweph point to the "eph" directory

swe_set_ephe_path("eph");

Here the documentation

How to compile

Make sure Emscripten is installed and working ๐Ÿ™‚. Here the documentation
From Command Line Interface (CLI) change to the sweph-wasm/lib/src directory.
To execute

make astro (compile sweph files and astro.c file)

make install (copy the files generated by the compiler to the right directory)

Emrun

If you don't have a local web server (localhost) you can use the emrun command.
Just add --emrun to your compiler (Makefile), compile.

To run the application:

emrun index.html

Here the documentation

Sweph files ephemeris

The application loads these three files into the virtual file system:

seas_18.se1
semo_18.se1
sepl_18.se1

These are sweph's high-precision ephemeris files.
These files have a date range from the year 1800 to 2400.
If you want to widen the date range just add the others files in the sweph-wasm/lib/src/eph directory and compile.
The compiler will add all the files present in the directory and create the astro.data file.

Command:

make astro
make install

How does it work

The astro.c file contains the logic to create the ephemeris. It interfaces with sweph and also contains functions that can be called from javascript.

A "web worker" is created from the browser which calls the "astro.js" file.

The web worker issues commands to functions in the astro.c file which returns a json string to the web worker. The return json is then processed by javascript.

The astro.js file is one of the files that is created by the compiler.

Preload data

To enable data preloading, uncomment the line:

<!--- <script type="text/javascript" src="js/preloadData.js"></script> --->

present in the index.html file

The Application Web

The Application Web

sweph-wasm's People

Contributors

u-blusky avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

sweph-wasm's Issues

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.