1 | export { _approxTimes as approxTimes };
|
2 | export { _times as times };
|
3 |
|
4 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | import base from './base';
|
18 | import deltat from './deltat';
|
19 | import elliptic from './elliptic';
|
20 | import interp from './interpolation';
|
21 | import julian from './julian';
|
22 | import sexa from './sexagesimal';
|
23 | import sidereal from './sidereal';
|
24 | var acos = Math.acos,
|
25 | asin = Math.asin,
|
26 | cos = Math.cos,
|
27 | sin = Math.sin;
|
28 |
|
29 |
|
30 | var SECS_PER_DEGREE = 240;
|
31 | var SECS_PER_DAY = 86400;
|
32 | var D2R = Math.PI / 180;
|
33 |
|
34 | export var errorAboveHorizon = base.errorCode('always above horizon', -1);
|
35 | export var errorBelowHorizon = base.errorCode('always below horizon', 1);
|
36 |
|
37 |
|
38 |
|
39 |
|
40 | export var meanRefraction = new sexa.Angle(false, 0, 34, 0).rad();
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 | export var stdh0 = {
|
49 | stellar: -meanRefraction,
|
50 | solar: new sexa.Angle(true, 0, 50, 0).rad(),
|
51 |
|
52 | lunar: new sexa.Angle(false, 0, 0, 0.7275).rad(),
|
53 | lunarMean: new sexa.Angle(false, 0, 0, 0.125).rad()
|
54 |
|
55 | |
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 | };export function refraction(h0, corr) {
|
62 | if (!corr) {
|
63 | return h0;
|
64 | } else {
|
65 | return h0 - meanRefraction - corr;
|
66 | }
|
67 | }
|
68 |
|
69 |
|
70 |
|
71 |
|
72 | export var stdh0Stellar = function stdh0Stellar(_refraction) {
|
73 | return refraction(stdh0.stellar, _refraction);
|
74 | };
|
75 | export var Stdh0Stellar = stdh0Stellar();
|
76 |
|
77 |
|
78 |
|
79 | export var stdh0Solar = function stdh0Solar(_refraction) {
|
80 | return refraction(stdh0.solar, _refraction);
|
81 | };
|
82 | export var Stdh0Solar = stdh0Solar();
|
83 |
|
84 |
|
85 |
|
86 |
|
87 | export var stdh0LunarMean = function stdh0LunarMean(_refraction) {
|
88 | return stdh0.lunarMean - refraction(_refraction);
|
89 | };
|
90 | export var Stdh0LunarMean = stdh0LunarMean();
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 | export var stdh0Lunar = function stdh0Lunar(π, refraction) {
|
100 | refraction = refraction || meanRefraction;
|
101 | return stdh0.lunar * π - refraction;
|
102 | };
|
103 | export var Stdh0Lunar = stdh0Lunar;
|
104 |
|
105 |
|
106 |
|
107 |
|
108 | export function hourAngle(lat, h0, δ) {
|
109 |
|
110 | var cosH = (sin(h0) - sin(lat) * sin(δ)) / (cos(lat) * cos(δ));
|
111 | if (cosH < -1) {
|
112 | throw errorAboveHorizon;
|
113 | } else if (cosH > 1) {
|
114 | throw errorBelowHorizon;
|
115 | }
|
116 | var H = acos(cosH);
|
117 | return H;
|
118 | }
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 |
|
126 | function _mt(lon, α, th0) {
|
127 |
|
128 | var mt = (lon + α) * SECS_PER_DEGREE * 180 / Math.PI - th0;
|
129 | return mt;
|
130 | }
|
131 |
|
132 |
|
133 |
|
134 |
|
135 |
|
136 |
|
137 | function _th0(Th0, m) {
|
138 |
|
139 |
|
140 |
|
141 | var th0 = base.pmod(Th0 + m * 360.985647 / 360, SECS_PER_DAY);
|
142 | return th0;
|
143 | }
|
144 |
|
145 |
|
146 |
|
147 | function _compatibility(rs) {
|
148 | var _rs = [rs.rise, rs.transit, rs.set];
|
149 | _rs.rise = rs.rise;
|
150 | _rs.transit = rs.transit;
|
151 | _rs.set = rs.set;
|
152 | return _rs;
|
153 | }
|
154 |
|
155 |
|
156 |
|
157 |
|
158 |
|
159 |
|
160 |
|
161 |
|
162 |
|
163 |
|
164 |
|
165 |
|
166 |
|
167 |
|
168 |
|
169 |
|
170 |
|
171 |
|
172 |
|
173 |
|
174 | function _approxTimes(p, h0, Th0, α, δ) {
|
175 | var H0 = hourAngle(p.lat, h0, δ) * SECS_PER_DEGREE * 180 / Math.PI;
|
176 |
|
177 |
|
178 | var mt = _mt(p.lon, α, Th0);
|
179 | var rs = {};
|
180 | rs.transit = base.pmod(mt, SECS_PER_DAY);
|
181 | rs.rise = base.pmod(mt - H0, SECS_PER_DAY);
|
182 | rs.set = base.pmod(mt + H0, SECS_PER_DAY);
|
183 | return _compatibility(rs);
|
184 | }
|
185 |
|
186 |
|
187 |
|
188 |
|
189 |
|
190 |
|
191 |
|
192 |
|
193 |
|
194 |
|
195 |
|
196 |
|
197 |
|
198 |
|
199 |
|
200 |
|
201 |
|
202 |
|
203 |
|
204 |
|
205 |
|
206 |
|
207 | function _times(p, ΔT, h0, Th0, α3, δ3) {
|
208 |
|
209 | var rs = _approxTimes(p, h0, Th0, α3[1], δ3[1]);
|
210 | var d3α = new interp.Len3(-SECS_PER_DAY, SECS_PER_DAY, α3);
|
211 | var d3δ = new interp.Len3(-SECS_PER_DAY, SECS_PER_DAY, δ3);
|
212 |
|
213 |
|
214 | var ut = rs.transit + ΔT;
|
215 | var α = d3α.interpolateX(ut);
|
216 | var th0 = _th0(Th0, rs.transit);
|
217 | var H = -1 * _mt(p.lon, α, th0);
|
218 | rs.transit -= H;
|
219 |
|
220 |
|
221 |
|
222 | var _base$sincos = base.sincos(p.lat),
|
223 | sLat = _base$sincos[0],
|
224 | cLat = _base$sincos[1];
|
225 |
|
226 | var adjustRS = function adjustRS(m) {
|
227 | var ut = m + ΔT;
|
228 | var α = d3α.interpolateX(ut);
|
229 | var δ = d3δ.interpolateX(ut);
|
230 | var th0 = _th0(Th0, m);
|
231 | var H = -1 * _mt(p.lon, α, th0);
|
232 | var Hrad = H / SECS_PER_DEGREE * D2R;
|
233 | var h = asin(sLat * sin(δ) + cLat * cos(δ) * cos(Hrad));
|
234 | var Δm = SECS_PER_DAY * (h - h0) / (cos(δ) * cLat * sin(Hrad) * 2 * Math.PI);
|
235 | return m + Δm;
|
236 | };
|
237 |
|
238 | rs.rise = adjustRS(rs.rise);
|
239 | rs.set = adjustRS(rs.set);
|
240 |
|
241 | return _compatibility(rs);
|
242 | }
|
243 |
|
244 |
|
245 |
|
246 |
|
247 | export var PlanetRise = function () {
|
248 | |
249 |
|
250 |
|
251 |
|
252 |
|
253 |
|
254 |
|
255 |
|
256 |
|
257 |
|
258 | function PlanetRise(jd, lat, lon, earth, planet, opts) {
|
259 | _classCallCheck(this, PlanetRise);
|
260 |
|
261 | this.opts = opts || {};
|
262 | this.refraction = this.opts.refraction || stdh0Stellar();
|
263 | if (jd instanceof Date) {
|
264 | jd = new julian.Calendar().fromDate(jd).toJD();
|
265 | }
|
266 | this.jd = Math.floor(jd - 0.5) + 0.5;
|
267 | this.lat = lat * D2R;
|
268 | this.lon = lon * D2R;
|
269 | var cal = new julian.Calendar().fromJD(this.jd);
|
270 | this.jde = cal.toJDE();
|
271 | this.ΔT = deltat.deltaT(cal.toYear());
|
272 | this.earth = earth;
|
273 | this.planet = planet;
|
274 | }
|
275 |
|
276 | PlanetRise.prototype.approxTimes = function approxTimes() {
|
277 | var body = elliptic.position(this.planet, this.earth, this.jde);
|
278 | var Th0 = sidereal.apparent0UT(this.jd);
|
279 | var rs = _approxTimes({ lat: this.lat, lon: this.lon }, this.refraction, Th0, body.ra, body.dec);
|
280 | return this._rsToJD(rs);
|
281 | };
|
282 |
|
283 | PlanetRise.prototype.times = function times() {
|
284 | var body = [elliptic.position(this.planet, this.earth, this.jde - 1), elliptic.position(this.planet, this.earth, this.jde), elliptic.position(this.planet, this.earth, this.jde + 1)];
|
285 | var Th0 = sidereal.apparent0UT(this.jd);
|
286 | var rs = _times({ lat: this.lat, lon: this.lon }, this.ΔT, this.refraction, Th0, this._toArr(body, 'ra'), this._toArr(body, 'dec'));
|
287 | return this._rsToJD(rs);
|
288 | };
|
289 |
|
290 |
|
291 |
|
292 | PlanetRise.prototype._toArr = function _toArr(body, p) {
|
293 | return body.map(function (item) {
|
294 | return item[p];
|
295 | });
|
296 | };
|
297 |
|
298 |
|
299 |
|
300 | PlanetRise.prototype._rsToJD = function _rsToJD(rs) {
|
301 | return {
|
302 | rise: this._toJD(rs.rise),
|
303 | transit: this._toJD(rs.transit),
|
304 | set: this._toJD(rs.set)
|
305 | };
|
306 | };
|
307 | /** @private */
|
308 |
|
309 |
|
310 | PlanetRise.prototype._toJD = function _toJD(secs) {
|
311 | var jd = this.jd + secs / 86400;
|
312 | if (this.opts.date) {
|
313 | return new julian.Calendar().fromJD(jd).toDate();
|
314 | } else {
|
315 | return jd;
|
316 | }
|
317 | };
|
318 |
|
319 | return PlanetRise;
|
320 | }();
|
321 |
|
322 | export default {
|
323 | errorAboveHorizon: errorAboveHorizon,
|
324 | errorBelowHorizon: errorBelowHorizon,
|
325 | meanRefraction: meanRefraction,
|
326 | stdh0: stdh0,
|
327 | refraction: refraction,
|
328 | stdh0Stellar: stdh0Stellar,
|
329 | Stdh0Stellar: Stdh0Stellar,
|
330 | stdh0Solar: stdh0Solar,
|
331 | Stdh0Solar: Stdh0Solar,
|
332 | stdh0LunarMean: stdh0LunarMean,
|
333 | Stdh0LunarMean: Stdh0LunarMean,
|
334 | stdh0Lunar: stdh0Lunar,
|
335 | Stdh0Lunar: Stdh0Lunar,
|
336 | hourAngle: hourAngle,
|
337 | approxTimes: _approxTimes,
|
338 | times: _times,
|
339 | PlanetRise: PlanetRise
|
340 | }; |
\ | No newline at end of file |