Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions jspredict.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@

// Npm
if (typeof require !== 'undefined') {
var satellite = require('satellite.js').satellite;
var satellite = require('satellite.js');
m_moment = require('moment');
}
// Meteor
Expand Down Expand Up @@ -148,13 +148,16 @@
var iterations = 0;

while (iterations < max_iterations && transits.length < maxTransits) {
transit = this._quickPredict(satrec, qth, time);
let transit = this._quickPredict(satrec, qth, time);
if (!transit) {
break;
}
if (transit.end > end.valueOf()) {
break;
}
if (transit.end === 0) { // Geostationary
break;
}
if (transit.end > start.valueOf() && transit.maxElevation > minElevation) {
transits.push(transit);
}
Expand Down Expand Up @@ -385,7 +388,7 @@

_gmst: function(date) {
date = new Date(date.valueOf());
return satellite.gstimeFromDate(
return satellite.gstime(
date.getUTCFullYear(),
date.getUTCMonth() + 1, // months range 1-12
date.getUTCDate(),
Expand Down
28 changes: 28 additions & 0 deletions jspredict.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const jspredict = require('./jspredict');

describe('transits', () => {
test('it computes predictable transits', () => {
const tle = "0 LEMUR-2 JEROEN\n1 40934U 15052E 15306.10048119 .00001740 00000-0 15647-3 0 9990\n2 40934 6.0033 141.2190 0010344 133.6141 226.4604 14.76056230 5130";
const qth = [15, 130, .1];
const transits = jspredict.transits(tle, qth, 1446516345242, 1446545135046, 2, 4);

// From the README.
const firstTransit = transits[0];
expect(firstTransit.start).toBeCloseTo(1446519623929.2715);
expect(firstTransit.end).toBeCloseTo(1446520436786.1265);
expect(firstTransit.maxElevation).toBeCloseTo(26.592307317708105);
expect(firstTransit.apexAzimuth).toBeCloseTo(173.4489444396936);
expect(firstTransit.maxAzimuth).toBeCloseTo(244.2708297009277);
expect(firstTransit.minAzimuth).toBeCloseTo(108.07476128814044);
expect(firstTransit.duration).toBeCloseTo(812856.8549804688);
});

test('it returns no transits for geostationary satellites', () => {
// INTELSAT 39 on Oct 31, 2019
// https://www.n2yo.com/satellite/?s=44476
const tle = "INTELSAT 39\n1 44476U 19049B 19304.31021668 .00000022 00000-0 00000+0 0 9995\n2 44476 0.0018 233.4327 0000272 5.2638 334.3170 1.00274937 908";
const qth = [20.5937, 78.9629, 0.840];
const transits = jspredict.transits(tle, qth, 1572562039000, 1572568039000, 2, 4);
expect(transits).toStrictEqual([]);
});
});
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@
},
"homepage": "https://github.com/nsat/jspredict",
"dependencies": {
"moment": "^2.10.6",
"satellite.js": "^1.2.0"
"moment": "^2.24.0",
"satellite.js": "^3.0.1"
},
"devDependencies": {
"jest": "^24.9.0"
},
"scripts": {
"test": "jest"
}
}
Loading