Skip to content

shashwatak/satellite-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

satellite.js

NPM version Downloads/month Build Status Coverage Status Gitter chat License

Introduction

A library to make satellite propagation via TLEs possible in the web. Provides the functions necessary for SGP4/SDP4 calculations, as callable javascript. Also provides functions for coordinate transforms.

The internals of this library are nearly identical to Brandon Rhode's sgp4 python library. However, it is encapsulated in a standard JS library (self executing function), and exposes only the functionality needed to track satellites and propagate paths. The only changes I made to Brandon Rhode's code was to change the positional parameters of functions to key:value objects. This reduces the complexity of functions that require 50+ parameters, and doesn't require the parameters to be placed in the exact order.

Special thanks to all contributors for improving usability and bug fixes :)

If you want to contribute to the project please read the Contributing section first.

Sites using the library can be found here.

Start Here:

The javascript in this library is heavily based (straight copied) from:

I've included the original PKG-INFO file from the python library.

The coordinate transforms are based off T.S. Kelso's columns:

And the coursework for UC Boulder's ASEN students

I would recommend anybody interested in satellite tracking or orbital propagation to read all of TS Kelso's columns. Without his work, this project would not be possible.

Get a free Space Track account and download your own up to date TLEs for use with this library.

Installation

Install the library with NPM:

npm install satellite.js

Install the library with Yarn:

yarn add satellite.js

Install the library with Bower:

bower install satellite.js

Warning!

satellite.js version 1.3.0 is the latest one for Bower since it has been deprecated.

Usage

Common.js (Node.js)

var satellite = require('satellite.js');
...
var positionAndVelocity = satellite.sgp4(satrec, time);
import { sgp4 } from 'satellite.js';
...
const positionAndVelocity = sgp4(satrec, time);
define(['path/to/dist/satellite'], function(satellite) {
    ...
    var positionAndVelocity = satellite.sgp4(satrec, time);
});

Here is a repo showing basic library usage with Require.js.

Script tag

Include dist/satellite.min.js as a script in your html:

<script src="path/to/dist/satellite.min.js"></script>

satellite object will be available in global scope:

var positionAndVelocity = satellite.sgp4(satrec, time);

Sample Usage

// Sample TLE
var tleLine1 = '1 25544U 98067A   19156.50900463  .00003075  00000-0  59442-4 0  9992',
    tleLine2 = '2 25544  51.6433  59.2583 0008217  16.4489 347.6017 15.51174618173442';    

// Initialize a satellite record
var satrec = satellite.twoline2satrec(tleLine1, tleLine2);

//  Propagate satellite using time since epoch (in minutes).
var positionAndVelocity = satellite.sgp4(satrec, timeSinceTleEpochMinutes);

//  Or you can use a JavaScript Date
var positionAndVelocity = satellite.propagate(satrec, new Date());

// The position_velocity result is a key-value pair of ECI coordinates.
// These are the base results from which all other coordinates are derived.
var positionEci = positionAndVelocity.position,
    velocityEci = positionAndVelocity.velocity;

// Set the Observer at 122.03 West by 36.96 North, in RADIANS
var observerGd = {
    longitude: satellite.degreesToRadians(-122.0308),
    latitude: satellite.degreesToRadians(36.9613422),
    height: 0.370
};

// You will need GMST for some of the coordinate transforms.
// http://en.wikipedia.org/wiki/Sidereal_time#Definition
var gmst = satellite.gstime(new Date());

// You can get ECF, Geodetic, Look Angles, and Doppler Factor.
var positionEcf   = satellite.eciToEcf(positionEci, gmst),
    observerEcf   = satellite.geodeticToEcf(observerGd),
    positionGd    = satellite.eciToGeodetic(positionEci, gmst),
    lookAngles    = satellite.ecfToLookAngles(observerGd, positionEcf),
    dopplerFactor = satellite.dopplerFactor(observerCoordsEcf, positionEcf, velocityEcf);

// The coordinates are all stored in key-value pairs.
// ECI and ECF are accessed by `x`, `y`, `z` properties.
var satelliteX = positionEci.x,
    satelliteY = positionEci.y,
    satelliteZ = positionEci.z;

// Look Angles may be accessed by `azimuth`, `elevation`, `range_sat` properties.
var azimuth   = lookAngles.azimuth,
    elevation = lookAngles.elevation,
    rangeSat  = lookAngles.rangeSat;

// Geodetic coords are accessed via `longitude`, `latitude`, `height`.
var longitude = positionGd.longitude,
    latitude  = positionGd.latitude,
    height    = positionGd.height;

