UNPKG

14.5 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.PlanetRise = exports.times = exports.approxTimes = exports.Stdh0Lunar = exports.stdh0Lunar = exports.Stdh0LunarMean = exports.stdh0LunarMean = exports.Stdh0Solar = exports.stdh0Solar = exports.Stdh0Stellar = exports.stdh0Stellar = exports.stdh0 = exports.meanRefraction = exports.errorBelowHorizon = exports.errorAboveHorizon = undefined;
7
8var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
9
10var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); /* eslint key-spacing: 1 */
11/**
12 * @copyright 2013 Sonia Keys
13 * @copyright 2016 commenthol
14 * @license MIT
15 * @module rise
16 */
17/**
18 * Rise: Chapter 15, Rising, Transit, and Setting.
19 */
20
21exports.refraction = refraction;
22exports.hourAngle = hourAngle;
23
24var _base = require('./base');
25
26var _base2 = _interopRequireDefault(_base);
27
28var _deltat = require('./deltat');
29
30var _deltat2 = _interopRequireDefault(_deltat);
31
32var _elliptic = require('./elliptic');
33
34var _elliptic2 = _interopRequireDefault(_elliptic);
35
36var _interpolation = require('./interpolation');
37
38var _interpolation2 = _interopRequireDefault(_interpolation);
39
40var _julian = require('./julian');
41
42var _julian2 = _interopRequireDefault(_julian);
43
44var _sexagesimal = require('./sexagesimal');
45
46var _sexagesimal2 = _interopRequireDefault(_sexagesimal);
47
48var _sidereal = require('./sidereal');
49
50var _sidereal2 = _interopRequireDefault(_sidereal);
51
52function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
53
54function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
55
56var acos = Math.acos,
57 asin = Math.asin,
58 cos = Math.cos,
59 sin = Math.sin;
60
61
62var SECS_PER_DEGREE = 240; // = 86400 / 360
63var SECS_PER_DAY = 86400;
64var D2R = Math.PI / 180;
65
66var errorAboveHorizon = exports.errorAboveHorizon = _base2.default.errorCode('always above horizon', -1);
67var errorBelowHorizon = exports.errorBelowHorizon = _base2.default.errorCode('always below horizon', 1);
68
69/**
70 * mean refraction of the atmosphere
71 */
72var meanRefraction = exports.meanRefraction = new _sexagesimal2.default.Angle(false, 0, 34, 0).rad();
73
74/**
75 * "Standard altitudes" for various bodies already including `meanRefraction` of 0°34'
76 *
77 * The standard altitude is the geometric altitude of the center of body
78 * at the time of apparent rising or seting.
79 */
80var stdh0 = exports.stdh0 = {
81 stellar: -meanRefraction,
82 solar: new _sexagesimal2.default.Angle(true, 0, 50, 0).rad(),
83 // not containing meanRefraction
84 lunar: new _sexagesimal2.default.Angle(false, 0, 0, 0.7275).rad(),
85 lunarMean: new _sexagesimal2.default.Angle(false, 0, 0, 0.125).rad()
86
87 /**
88 * Helper function to obtain corrected refraction
89 * @param {number} h0 - altitude of the body in radians containing `meanRefraction` of 0°34'
90 * @param {number} corr - the calcluated refraction e.g. from package `refraction` in radians
91 * @return {number} refraction value in radians
92 */
93};function refraction(h0, corr) {
94 if (!corr) {
95 return h0;
96 } else {
97 return h0 - meanRefraction - corr;
98 }
99}
100
101/**
102 * standard altitude for stars, planets at apparent rising, seting
103 */
104var stdh0Stellar = exports.stdh0Stellar = function stdh0Stellar(_refraction) {
105 return refraction(stdh0.stellar, _refraction);
106};
107var Stdh0Stellar = exports.Stdh0Stellar = stdh0Stellar(); // for backward-compatibility
108/**
109 * standard altitude for sun for upper limb of the disk
110 */
111var stdh0Solar = exports.stdh0Solar = function stdh0Solar(_refraction) {
112 return refraction(stdh0.solar, _refraction);
113};
114var Stdh0Solar = exports.Stdh0Solar = stdh0Solar(); // for backward-compatibility
115
116/**
117 * standard altitude for moon (low accuracy)
118 */
119var stdh0LunarMean = exports.stdh0LunarMean = function stdh0LunarMean(_refraction) {
120 return stdh0.lunarMean - refraction(_refraction);
121};
122var Stdh0LunarMean = exports.Stdh0LunarMean = stdh0LunarMean(); // for backward-compatibility
123/**
124 * Stdh0Lunar is the standard altitude of the Moon considering π, the
125 * Moon's horizontal parallax.
126 * @param {number} π - the Moon's horizontal parallax
127 * @param {number} [refraction] - optional value for refraction in radians if
128 * omitted than meanRefraction is used
129 * @return {number} altitude of Moon in radians
130 */
131var stdh0Lunar = exports.stdh0Lunar = function stdh0Lunar(π, refraction) {
132 refraction = refraction || meanRefraction;
133 return stdh0.lunar * π - refraction;
134};
135var Stdh0Lunar = exports.Stdh0Lunar = stdh0Lunar; // for backward-compatibility
136
137/**
138 * @return {number} local angle in radians
139 */
140function hourAngle(lat, h0, δ) {
141 // approximate local hour angle
142 var cosH = (sin(h0) - sin(lat) * sin(δ)) / (cos(lat) * cos(δ)); // (15.1) p. 102
143 if (cosH < -1) {
144 throw errorAboveHorizon;
145 } else if (cosH > 1) {
146 throw errorBelowHorizon;
147 }
148 var H = acos(cosH);
149 return H;
150}
151
152/**
153 * @param {number} lon - longitude in radians
154 * @param {number} α - right ascension in radians
155 * @param {number} th0 - sidereal.apparent0UT in seconds of day `[0...86400[`
156 * @return {number} time of transit in seconds of day `[0, 86400[`
157 */
158function _mt(lon, α, th0) {
159 // const mt = (((lon + α) * 180 / Math.PI - (th0 * 360 / 86400)) * 86400 / 360)
160 var mt = (lon + α) * SECS_PER_DEGREE * 180 / Math.PI - th0;
161 return mt;
162}
163
164/**
165 * @param {number} Th0 - sidereal.apparent0UT in seconds of day `[0...86400[`
166 * @param {number} m - motion in seconds of day `[0...86400[`
167 * @return {number} new siderial time seconds of day `[0...86400[`
168 */
169function _th0(Th0, m) {
170 // in original formula Th0 = 0...360 and m = 0...1 -> return value would be in 0...360 degrees
171 // Th0 /= 240
172 // m /= 86400
173 var th0 = _base2.default.pmod(Th0 + m * 360.985647 / 360, SECS_PER_DAY); // p103
174 return th0; // 0...86400 in seconds angle
175}
176
177// maintain backward compatibility - will be removed in v2
178// return value in future will be an object not an array
179function _compatibility(rs) {
180 var _rs = [rs.rise, rs.transit, rs.set];
181 _rs.rise = rs.rise;
182 _rs.transit = rs.transit;
183 _rs.set = rs.set;
184 return _rs;
185}
186
187/**
188 * ApproxTimes computes approximate UT rise, transit and set times for
189 * a celestial object on a day of interest.
190 *
191 * The function argurments do not actually include the day, but do include
192 * values computed from the day.
193 *
194 * @param {coord.Globe} p - is geographic coordinates of observer.
195 * @param {number} h0 - is "standard altitude" of the body in radians
196 * @param {number} Th0 - is apparent sidereal time at 0h UT at Greenwich in seconds
197 * (range 0...86400) must be the time on the day of interest, in seconds.
198 * See sidereal.apparent0UT
199 * @param {Array<number>} α3 - slices of three right ascensions
200 * @param {Array<number>} δ3 - slices of three declinations.
201 * α3, δ3 must be values at 0h dynamical time for the day before, the day of,
202 * and the day after the day of interest. Units are radians.
203 * @return Result units are seconds and are in the range [0,86400)
204 * @throws Error
205 */
206function _approxTimes(p, h0, Th0, α, δ) {
207 var H0 = hourAngle(p.lat, h0, δ) * SECS_PER_DEGREE * 180 / Math.PI; // in degrees per day === seconds
208 // approximate transit, rise, set times.
209 // (15.2) p. 102.0
210 var mt = _mt(p.lon, α, Th0);
211 var rs = {};
212 rs.transit = _base2.default.pmod(mt, SECS_PER_DAY);
213 rs.rise = _base2.default.pmod(mt - H0, SECS_PER_DAY);
214 rs.set = _base2.default.pmod(mt + H0, SECS_PER_DAY);
215 return _compatibility(rs);
216}
217
218/**
219 * Times computes UT rise, transit and set times for a celestial object on
220 * a day of interest.
221 *
222 * The function argurments do not actually include the day, but do include
223 * a number of values computed from the day.
224 *
225 * @param {coord.Globe} p - is geographic coordinates of observer.
226 * @param {number} ΔT - is delta T in seconds
227 * @param {number} h0 - is "standard altitude" of the body in radians
228 * @param {number} Th0 - is apparent sidereal time at 0h UT at Greenwich in seconds
229 * (range 0...86400) must be the time on the day of interest, in seconds.
230 * See sidereal.apparent0UT
231 * @param {Array<number>} α3 - slices of three right ascensions
232 * @param {Array<number>} δ3 - slices of three declinations.
233 * α3, δ3 must be values at 0h dynamical time for the day before, the day of,
234 * and the day after the day of interest. Units are radians.
235 *
236 * @return Result units are seconds and are in the range [0,86400)
237 * @throws Error
238 */
239exports.approxTimes = _approxTimes;
240function _times(p, ΔT, h0, Th0, α3, δ3) {
241 // (p globe.Coord, ΔT, h0, Th0 float64, α3, δ3 []float64) (mRise, mTransit, mSet float64, err error)
242 var rs = _approxTimes(p, h0, Th0, α3[1], δ3[1]);
243 var d3α = new _interpolation2.default.Len3(-SECS_PER_DAY, SECS_PER_DAY, α3);
244 var d3δ = new _interpolation2.default.Len3(-SECS_PER_DAY, SECS_PER_DAY, δ3);
245
246 // adjust mTransit
247 var ut = rs.transit + ΔT;
248 var α = d3α.interpolateX(ut);
249 var th0 = _th0(Th0, rs.transit);
250 var H = -1 * _mt(p.lon, α, th0); // in secs // Hmeus = 0...360
251 rs.transit -= H;
252
253 // adjust mRise, mSet
254
255 var _base$sincos = _base2.default.sincos(p.lat),
256 _base$sincos2 = _slicedToArray(_base$sincos, 2),
257 sLat = _base$sincos2[0],
258 cLat = _base$sincos2[1];
259
260 var adjustRS = function adjustRS(m) {
261 var ut = m + ΔT;
262 var α = d3α.interpolateX(ut);
263 var δ = d3δ.interpolateX(ut);
264 var th0 = _th0(Th0, m);
265 var H = -1 * _mt(p.lon, α, th0);
266 var Hrad = H / SECS_PER_DEGREE * D2R;
267 var h = asin(sLat * sin(δ) + cLat * cos(δ) * cos(Hrad)); // formula 13.6
268 var Δm = SECS_PER_DAY * (h - h0) / (cos(δ) * cLat * sin(Hrad) * 2 * Math.PI); // formula p103 3
269 return m + Δm;
270 };
271
272 rs.rise = adjustRS(rs.rise);
273 rs.set = adjustRS(rs.set);
274
275 return _compatibility(rs);
276}
277
278/**
279 * RisePlanet computes rise, transit and set times for a planet on a day of interest.
280 */
281exports.times = _times;
282
283var PlanetRise = exports.PlanetRise = function () {
284 /**
285 * @param {number|Date} jd - Julian Day starting at midnight or Date object
286 * @param {number} lat - geographic latitude of the observerin degrees
287 * @param {number} lon - geographic longitude of the observer in degrees (measured positively westward)
288 * @param {planetposition.Planet} earth - VSOP87 Planet object for Earth
289 * @param {planetposition.Planet} planet - VSOP87 Planet object of observed body
290 * @param {object} opts
291 * @param {boolean} opts.date - return times as Date objects
292 * @param {number} opts.refraction - use different refraction than `stdh0Stellar`
293 */
294 function PlanetRise(jd, lat, lon, earth, planet, opts) {
295 _classCallCheck(this, PlanetRise);
296
297 this.opts = opts || {};
298 this.refraction = this.opts.refraction || stdh0Stellar();
299 if (jd instanceof Date) {
300 jd = new _julian2.default.Calendar().fromDate(jd).toJD();
301 }
302 this.jd = Math.floor(jd - 0.5) + 0.5; // start at midnight
303 this.lat = lat * D2R; // convert to radians
304 this.lon = lon * D2R;
305 var cal = new _julian2.default.Calendar().fromJD(this.jd);
306 this.jde = cal.toJDE();
307 this.ΔT = _deltat2.default.deltaT(cal.toYear());
308 this.earth = earth;
309 this.planet = planet;
310 }
311
312 _createClass(PlanetRise, [{
313 key: 'approxTimes',
314 value: function approxTimes() {
315 var body = _elliptic2.default.position(this.planet, this.earth, this.jde);
316 var Th0 = _sidereal2.default.apparent0UT(this.jd);
317 var rs = _approxTimes({ lat: this.lat, lon: this.lon }, this.refraction, Th0, body.ra, body.dec);
318 return this._rsToJD(rs);
319 }
320 }, {
321 key: 'times',
322 value: function times() {
323 var body = [_elliptic2.default.position(this.planet, this.earth, this.jde - 1), _elliptic2.default.position(this.planet, this.earth, this.jde), _elliptic2.default.position(this.planet, this.earth, this.jde + 1)];
324 var Th0 = _sidereal2.default.apparent0UT(this.jd);
325 var rs = _times({ lat: this.lat, lon: this.lon }, this.ΔT, this.refraction, Th0, this._toArr(body, 'ra'), this._toArr(body, 'dec'));
326 return this._rsToJD(rs);
327 }
328 /** @private */
329
330 }, {
331 key: '_toArr',
332 value: function _toArr(body, p) {
333 return body.map(function (item) {
334 return item[p];
335 });
336 }
337 /** @private */
338
339 }, {
340 key: '_rsToJD',
341 value: function _rsToJD(rs) {
342 return {
343 rise: this._toJD(rs.rise),
344 transit: this._toJD(rs.transit),
345 set: this._toJD(rs.set)
346 };
347 }
348 /** @private */
349
350 }, {
351 key: '_toJD',
352 value: function _toJD(secs) {
353 var jd = this.jd + secs / 86400;
354 if (this.opts.date) {
355 return new _julian2.default.Calendar().fromJD(jd).toDate();
356 } else {
357 return jd;
358 }
359 }
360 }]);
361
362 return PlanetRise;
363}();
364
365exports.default = {
366 errorAboveHorizon: errorAboveHorizon,
367 errorBelowHorizon: errorBelowHorizon,
368 meanRefraction: meanRefraction,
369 stdh0: stdh0,
370 refraction: refraction,
371 stdh0Stellar: stdh0Stellar,
372 Stdh0Stellar: Stdh0Stellar,
373 stdh0Solar: stdh0Solar,
374 Stdh0Solar: Stdh0Solar,
375 stdh0LunarMean: stdh0LunarMean,
376 Stdh0LunarMean: Stdh0LunarMean,
377 stdh0Lunar: stdh0Lunar,
378 Stdh0Lunar: Stdh0Lunar,
379 hourAngle: hourAngle,
380 approxTimes: _approxTimes,
381 times: _times,
382 PlanetRise: PlanetRise
383};
\No newline at end of file