This is a T3/adv3 module that implements a very simple ephemeris consisting of the IAU designated constellations plus the Pleiades: nightSky github repo.
The module works with the calendar
module I put up the other day, using the local sidereal time to compute the constellations visible in the local sky, optionally computing the local altitude-azimuth coordinates for each.
Under the hood it uses very back-of-the-envelope math: approximating constellation positions by their centroids; using integer angles; rounding times to the nearest hour; and so on.
The constellation “database” consists of the IAU constellation list plus the Pleiades (for a total of 89 objects), but there are 20-odd constellations I more or less arbitrarily identified as the “prominent” ones, and the search function(s) accept an argument to only return the “prominent” constellations.
Basic usage:
// Create a calendar with the current date June 22, 1979.
c = new Calendar(1979, 6, 22, 'EST-5EDT');
// Create a sky instance centered on Cambridge, Mass.
sky = new NightSky(42, -71, c);
Having done that, you can get a list of visible constellations via:
local visible = sky.computeVisible(23, 5, true);
Where the first arg (23
here) is the local hour, the second arg is the “radius” of the horizon in hours of right ascension (5
in this case, indicating 11 total hours, or roughly half the sky, is visible), and the optional third argument indicates whether or not to only return the “interesting” constellations (true
in this case, resulting in the shorter list).
Each element in the list returned will be a list containing: the name of the constellation, the constellation’s abbreviation, the right ascension of the center of the constellation, the declination of the center of the constellation, and the “interesting” flag.
These can be used to compute the local alt-az coordinates of the constellation (or rather its center) by calling NightSky.raDecToAltAz()
. Continuing the example:
// Iterate over the list.
visible.forEach(function(o) {
// o[3] and o[4] are the RA and DEC, respectively.
// 23 is the local hour we're computing.
altAz = sky.raDecToAltAz(o[3], o[4], 23);
// o[1] is the constellation name, altAz[1]
// is the altitude, altAz[2] is the azimuth.
"\n\t<<o[1]>> (<<toString(altAz[1])>>,
<<toString(altAz[2])>>)\n ";
});
In this case the output would be:
Aquarius (15, 118)
Aquila (43, 137)
Bootes (53, 268)
Capricornus (17, 135)
Cassiopeia (30, 32)
Cepheus (27, 15)
Cygnus (58, 69)
Draco (55, 331)
Libra (20, 226)
Lyra (77, 108)
Pegasus (24, 85)
Sagittarius (19, 166)
Scorpius (20, 194)
Serpens (Caput) (49, 229)
Serpens (Cauda) (45, 180)
Ursa Major (24, 318)
Virgo (8, 257)
There’s also a NightSky.checkConstellation()
method that takes a string and an hour as its arguments and returns true
if the string is a name or abbreviation for a constellation that’s currently visible for the given hour:
// Returns true for our example
sky.checkConstellation('draco', 23);
// Returns nil
sky.checkConstellation('aries', 23);
For my purposes I’m going to want some additional sugar for adding constellations into descriptions of the sky, and some actions for handling examing the sky and constellations, but I don’t know if that’ll end up in the module or not.