//  Convert the RADIANS to DEGREES.
var longitudeDeg = satellite.degreesLong(longitude),
    latitudeDeg  = satellite.degreesLat(latitude);

Contributing

This repo follows Gitflow Workflow. Before starting a work on new pull request, please, checkout your feature or bugfix branch from develop branch:

git checkout develop
git fetch origin
git merge origin/develop
git checkout -b my-feature

Make sure that your changes don't break the existing code by running

npm test

and that your code follows Airbnb style

npm run lint
npm run lint:test

Implementing new functions or features, please, if possible, provide tests to cover them and mention your works in Changelog. Please don't change version number in package.json and don't add it to CHANGELOG.md. All these things should be done later with raise-version when merging to master:

npm run raise major

or

npm run raise minor

or

npm run raise patch

In order to get test code coverage run the following:

npm run test:coverage

Building

The source code is organized as Common.js modules and uses ES6 syntax.

In order to build the library follow these steps:

  • install Node.js and Node Package Manager;

  • install all required packages with NPM by running the following command from repository's root directory:

    npm install
  • run the following NPM script to build everything:

    npm run build
  • run the following NPM script to run test specs test/*.spec.js files with Mocha:

    npm test

These is a full list of all available NPM scripts:

  • build builds everything;

  • transpile transpiles ES source files located in src directory to Common.js compatible modules and saves the resulting files in lib directory;

  • dist builds ES and UMD modules in dist directory;

  • dist:es builds ES module in dist directory;

  • dist:umd builds UMD module in dist directory (both non-compressed and compressed versions);

  • dist:umd:dev builds non-compressed version of UMD module in dist directory;

  • dist:umd:prod builds compressed version of UMD module in dist directory;

  • watch:es watches for changes in src directory and automatically rebuilds ES module;

  • copy copies built library from dist to SGP4 verification application's directory;

  • lint lints sources code located in src directory with ESLint with Airbnb shared configuration;

  • lint:test lints tests located in test directory with ESLint;

  • test runs tests;

  • test:coverage runs tests with Istanbul coverage summary;

  • test:coveralls runs tests with Istanbul coverage summary and aggregates the results by Coveralls; in order to run it locally COVERALLS_REPO_TOKEN is required:

    COVERALLS_REPO_TOKEN=<token> npm run test:coveralls
    

ES5 and satellite.min.js

Some people are confused that they can't just download a single satellite.js or satellite.min.js file. That is because satellite.js is not written in plain old JavaScript (ES5) anymore but ported to latter JavaScript versions ES6+.

Only the "src" directory is included in the Git repository, "dist" and "lib" directories are ignored. It's done intentionally to retain the size of the repository as small as possible. A full detailed explanation of why is located here.

You should install satellite.js with your package manager (npm or yarn) and then find satellite.js and satellite.min.js in node_modules/satellite.js/dist directory.

TODO

Optional functions that utilize Worker Threads

Exposed Objects

satrec

The satrec object comes from the original code by Rhodes as well as Vallado. It is immense and complex, but the most important values it contains are the Keplerian Elements and the other values pulled from the TLEs. I do not suggest that anybody try to simplify it unless they have absolute understanding of Orbital Mechanics.

  • satnum Unique satellite number given in the TLE file.
  • epochyr Full four-digit year of this element set's epoch moment.
  • epochdays Fractional days into the year of the epoch moment.
  • jdsatepoch Julian date of the epoch (computed from epochyr and epochdays).
  • ndot First time derivative of the mean motion (ignored by SGP4).
  • nddot Second time derivative of the mean motion (ignored by SGP4).
  • bstar Ballistic drag coefficient B* in inverse earth radii.
  • inclo Inclination in radians.
  • nodeo Right ascension of ascending node in radians.
  • ecco Eccentricity.
  • argpo Argument of perigee in radians.
  • mo Mean anomaly in radians.
  • no Mean motion in radians per minute.

Exposed Functions

Initialization

var satrec = satellite.twoline2satrec(longstr1, longstr2);

returns satrec object, created from the TLEs passed in. The satrec object is vastly complicated, but you don't have to do anything with it, except pass it around.

NOTE! You are responsible for providing TLEs. Get your free Space Track account here. longstr1 and longstr2 are the two lines of the TLE, properly formatted by NASA and NORAD standards. if you use Space Track, there should be no problem.

Propagation

Both propagate() and sgp4() functions return position and velocity as a dictionary of the form:

{
  "position": { "x" : 1, "y" : 1, "z" : 1 },
  "velocity": { "x" : 1, "y" : 1, "z" : 1 }
}

position is in km, velocity is in km/s, both the ECI coordinate frame.

var positionAndVelocity = satellite.propagate(satrec, new Date());

Returns position and velocity, given a satrec and the calendar date. Is merely a wrapper for sgp4(), converts the calendar day to Julian time since satellite epoch. Sometimes it's better to ask for position and velocity given a specific date.

var positionAndVelocity = satellite.sgp4(satrec, timeSinceTleEpochMinutes);

Returns position and velocity, given a satrec and the time in minutes since epoch. Sometimes it's better to ask for position and velocity given the time elapsed since epoch.

Doppler

You can get the satellites current Doppler factor, relative to your position, using the dopplerFactor() function. Use either ECI or ECF coordinates, but don't mix them.

var dopplerFactor = satellite.dopplerFactor(observer, position, velocity);

See the section on Coordinate Transforms to see how to get ECF/ECI/Geodetic coordinates.

Coordinate Transforms

Greenwich Mean Sidereal Time

You'll need to provide some of the coordinate transform functions with your current GMST aka GSTIME. You can use Julian Day:

var gmst = satellite.gstime(julianDay);

or a JavaScript Date:

var gmst = satellite.gstime(new Date());

Transforms

Most of these are self explanatory from their names. Coords are arrays of three floats EX: [1.1, 1.2, 1.3] in kilometers. Once again, read the following first.

The coordinate transforms are based off T.S. Kelso's columns:

And the coursework for UC Boulder's ASEN students

These four are used to convert between ECI, ECF, and Geodetic, as you need them. ECI and ECF coordinates are in km or km/s. Geodetic coords are in radians.

var ecfCoords = satellite.eciToEcf(eciCoords, gmst);
var eciCoords = satellite.ecfToEci(ecfCoords, gmst);
var geodeticCoords = satellite.eciToGeodetic(eciCoords, gmst);
var ecfCoords = satellite.geodeticToEcf(geodeticCoords);

These function is used to compute the look angle, from your geodetic position to a satellite in ECF coordinates. Make sure you convert the ECI output from sgp4() and propagate() to ECF first.

var lookAngles = satellite.ecfToLookAngles(observerGeodetic, satelliteEcf);

Latitude and Longitude

These two functions will return human readable Latitude or Longitude strings (Ex: "125.35W" or "45.565N") from geodeticCoords:

var latitudeStr = satellite.degreesLat(geodeticRadians),
    longitudeStr = satellite.degreesLong(geodeticRadians);

Note about Code Conventions

Like Brandon Rhodes before me, I chose to maintain as little difference between this implementation and the prior works. This is to make adapting future changes suggested by Vallado much simpler. Thus, some of the conventions used in this library are very weird.

How this was written

I took advantage of the fact that Python and JavaScript are nearly semantically identical. Most of the code is just copied straight from Python. Brandon Rhodes did me the favor of including semi-colons on most of the lines of code. JavaScript doesn't support multiple values returned per statement, so I had to rewrite the function calls. Absolutely none of the mathematical logic had to be rewritten.

Benchmarking

I've included a small testing app, that provides some benchmarking tools and verifies SGP4 and SDP4 using the Test Criteria provided by SpaceTrack Report #3, and is based off System Benchmarking by TS Kelso.

The testing app is a Chrome Packaged App that uses the angular.js framework.

Before running the app build the library and copy resulting files from dist directory to app's directory with the following command:

npm run copy

To run the test, open up Chrome, go to the extensions page, and check "Developer Mode". Then, click "Load Unpacked App", and select the sgp4_verification folder. Then run the app from within Chrome. The test file is located within the sgp4_verification directory, as a JSON file called spacetrack-report-3.json.

Acknowledgments

Major thanks go to Brandon Rhodes, TS Kelso, and David Vallado's team. Also, I'd like to thank Professor Steve Petersen (AC6P) of UCSC for pointing me in the correct directions.

License

All files marked with the License header at the top are Licensed. Any files unmarked by me or others are unlicensed, and are kept only as a resource for [Shashwat Kandadai and other developers] for testing.

I chose the MIT License because this library is a derivative work off Brandon Rhodes sgp4, and that is licensed with MIT. It just seemed simpler this way, sub-licensing freedoms notwithstanding.

I worked in the Dining Hall at UCSC for a month, which means I signed a form that gives UCSC partial ownership of anything I make while under their aegis, so I included them as owners of the copyright.

Please email all complaints to help@ucsc.edu