1.0.0 • Published 1 month ago
practical-astronomy-javascript v1.0.0
Practical Astronomy - JavaScript (practical-astronomy-javascript)
Algorithms from "Practical Astronomy with your Calculator or Spreadsheet" by Peter Duffett-Smith, implemented in JavaScript.
If you're interested in this topic, please buy the book! It provides far more detail and context.
Installation
npm install practical-astronomy-javascript
Usage
Example 1: Calculate date of Easter for 2024.
Create client.js:
const pa = require('practical-astronomy-javascript');
console.log(pa.paDateTime.getDateOfEaster(2024));
Run it:
node client.js
Result:
[ 3, 31, 2024 ]
Example 2: Get detailed information about the April 8 solar eclipse, for West Alexandria, Ohio
Create client.js:
const pa = require('practical-astronomy-javascript');
// Information about the observer location
var monthOfObservation = 4;
var dayOfObservation = 8;
var yearOfObservation = 2024;
var isDaylightSavings = true;
var zoneCorrectionHours = 5;
var observerLatitude = 39.74722;
var observerLongitude = -84.53639;
var [solarEclipseCertainDateDay, solarEclipseCertainDateMonth, solarEclipseCertainDateYear, utFirstContactHour, utFirstContactMinutes, utMidEclipseHour, utMidEclipseMinutes, utLastContactHour, utLastContactMinutes, eclipseMagnitude] = pa.paEclipses.solarEclipseCircumstances(dayOfObservation, monthOfObservation, yearOfObservation, isDaylightSavings, zoneCorrectionHours, observerLongitude, observerLatitude);
// Results are in universal time, so adjust them for the observer's time zone
utFirstContactHour = utFirstContactHour - ((isDaylightSavings) ? zoneCorrectionHours - 1 : zoneCorrectionHours);
utMidEclipseHour = utMidEclipseHour - ((isDaylightSavings) ? zoneCorrectionHours - 1 : zoneCorrectionHours);
utLastContactHour = utLastContactHour - ((isDaylightSavings) ? zoneCorrectionHours - 1 : zoneCorrectionHours);
console.log(`Date of eclipse: ${solarEclipseCertainDateMonth}/${solarEclipseCertainDateDay}/${solarEclipseCertainDateYear}`);
console.log(`First contact: ${utFirstContactHour}:${utFirstContactMinutes}`);
console.log(`Mid-eclipse (totality): ${utMidEclipseHour}:${utMidEclipseMinutes}`);
console.log(`Last contact: ${utLastContactHour}:${utLastContactMinutes}`);
console.log(`Magnitude of eclipse: ${eclipseMagnitude}`);
Run it:
node client.js
Result:
Date of eclipse: 4/8/2024
First contact: 13:55
Mid-eclipse (totality): 15:11
Last contact: 16:27
Magnitude of eclipse: 1.006
Links
Library Functions - Status
Date/Time
- Calculate -> Date of Easter
- Convert -> Civil Date to Day Number
- Convert -> Civil Time <-> Decimal Hours
- Extract -> Hour, Minutes, and Seconds parts of Decimal Hours
- Convert -> Local Civil Time <-> Universal Time
- Convert -> Universal Time <-> Greenwich Sidereal Time
- Convert -> Greenwich Sidereal Time <-> Local Sidereal Time
Coordinates
- Convert -> Angle <-> Decimal Degrees
- Convert -> Right Ascension <-> Hour Angle
- Convert -> Equatorial Coordinates <-> Horizon Coordinates
- Calculate -> Obliquity of the Ecliptic
- Convert -> Ecliptic Coordinates <-> Equatorial Coordinates
- Convert -> Equatorial Coordinates <-> Galactic Coordinates
- Calculate -> Angle between two objects
- Calculate -> Rising and Setting times for an object
- Calculate -> Precession (corrected coordinates between two epochs)
- Calculate -> Nutation (in ecliptic longitude and obliquity) for a Greenwich date
- Calculate -> Effects of aberration for ecliptic coordinates
- Calculate -> RA and Declination values, corrected for atmospheric refraction
- Calculate -> RA and Declination values, corrected for geocentric parallax
- Calculate -> Heliographic coordinates
- Calculate -> Carrington rotation number
- Calculate -> Selenographic (lunar) coordinates (sub-Earth and sub-Solar)
The Sun
- Calculate -> Approximate and precise positions of the Sun
- Calculate -> Sun's distance and angular size
- Calculate -> Local sunrise and sunset
- Calculate -> Morning and evening twilight
- Calculate -> Equation of time
- Calculate -> Solar elongation
Planets
- Calculate -> Approximate position of planet
- Calculate -> Precise position of planet
- Calculate -> Visual aspects of planet (distance, angular diameter, phase, light time, position angle of bright limb, and apparent magnitude)
Comets
- Calculate -> Position of comet (elliptical)
- Calculate -> Position of comet (parabolic)
Binary Stars
- Calculate -> Binary star orbit data
The Moon
- Calculate -> Approximate and precise position of Moon
- Calculate -> Moon phase and position angle of bright limb
- Calculate -> Times of new Moon and full Moon
- Calculate -> Moon's distance, angular diameter, and horizontal parallax
- Calculate -> Local moonrise and moonset
Eclipses
- Calculate -> Lunar eclipse occurrence and circumstances
- Calculate -> Solar eclipse occurrence and circumstances
1.0.0
1 month ago
0.7.5
1 month ago
0.8.1
1 month ago
0.8.2
1 month ago
0.7.2
1 month ago
0.7.1
1 month ago
0.7.4
1 month ago
0.7.3
1 month ago
0.4.1
1 month ago
0.6.1
1 month ago
0.5.2
1 month ago
0.4.3
1 month ago
0.5.1
1 month ago
0.4.2
1 month ago
0.3.6
1 month ago
0.3.5
1 month ago
0.3.2
1 month ago
0.3.1
1 month ago
0.3.4
1 month ago
0.3.3
1 month ago
0.2.16
1 month ago
0.2.15
1 month ago
0.2.13
1 month ago
0.2.11
1 month ago
0.2.10
1 month ago
0.2.1
1 month ago
0.2.7
1 month ago
0.2.6
1 month ago
0.1.7
1 month ago
0.2.9
1 month ago
0.2.8
1 month ago
0.2.3
1 month ago
0.2.2
1 month ago
0.2.5
1 month ago
0.1.6
1 month ago
0.2.4
1 month ago
0.1.5
1 month ago
0.1.4
1 month ago
0.1.3
1 month ago
0.1.1
1 month ago
0.1.0
1 month ago