-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
1270 lines (1096 loc) · 44 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* © Alfred-Wegener-Institute Bremerhaven, Germany (2022)
* @link https://awi.de
*
* @author Benjamin Thomas Schwertfeger (2022)
* @email benjamin.schwertfeger@awi.de
* @email development@b-schwertfeger.de
* @link https://b-schwertfeger.de
* @link https://github.com/btschwertfeger/Orbit-astronomical-theory-of-ice-ages-Website
* required: https://github.com/scijs/modified-newton-raphson
* sudo watchify main.js -o main_bundle.js
**/
const newton = require('modified-newton-raphson');
const utils = require('./utils')
$(document).ready(() => {
document.getElementById('dayval').innerHTML = utils.dateFromDay(2021, parseInt(document.getElementById('orbital_day_slide').value));
// === Load orbital parameters (given each kyr for 0-5Mya) ===
// Load the matrix contains data from Berger and Loutre (1991)
$.ajax({
type: 'GET',
url: 'orbital_param.csv',
dataType: 'text',
success: (data) => {
const kyear = [...new Array(TIMESTEPS)].map((elem, index) => index / 10);
processData(data, kyear);
}
});
});
function processData(allText, kyear) {
let allTextLines = allText.split(/\r\n|\n/);
let
headers = allTextLines[0].split(' '),
kyear0 = new Array(0),
ecc0 = new Array(0),
epsilon0 = new Array(0),
omega0 = new Array(0);
for (let i = 1; i < allTextLines.length; i++) {
let data = allTextLines[i].split(' ');
for (let j = 0; j < headers.length; j++) {
switch (j) {
case 0:
kyear0.push(-parseInt(data[j]));
break;
case 1:
ecc0.push(parseFloat(data[j])); // eccentricity
break;
case 2:
// longitude of perihelion (precession angle)
// add 180 degrees to omega (see lambda definition, Berger 1978 Appendix)
omega0.push(parseFloat(data[j]) + 180);
break;
case 3:
epsilon0.push(parseFloat(data[j]));
}
}
}
// remove discontinuities(360 degree jumps)
omega0 = unwrap(omega0.map((elem) => elem * Math.PI / 180)).map((elem) => elem * 180 / Math.PI);
for (let i = 0; i < TIMESTEPS; i++) {
window.orbital_global.ecc.push(ecc0[i]);
window.orbital_global.omega.push(omega0[i] * Math.PI / 180);
window.orbital_global.epsilon.push(epsilon0[i] * Math.PI / 180);
}
plotALL(null, true); // line plots (parameter: data<null>, init<true>)
plot_contour_1();
plot_contour_2();
plot_contour_3();
}
/**
* ============================================================
____ _ _ _
/ ___|___ _ __ ___ _ __ _ _| |_ __ _| |_(_) ___ _ __
| | / _ \| '_ ` _ \| '_ \| | | | __/ _` | __| |/ _ \| '_ \
| |__| (_) | | | | | | |_) | |_| | || (_| | |_| | (_) | | | |
\____\___/|_| |_| |_| .__/ \__,_|\__\__,_|\__|_|\___/|_| |_|
|_|
*/
/**
* Computes the days per months based on eccentricity and longp
* @param {*} epsilon
* @param {*} VE
* @returns
*/
function calendar(epsilon, VE, int = true) {
VE = 2 * Math.PI - (VE * 2 * Math.PI / 360);
const VE_mod = 282.157 * 2 * Math.PI / 360;
let
times = [...new Array(13)].map(() => 0), // np.zeros(13)
laengen_dec = [...new Array(12)].map(() => 0), // np.zeros(12)
angles = utils.arange(0, 2 * Math.PI + Math.PI / 6, Math.PI / 6);
let n = times.length;
/**
* Two fundamental functions: 'day' and 'ang'.
'day': For a given angle (seen from perihelion), 'day' returns the time elapsed since perihelion.
'ang': For a given time (seen from perihelion), 'ang' returns the angle (seen from perihelion.
*/
const
day = (phi) => {
const exzAn = 2 * Math.atan(Math.pow(((1 - epsilon) / (1 + epsilon)), 0.5) * Math.tan(phi / 2));
const M = exzAn - epsilon * Math.sin(exzAn);
return M * 365.25 / (2 * Math.PI);
},
ang = (t, t0 = 0) => {
const M = 2 * Math.PI / 365.25 * (t - t0);
const
exz = (E) => { return E - epsilon * Math.sin(E) - M; },
exzprime = (E) => { return 1 - epsilon * Math.cos(E); },
exz2prime = (E) => { return epsilon * Math.cos(E); };
const exzAn = newton(
exz,
exzprime,
exz2prime,
(2 * Math.PI * (t - t0) / 365.25),
{
tolerance: Math.pow(10, -5)
}
)
const phi = 2 * Math.atan(Math.pow(((1 + epsilon) / (1 - epsilon)), 0.5) * Math.tan(exzAn / 2));
return phi;
};
/**
* Shift to April 1st:
For calculating the months, the starting day has to be shifted from the day of the VE (fixed at March 21st) to April 1st.
Since the time between nowadays March 21st and April 1st may not be true for past calendars,
we define April 1st by the angle.
Therefore we calculate the angle between nowadays March 21st, noon and the 10.5 days-later-April 1st and afterwards
calculate the day of April 1st for the past calendar.
´*/
const tVE_mod = day(VE_mod); //day of modern VE
const phi14_mod = ang(tVE_mod + 10.5) - VE_mod; //angle between modern VE and April 1st
const tVE = day(VE); // time of pas VE
const t14 = day(VE + phi14_mod); // time of past April 1st, defined by the angle
// shifts the days s.t. the first month starts at April 1st
for (let w = 0; w < n; w++) {
times[w] = day(VE + angles[w]) - tVE;
times[w] = day(VE + phi14_mod + angles[w]) - tVE - t14;
}
// from month starting day April 1st, calculate monthly lengths. Nothin has been rounded yet.
for (let i in utils.arange(0, n - 3, 1)) {
i = parseInt(i)
const r = (times[i + 1] - times[i]);
laengen_dec[i] = ((r % 365) + 365) % 365; // javascript modulo bug for negative numbers.. this is how to avoid
}
// change to right order: January, February, ....
const sort_by_index = (arr, indices) => {
if (arr.length != indices.length) throw Error('Invalid lengths to sort.');
const n = arr.length;
let out_arr = [...new Array(n)];
for (let i = 0; i < n; i++) {
// print(i, arr[i], '->', )
out_arr[i] = arr[indices[i]];
}
return out_arr;
};
laengen_dec = sort_by_index(laengen_dec, [9, 10, 11, 0, 1, 2, 3, 4, 5, 6, 7, 8]);
/**
* Use the 'largest remainder method' for rounding: Each month gets his 'interger-part'-number of days, the remaining
(365-sum of all integer part) days are distributed by the size of the month's decimal parts.
Doing this, every year gets 365 days and they are reasonable distributed.
*/
if (!int) return laengen_dec;
let
laengen_int = [...new Array(laengen_dec.length)],
dec = [...new Array(laengen_dec.length)];
for (let i = 0; i < dec.length; i++) {
const result = utils.divmod(laengen_dec[i], 1);
laengen_int[i] = result[0];
dec[i] = result[1];
}
let ges = laengen_int.reduce((a, b) => {
return parseInt(a + b);
});
for (let _ in utils.arange(0, 365 - ges - 2, 1)) {
const k = utils.argMax(dec);
laengen_int[k] = laengen_int[k] + 1;
ges += 1;
dec[k] = 0
}
return laengen_int;
}
const
FONT_FAMILY = 'Helvetica',
TIMESTEPS = 5000;
window.orbital_global = {
kyear0: new Array(),
ecc: new Array(),
epsilon: new Array(),
omega: new Array()
};
function unwrap(p) {
// Q = unwrap(P) corrects the radian phase angles in array P by adding multiples of ±2pi when absolute jumps between consecutive array elements are greater than pi radians.
// based on http://ccrma.stanford.edu/~jos/sasp/Matlab_listing_unwrap_m.html
let N = p.length;
let
up = [...new Array(N)].map(() => 0),
pm1 = p[0];
up[0] = pm1;
let po = 0,
thr = Math.PI,
pi2 = 2 * Math.PI;
for (let i = 1; i < N; i++) {
let cp = p[i] + po;
let dp = cp - pm1;
pm1 = cp;
if (dp >= thr) {
while (dp >= thr) {
po = po - pi2;
dp = dp - pi2;
}
}
if (dp <= ((-1) * thr)) {
while (dp <= thr) {
po = po + pi2;
dp = dp + pi2;
}
}
cp = p[i] + po
pm1 = cp
up[i] = cp
}
return up
}
function tlag(data, ilag) {
let temp = utils.rep(data, 3);
for (let i = 366; i < 731; i++) {
temp[i] -= ilag;
}
return temp
}
// Cover functions to return the daily insolation, either using a classical calendar (aligned with March21) or using an alignment with Dec21 summer solstice
function insolMarch21(kyear, LAT) {
let res = new Array(0);
for (let day = 1; day < 365 + 1; day++) {
res.push(daily_insolation(kyear, LAT, day).Fsw);
}
return res;
}
function insolDec21(kyear, LAT) {
let res = {
Fsw: new Array(0),
lambda: new Array(0),
};
for (let day = 1; day < 365 + 1; day++) { //Eigentlich passt 356 besser
let tmp = daily_insolation(kyear, LAT, day);
res.Fsw.push(tmp.Fsw);
res.lambda.push(tmp.lambda);
}
//let shift = 355 - Math.min.apply(Math, res.lambda.map((elem) => Math.abs(elem - 270))); //dann entprechend hinschieben
const min = Math.min.apply(Math, res.lambda.map((elem) => Math.abs(elem - 270)));
for (let i = 0; i < res.lambda.length; i++) {
if (res.lambda[i] == min)
return tlag(res.Fsw, 355 - i);
}
return tlag(res.Fsw, shift);
}
function insolDec21_param(ecc, obliquity, long_perh, LAT) {
let res = {
Fsw: new Array(0),
lambda: new Array(0),
};
for (let day = 1; day < 365 + 1; day++) {
let tmp = daily_insolation_param(LAT, day, ecc, obliquity, long_perh);
res.Fsw.push(tmp.Fsw);
res.lambda.push(tmp.lambda);
}
let shift = 355 - Math.min.apply(Math, res.lambda.map((elem) => Math.abs(elem - 270))); // which.min(abs(r.lambda - 270)) //dann entprechend hinschieben1
return tlag(res.Fsw, shift)
}
function daily_insolation_param(lat, day, ecc, obliquity, long_perh, day_type = 1) {
/* Insolation, converted and adapted from Huybers Code, based on Berger 1991
Description:
Computes daily average insolation as a function of day and latitude at
any point during the past 5 million years.
Inputs:
kyear: Thousands of years before present (0 to 5000).
lat: Latitude in degrees (-90 to 90).
day: Indicator of time of year; calendar day by default.
day_type: Convention for specifying time of year (+/- 1,2) [optional].
day_type=1 (default): day input is calendar day (1-365.24), where day 1
is January first. The calendar is referenced to the vernal equinox
which always occurs at day 80.
day_type=2: day input is solar longitude (0-360 degrees). Solar
longitude is the angle of the Earth's orbit measured from spring
equinox (21 March). Note that calendar days and solar longitude are
not linearly related because, by Kepler's Second Law, Earth's
angular velocity varies according to its distance from the sun.
Output:
Fsw = Daily average solar radiation in W/m^2.
Can also output orbital parameters.
This script contains orbital parameter data for the past 50000 years
from Berger and Loutre (1991).
Detailed description of calculation:
Values for eccentricity, obliquity, and longitude of perihelion for the
past 5 Myr are taken from Berger and Loutre 1991 (data from
ncdc.noaa.gov). If using calendar days, solar longitude is found using an
approximate solution to the differential equation representing conservation
of angular momentum (Kepler's Second Law). Given the orbital parameters
and solar longitude, daily average insolation is calculated exactly
following Berger 1978.
References:
Berger A. and Loutre M.F. (1991). Insolation values for the climate of
the last 10 million years. Quaternary Science Reviews, 10(4), 297-317.
Berger A. (1978). Long-term variations of daily insolation and
Quaternary climatic changes. Journal of Atmospheric Science, 35(12),
2362-2367.
Authors:
Ian Eisenman and Peter Huybers, Harvard University, August 2006
eisenman@fas.harvard.edu
This file is available online at
http://deas.harvard.edu/~eisenman/downloads
Translated into JavaScript by Benjamin Thomas Schwertfeger
Suggested citation:
P. Huybers and I. Eisenman, 2006. Integrated summer insolation
calculations. NOAA/NCDC Paleoclimatology Program Data
Contribution #2006-079.
*/
// // === Get orbital parameters ===
// let epsilon = obliquity * Math.PI / 180;
// let omega = long_perh * Math.PI / 180;
// // === Calculate insolation ===
// lat = lat * Math.PI / 180 // latitude
// // lambda (or solar longitude) is the angular distance along Earth's orbit measured from spring equinox (21 March)
// let lambda = null;
// if (day_type === 1) { // calendar days
// // estimate lambda from calendar day using an approximation from Berger 1978 section 3
// let delta_lambda_m = (day[i] - 80) * 2 * Math.PI / 365.2422; // lambda bei gleich langen Tagen
// let beta = Math.pow((1 - Math.pow(ecc, 2)), 1 / 2);
// let lambda_m0 = (-2) * ((1 / 2 * ecc + 1 / 8 * Math.pow(ecc, 3)) * (1 + beta) * Math.sin(-omega) - 1 / 4 * Math.pow(ecc, 2) * (1 / 2 + beta) * Math.sin(-2 * omega) + 1 / 8 * Math.pow(ecc, 3) * (1 / 3 + beta) * (Math.sin(-3 * omega)));
// let lambda_m = lambda_m0 + delta_lambda_m;
// lambda = lambda_m + (2 * ecc - 1 / 4 * Math.pow(ecc, 3)) * Math.sin(lambda_m - omega) + (5 / 4) * Math.pow(ecc, 2) * Math.sin(2 * (lambda_m - omega)) + (13 / 12) * Math.pow(ecc, 3) * Math.sin(3 * (lambda_m - omega));
// } else if (day_type === 2) { // solar longitude (1-360)
// lambda = day[i] * 2 * Math.PI / 360; // lambda=0 for spring equinox
// } else console.log('was geschieht hier?');
// let So = 1365; // solar constant (W/m^2)
// let delta = Math.asin(Math.sin(epsilon) * Math.sin(lambda)); // declination of the sun
// let Ho = Math.acos(-Math.tan(lat) * Math.tan(delta)); // hour angle at sunrise/sunset
// // no sunrise or no sunset: Berger 1978 eqn(8), (9)
// if ((Math.abs(lat) >= Math.PI / 2 - Math.abs(delta)) && (lat * delta > 0)) Ho = Math.PI;
// else Ho = 0;
// // Insolation: Berger 1978 eq(10)
// let Fsw = So / Math.PI * Math.pow((1 + ecc * Math.cos(lambda - omega)), 2) / Math.pow((1 - Math.pow(ecc, 2)), 2) * (Ho * Math.sin(lat) * Math.sin(delta) + Math.cos(lat) * Math.cos(delta) * Math.sin(Ho));
// return {
// Fsw: Fsw,
// ecc: ecc,
// obliquity: obliquity,
// long_perh: long_perh,
// lambda: lambda / 2 / Math.PI * 360
// };
return compute(ecc, obliquity, long_perh, lat, day, day_type);
}
function daily_insolation(kyear, lat, day, day_type = 1, fast = true) {
/* CALCULATE DAILY INSOLATION
Description:
Computes daily average insolation as a function of day and latitude at
any point during the past 5 million years.
Inputs:
kyear: Thousands of years before present (0 to 5000).
lat: Latitude in degrees (-90 to 90).
day: Indicator of time of year; calendar day by default.
day_type: Convention for specifying time of year (+/- 1,2) [optional].
day_type=1 (default): day input is calendar day (1-365.24), where day 1
is January first. The calendar is referenced to the vernal equinox
which always occurs at day 80.
day_type=2: day input is solar longitude (0-360 degrees). Solar
longitude is the angle of the Earth's orbit measured from spring
equinox (21 March). Note that calendar days and solar longitude are
not linearly related because, by Kepler's Second Law, Earth's
angular velocity varies according to its distance from the sun.
Output:
Fsw = Daily average solar radiation in W/m^2.
Can also output orbital parameters.
This script contains orbital parameter data for the past 50000 years
from Berger and Loutre (1991).
Detailed description of calculation:
Values for eccentricity, obliquity, and longitude of perihelion for the
past 5 Myr are taken from Berger and Loutre 1991 (data from
ncdc.noaa.gov). If using calendar days, solar longitude is found using an
approximate solution to the differential equation representing conservation
of angular momentum (Kepler's Second Law). Given the orbital parameters
and solar longitude, daily average insolation is calculated exactly
following Berger 1978.
References:
Berger A. and Loutre M.F. (1991). Insolation values for the climate of
the last 10 million years. Quaternary Science Reviews, 10(4), 297-317.
Berger A. (1978). Long-term variations of daily insolation and
Quaternary climatic changes. Journal of Atmospheric Science, 35(12),
2362-2367.
Authors:
Ian Eisenman and Peter Huybers, Harvard University, August 2006
eisenman@fas.harvard.edu
This file is available online at
http://deas.harvard.edu/~eisenman/downloads
Translated into JavaScript by Benjamin Thomas Schwertfeger
Suggested citation:
P. Huybers and I. Eisenman, 2006. Integrated summer insolation
calculations. NOAA/NCDC Paleoclimatology Program Data
Contribution #2006-079.
*/
// === Get orbital parameters ===
let temp = {};
if (fast) temp = orbital_parameters_fast(kyear)
else {
temp.ecc = window.orbital_global.ecc[kyear]
temp.epsilon = window.orbital_global.epsilon[kyear]
temp.omega = window.orbital_global.omega[kyear]
}
let
ecc = temp.ecc,
epsilon = temp.epsilon,
omega = temp.omega;
// For output of orbital parameters
let
obliquity = epsilon * 180 / Math.PI,
long_perh = omega * 180 / Math.PI;
var x = compute(ecc, obliquity, long_perh, lat, day, day_type)
return x;
}
function compute(ecc, obliquity, long_perh, lat, day, day_type = 1) {
let
epsilon = (obliquity * Math.PI) / 180,
omega = (long_perh * Math.PI) / 180;
// === Calculate insolation ===
lat = lat * Math.PI / 180 // latitude
// lambda(or solar longitude) is the angular distance along Earth 's orbit measured from spring equinox (21 March)
let lambda = null;
if (day_type == 1) { //calendar days
// estimate lambda from calendar day using an approximation from Berger 1978 section 3
const delta_lambda_m = (day - 80) * 2 * Math.PI / 365.2422;
const beta = Math.pow((1 - Math.pow(ecc, 2)), (1 / 2))
const lambda_m0 = (-2) * ((1 / 2 * ecc + 1 / 8 * Math.pow(ecc, 3)) * (1 + beta) * Math.sin(-omega) - 1 / 4 * Math.pow(ecc, 2) * (1 / 2 + beta) * Math.sin(-2 * omega) + 1 / 8 * Math.pow(ecc, 3) * (1 / 3 + beta) * (Math.sin(-3 * omega)))
const lambda_m = lambda_m0 + delta_lambda_m
lambda = lambda_m + (2 * ecc - 1 / 4 * Math.pow(ecc, 3)) * Math.sin(lambda_m - omega) + (5 / 4) * Math.pow(ecc, 2) * Math.sin(2 * (lambda_m - omega)) + (13 / 12) * Math.pow(ecc, 3) * Math.sin(3 * (lambda_m - omega))
} else if (day_type == 2) lambda = day * 2 * Math.PI / 360 // lambda = 0 for spring equinox
else console.log('was geschieht hier?');
let So = 1365; // solar constant(W / m ^ 2)
let delta = Math.asin(Math.sin(epsilon) * Math.sin(lambda)); // declination of the sun
let Ho = Math.acos(-Math.tan(lat) * Math.tan(delta)); // hour angle at sunrise / sunset
// no sunrise or no sunset: Berger 1978 eqn(8), (9)
if (Math.abs(lat) >= (Math.PI / 2 - Math.abs(delta))) {
if (lat * delta > 0) Ho = Math.PI;
else Ho = 0;
}
// Insolation: Berger 1978 eq(10)
//Fsw=So/pi*(1+ecc*cos(lambda-omega))^2 /(1-ecc^2)^2 * ( Ho*sin(lat)*sin(delta) + cos(lat)*cos(delta)*sin(Ho))
let Fsw = So / Math.PI * Math.pow(1 + ecc * Math.cos(lambda - omega), 2) / Math.pow(1 - Math.pow(ecc, 2), 2) * (Ho * Math.sin(lat) * Math.sin(delta) + Math.cos(lat) * Math.cos(delta) * Math.sin(Ho));
return {
Fsw: Fsw,
ecc: ecc,
obliquity: obliquity,
long_perh: long_perh,
lambda: lambda / 2 / Math.PI * 360
};
}
function get_insolation_of_year(year) {
let result = new Array(0);
for (var lat = -90; lat < 90; lat++) {
let inner = new Array(0);
for (var day = 0; day < 365; day++) inner.push(daily_insolation(year, lat, day, 1, false).Fsw);
result.push(inner)
}
return result;
}
function anno_insol_by_param(ecc, obliquity, long_perh) {
// CALCULATIOE INSOLATION by parameter
let result = new Array(0);
for (var lat = -90; lat < 90; lat++) {
var inner = new Array(0);
for (var day = 0; day < 365; day++) inner.push(daily_insolation_param(lat, day, ecc, obliquity, long_perh).Fsw);
result.push(inner);
}
return result;
}
function orbital_parameters_fast(kyear) {
return {
ecc: window.orbital_global.ecc[parseInt(kyear * 10)],
epsilon: window.orbital_global.epsilon[parseInt(kyear * 10)],
omega: window.orbital_global.omega[parseInt(kyear * 10)]
}
}
function get_orbital_parameter(year) {
const
ecc = window.orbital_global.ecc[year],
epsilon = window.orbital_global.epsilon[year],
omega = window.orbital_global.omega[year];
const
obliquity = epsilon * 180 / Math.PI,
long_perh = omega * 180 / Math.PI;
return {
ecc: ecc,
obliquity: obliquity,
long_perh: long_perh,
}
}
/**
_ _ ____ _ _
| | (_)_ __ ___| _ \| | ___ | |_ ___
| | | | '_ \ / _ \ |_) | |/ _ \| __/ __|
| |___| | | | | __/ __/| | (_) | |_\__ \
|_____|_|_| |_|\___|_| |_|\___/ \__|___/
*/
function plotALL(input = null, init = false) {
let
day = 172,
lat = 65;
if (input !== null) day = input.day, lat = input.lat;
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
const time = [...new Array(TIMESTEPS)].map((elem, index) => -index)
let dailyInsolationResult = {
Fsw: new Array(),
ecc: new Array(),
obliquity: new Array(),
lambda: new Array(),
long_perh: new Array()
};
for (let year = 0; year < 5000; year++) {
const res = daily_insolation(year, lat, day, 1, false) // false or true for fast and not fast
dailyInsolationResult.Fsw.push(res.Fsw);
dailyInsolationResult.ecc.push(res.ecc);
dailyInsolationResult.obliquity.push(res.obliquity);
dailyInsolationResult.long_perh.push(res.long_perh);
dailyInsolationResult.lambda.push(res.lambda);
}
let default_config = {
type: 'line',
data: {
labels: time,
datasets: [],
},
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
title: {
display: true,
text: '',
font: {
Family: FONT_FAMILY,
size: 18,
},
},
legend: {
position: 'top',
display: false,
},
tooltip: {
usePointStyle: true,
callbacks: {
labelPointStyle: function (context) {
return {
pointStyle: 'rectRot',
rotation: 0,
};
},
},
},
},
scales: {
x: {
display: true,
title: {
display: true,
text: '',
font: {
family: FONT_FAMILY,
size: 16,
},
},
// reverse: true
},
y: {
display: true,
title: {
display: true,
text: '',
font: {
family: FONT_FAMILY,
size: 16,
},
},
},
},
animations: {
radius: {
duration: 400,
easing: 'linear',
loop: (ctx) => ctx.activate,
},
},
hoverRadius: 8,
hoverBackgroundColor: 'yellow',
interaction: {
mode: 'nearest',
intersect: false,
axis: 'x',
},
},
};
/* ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- */
// 1. PLOT
/* ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- */
const insol5000Data = {
label: 'Insolation for 5.000ky',
data: dailyInsolationResult.Fsw,
fill: false,
borderColor: 'rgb(255, 0, 0)',
pointRadius: 0,
tension: 0.1,
borderWidth: 2
};
document.getElementById('orbital_line_plot_1').remove();
document.getElementById('orbital_line_plot_1_container').innerHTML = '<canvas id=\'orbital_line_plot_1\'></canvas>';
let ctx1 = document.getElementById('orbital_line_plot_1');
let config1 = {
...default_config
};
config1.data.datasets = [insol5000Data];
config1.options.plugins.title.text = 'Insolation for 5.000ky';
config1.options.plugins.legend.display = false;
config1.options.scales.x.title.text = 'ky';
config1.options.scales.y.title.text = 'Insolation';
window.orbital_line_plot_1 = new Chart(ctx1, config1);
/* ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- */
// 2. PLOT
/* ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- */
const insol5000max510 = new Array();
for (let i = 0; i < dailyInsolationResult.Fsw.length; i++) {
if (dailyInsolationResult.Fsw[i] > 510) {
insol5000max510.push(510);
} else {
insol5000max510.push(dailyInsolationResult.Fsw[i]);
}
}
const insol5000max510Data = {
label: 'Insolation for 5.000 ky (y > 510 => 510)',
data: insol5000max510,
fill: false,
borderColor: 'rgb(255, 0, 0)',
pointRadius: 0,
tension: 0.1,
borderWidth: 2
};
const meanOfInsol = utils.avg(insol5000max510);
let meanInsol5000max510Data = {
label: 'Mean',
data: [...new Array(TIMESTEPS)].map(() => meanOfInsol),
borderColor: 'black',
pointRadius: 0,
borderDash: [10, 5],
fill: false,
borderWidth: 1
};
document.getElementById('orbital_line_plot_2').remove();
document.getElementById('orbital_line_plot_2_container').innerHTML = '<canvas id=\'orbital_line_plot_2\'></canvas>';
let ctx2 = document.getElementById('orbital_line_plot_2');
insol5000Data.label = 'Insolation for 5.000ky'
let config2 = {
...default_config
};
config2.data.datasets = [meanInsol5000max510Data, insol5000max510Data];
config2.options.plugins.title.text = 'overflowed, non-linear wave';
config2.options.plugins.legend.display = true;
config2.options.scales.x.title.text = 'ky';
config2.options.scales.y.title.text = 'Wave';
window.orbital_line_plot_2 = new Chart(ctx2, config2);
if (!init) return;
/* ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- */
// 3. PLOT
/* ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- */
// plot(time, ecc.new, col = 'red', type = 'l')
document.getElementById('orbital_line_plot_3').remove();
document.getElementById('orbital_line_plot_3_container').innerHTML = '<canvas id=\'orbital_line_plot_3\'></canvas>';
const ctx3 = document.getElementById('orbital_line_plot_3');
// console.log(dailyInsolationResult.ecc)
const dailyInsol_ecc = {
label: 'Eccentricity',
data: dailyInsolationResult.ecc,
fill: false,
borderColor: 'rgb(255, 0, 0)',
pointRadius: 0,
tension: 0.1,
borderWidth: 2
};
let config3 = {
...default_config
};
config3.data.datasets = [dailyInsol_ecc];
config3.options.plugins.title.text = 'Eccentricity';
config3.options.plugins.legend.display = false;
config3.options.scales.x.title.text = 'ky';
config3.options.scales.y.title.text = 'Eccentricity';
window.orbital_line_plot_3 = new Chart(ctx3, config3);
/* ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- */
// 4. PLOT
/* ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- */
document.getElementById('orbital_line_plot_4').remove();
document.getElementById('orbital_line_plot_4_container').innerHTML = '<canvas id=\'orbital_line_plot_4\'></canvas>';
const ctx4 = document.getElementById('orbital_line_plot_4');
const dailyInsol_obliquity = {
label: 'Obliquity',
data: dailyInsolationResult.obliquity,
fill: false,
borderColor: 'blue',
pointRadius: 0,
tension: 0.1,
borderWidth: 2
};
let config4 = {
...default_config
};
config4.data.datasets = [dailyInsol_obliquity];
config4.options.plugins.title.text = 'Obliquity';
config4.options.plugins.legend.display = false;
config4.options.scales.x.title.text = 'ky';
config4.options.scales.y.title.text = 'Obliquity';
window.orbital_line_plot_4 = new Chart(ctx4, config4);
/* ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- */
// 5. PLOT
/* ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- */
document.getElementById('orbital_line_plot_5').remove();
document.getElementById('orbital_line_plot_5_container').innerHTML = '<canvas id=\'orbital_line_plot_5\'></canvas>';
const ctx5 = document.getElementById('orbital_line_plot_5');
const dailyInsol_lambda = {
label: 'Lambda',
data: dailyInsolationResult.lambda,
fill: false,
borderColor: 'black',
pointRadius: 0,
tension: 0.1,
borderWidth: 2
};
let config5 = {
...default_config
}
config5.data.datasets = [dailyInsol_lambda];
config5.options.plugins.title.text = 'Lambda';
config5.options.plugins.legend.display = false;
config5.options.scales.x.title.text = 'ky';
config5.options.scales.y.title.text = 'Lambda';
window.orbital_line_plot_5 = new Chart(ctx5, config5);
}
const
orbital_lat_slide = document.getElementById('orbital_lat_slide'),
orbital_day_slide = document.getElementById('orbital_day_slide'),
orbital_slide_value_fields = document.getElementsByName('orbital_slide_value'),
orbital_slider = document.getElementsByName('orbital_slide'),
orbital_RESET_BTN = document.getElementById('orbital_resetBtn'),
orbital_plot_variables = ['lat', 'day'],
default_orbital_values = {
lat: 65,
day: 172
};
// ----- ----- ----- ----- ----- ----- ----- ----- -----
orbital_RESET_BTN.onclick = () => {
plotALL(); // resets the plot
orbital_lat_slide.value = default_orbital_values.lat,
orbital_day_slide.value = default_orbital_values.day;
orbital_slide_value_fields.forEach((element, index) => { // Reset value fields
const default_value = default_orbital_values[orbital_plot_variables[index]];
document.getElementById(element.id).innerHTML = default_value;
});
}
orbital_lat_slide.oninput = () => {
document.getElementById('orbital_lat_value').innerHTML = orbital_lat_slide.value;
}
// ----- ----- ----- ----- ----- ----- ----- ----- -----
for (let entry = 0; entry < orbital_slider.length; entry++) {
orbital_slider[entry].onchange = () => {
plotALL({
day: parseInt(orbital_day_slide.value),
lat: parseInt(orbital_lat_slide.value)
});
}
}
orbital_day_slide.oninput = () => {
document.getElementById('dayval').innerHTML = utils.dateFromDay(2021, parseInt(document.getElementById('orbital_day_slide').value));
document.getElementById('orbital_day_value').innerHTML = orbital_day_slide.value;
}
/** ============================================================
____ _ ____ _ _
/ ___|___ _ __ | |_ ___ _ _ _ __| _ \| | ___ | |_ ___
| | / _ \| '_ \| __/ _ \| | | | '__| |_) | |/ _ \| __/ __|
| |__| (_) | | | | || (_) | |_| | | | __/| | (_) | |_\__ \
\____\___/|_| |_|\__\___/ \__,_|_| |_| |_|\___/ \__|___/
*/
const
MONTHS = [
'January', 'February',
'March', 'April', 'May',
'June', 'July', 'August',
'September', 'October', 'November',
'December'
],
colorscale_str = 'Jet',
contour_plot_config = {
toImageButtonOptions: {
format: 'svg',
filename: 'contour_1',
width: 1920,
height: 1080,
scale: 1,
}
},
contour_plot_layout = {
title: {
text: '',
font: {
family: FONT_FAMILY,
size: 18,
},
xref: 'paper',
x: 0.05,
},
xaxis: {
title: {
text: 'time',
font: {
family: FONT_FAMILY,
size: 18,
color: '#7f7f7f',
},
},
// tickformat: '%m',
dtick: '30',
/* Set the values at which ticks on this axis appear */
tickvals: [15, 45, 75, 105, 135, 165, 195, 225, 255, 285, 315, 345],
/* Set the text displayed at the ticks position via tickvals */
ticktext: MONTHS,
/* Specifies the maximum number of ticks */
nticks: 12,
},
yaxis: {
title: {
text: 'latitude',
font: {
family: FONT_FAMILY,
size: 18,
color: '#7f7f7f',
},
},
},
};
function plot_contour(input) {
Plotly.newPlot(
input.divId,
input.data,
input.layout,
contour_plot_config,
);
}
function plot_contour_1(input = {
year: 0
}) {
input.year = (input.year < 0) ? input.year * -1 : input.year;
const RESULT = get_insolation_of_year(input.year);
const max = utils.get2dmax(RESULT)
// console.log(RESULT)
const contour_plot_data = [{
z: RESULT,
x: [...new Array(RESULT[0].length)].map((elem, index) => index), //utils.dateFromDay(2021, index + 1)), // time