Skip to content
This repository has been archived by the owner on Apr 25, 2020. It is now read-only.

Commit

Permalink
Sweeping Refactor (#13)
Browse files Browse the repository at this point in the history
* refactor solar for better caching

* get tests to run again

* fix lunar tests

* fix tests

* refactor interface to suck less

* fix tests again

* refactor lunar to match solar

* refactor

* fix #4

* bump node version in travis

* additions and cleanup

* cleanup comments

* add tests

* cutsify the tests a little more

* more tests
  • Loading branch information
Jay LaPorte committed Apr 4, 2019
1 parent 1d9c262 commit 13b6288
Show file tree
Hide file tree
Showing 13 changed files with 385 additions and 355 deletions.
5 changes: 4 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"extends": "@darkskyapp"
"extends": "@darkskyapp",
"rules": {
"max-len": "off"
}
}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/.nyc_output
/.package-lock.json
/coverage
/node_modules
/package-lock.json
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: node_js
node_js:
- '6'
- '10'
cache:
directories:
- node_modules
20 changes: 4 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
# astro
A library that calculates the position of the sun and moon in the sky.

Installation
------------

Use NPM in the usual way.

npm install


Usage
-----

## Usage
Methods for calculating positions of the moon are in the `lunar` submodule;
method for calculating positions of the sun, in `solar`. The top-level `astro`
module contains methods for calculating astronomical times.
method for calculating positions of the sun, in `solar`.

const astro = require("astro"),
lunar = astro.lunar,
solar = astro.solar;
All methods operate in units of degrees (for angles, including latitudes and
longitudes), milliseconds (for timestamps), and AU (for distances).
64 changes: 2 additions & 62 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,63 +1,3 @@
"use strict";
const lunar = require("./lib/lunar");
const solar = require("./lib/solar");

// Convert to/from J2000 dates.
const J1970 = -10957.5;

function ms_to_julian(ms) {
return J1970 + ms / 86400000;
}

function unix_to_julian(unix) {
return J1970 + unix / 86400;
}

function date_to_julian(date) {
return ms_to_julian(date.getTime());
}

function julian_to_ms(t) {
return (t - J1970) * 86400000;
}

function julian_to_unix(t) {
return (t - J1970) * 86400;
}

function julian_to_date(t) {
return new Date(julian_to_ms(t));
}

// Greenwich mean sidereal time, accurate to ~1 second.
// http://aa.usno.navy.mil/faq/docs/GAST.php
const GMST0 = 18.697374558 * Math.PI / 12;
const GMST1 = 24.06570982441908 * Math.PI / 12;

function greenwich_mean_sidereal_time(jt) {
return GMST0 + GMST1 * jt;
}

function local_sidereal_time(jt, lon_r) {
return greenwich_mean_sidereal_time(jt) + lon_r;
}

function hour_angle(jt, lon_r) {
let angle = local_sidereal_time(jt, lon_r) - solar.right_ascension(jt);
angle -= Math.floor(angle / (2 * Math.PI)) * (2 * Math.PI);
if(angle > Math.PI) {
angle -= 2 * Math.PI;
}
return angle;
}

exports.ms_to_julian = ms_to_julian;
exports.unix_to_julian = unix_to_julian;
exports.date_to_julian = date_to_julian;
exports.julian_to_ms = julian_to_ms;
exports.julian_to_unix = julian_to_unix;
exports.julian_to_date = julian_to_date;
exports.local_sidereal_time = local_sidereal_time;
exports.hour_angle = hour_angle;
exports.solar = solar;
exports.lunar = lunar;
exports.lunar = require("./lib/lunar");
exports.solar = require("./lib/solar");
40 changes: 0 additions & 40 deletions lib/astro.js

This file was deleted.

Loading

0 comments on commit 13b6288

Please sign in to comment.