@neaps/tide-predictor 0.4.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +85 -68
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +82 -65
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -61,16 +61,16 @@ var coefficients_default = coefficients;
|
|
|
61
61
|
|
|
62
62
|
//#endregion
|
|
63
63
|
//#region src/astronomy/index.ts
|
|
64
|
-
const polynomial = (coefficients
|
|
64
|
+
const polynomial = (coefficients, argument) => {
|
|
65
65
|
const result = [];
|
|
66
|
-
coefficients
|
|
66
|
+
coefficients.forEach((coefficient, index) => {
|
|
67
67
|
result.push(coefficient * Math.pow(argument, index));
|
|
68
68
|
});
|
|
69
69
|
return result.reduce((a, b) => a + b);
|
|
70
70
|
};
|
|
71
|
-
const derivativePolynomial = (coefficients
|
|
71
|
+
const derivativePolynomial = (coefficients, argument) => {
|
|
72
72
|
const result = [];
|
|
73
|
-
coefficients
|
|
73
|
+
coefficients.forEach((coefficient, index) => {
|
|
74
74
|
result.push(coefficient * index * Math.pow(argument, index - 1));
|
|
75
75
|
});
|
|
76
76
|
return result.reduce((a, b) => a + b);
|
|
@@ -305,57 +305,57 @@ var node_corrections_default = corrections;
|
|
|
305
305
|
|
|
306
306
|
//#endregion
|
|
307
307
|
//#region src/constituents/definition.ts
|
|
308
|
-
function defineConstituent(names, coefficients
|
|
309
|
-
if (!coefficients
|
|
308
|
+
function defineConstituent(names, coefficients, u, f) {
|
|
309
|
+
if (!coefficients) throw new Error("Coefficient must be defined for a constituent");
|
|
310
310
|
return Object.freeze({
|
|
311
311
|
names: Array.isArray(names) ? names : [names],
|
|
312
|
-
coefficients
|
|
313
|
-
value: (astro
|
|
314
|
-
return dotArray(coefficients
|
|
312
|
+
coefficients,
|
|
313
|
+
value: (astro) => {
|
|
314
|
+
return dotArray(coefficients, astronomicValues(astro));
|
|
315
315
|
},
|
|
316
|
-
speed(astro
|
|
317
|
-
return dotArray(coefficients
|
|
316
|
+
speed(astro) {
|
|
317
|
+
return dotArray(coefficients, astronomicSpeed(astro));
|
|
318
318
|
},
|
|
319
319
|
u: typeof u !== "undefined" ? u : node_corrections_default.uZero,
|
|
320
320
|
f: typeof f !== "undefined" ? f : node_corrections_default.fUnity
|
|
321
321
|
});
|
|
322
322
|
}
|
|
323
323
|
function defineCompoundConstituent(names, members) {
|
|
324
|
-
const coefficients
|
|
324
|
+
const coefficients = [];
|
|
325
325
|
members.forEach(({ constituent, factor }) => {
|
|
326
326
|
constituent.coefficients.forEach((coefficient, index) => {
|
|
327
|
-
if (typeof coefficients
|
|
328
|
-
coefficients
|
|
327
|
+
if (typeof coefficients[index] === "undefined") coefficients[index] = 0;
|
|
328
|
+
coefficients[index] += coefficient * factor;
|
|
329
329
|
});
|
|
330
330
|
});
|
|
331
331
|
return Object.freeze({
|
|
332
332
|
names: Array.isArray(names) ? names : [names],
|
|
333
|
-
coefficients
|
|
334
|
-
speed: (astro
|
|
333
|
+
coefficients,
|
|
334
|
+
speed: (astro) => {
|
|
335
335
|
let speed = 0;
|
|
336
336
|
members.forEach(({ constituent, factor }) => {
|
|
337
|
-
speed += constituent.speed(astro
|
|
337
|
+
speed += constituent.speed(astro) * factor;
|
|
338
338
|
});
|
|
339
339
|
return speed;
|
|
340
340
|
},
|
|
341
|
-
value: (astro
|
|
341
|
+
value: (astro) => {
|
|
342
342
|
let value = 0;
|
|
343
343
|
members.forEach(({ constituent, factor }) => {
|
|
344
|
-
value += constituent.value(astro
|
|
344
|
+
value += constituent.value(astro) * factor;
|
|
345
345
|
});
|
|
346
346
|
return value;
|
|
347
347
|
},
|
|
348
|
-
u: (astro
|
|
348
|
+
u: (astro) => {
|
|
349
349
|
let u = 0;
|
|
350
350
|
members.forEach(({ constituent, factor }) => {
|
|
351
|
-
u += constituent.u(astro
|
|
351
|
+
u += constituent.u(astro) * factor;
|
|
352
352
|
});
|
|
353
353
|
return u;
|
|
354
354
|
},
|
|
355
|
-
f: (astro
|
|
355
|
+
f: (astro) => {
|
|
356
356
|
const f = [];
|
|
357
357
|
members.forEach(({ constituent, factor }) => {
|
|
358
|
-
f.push(Math.pow(constituent.f(astro
|
|
358
|
+
f.push(Math.pow(constituent.f(astro), Math.abs(factor)));
|
|
359
359
|
});
|
|
360
360
|
return f.reduce((previous, value) => previous * value);
|
|
361
361
|
}
|
|
@@ -371,27 +371,27 @@ function dotArray(a, b) {
|
|
|
371
371
|
});
|
|
372
372
|
return results.reduce((total, value) => total + value);
|
|
373
373
|
}
|
|
374
|
-
function astronimicDoodsonNumber(astro
|
|
374
|
+
function astronimicDoodsonNumber(astro) {
|
|
375
375
|
return [
|
|
376
|
-
astro
|
|
377
|
-
astro
|
|
378
|
-
astro
|
|
379
|
-
astro
|
|
380
|
-
astro
|
|
381
|
-
astro
|
|
382
|
-
astro
|
|
376
|
+
astro["T+h-s"],
|
|
377
|
+
astro.s,
|
|
378
|
+
astro.h,
|
|
379
|
+
astro.p,
|
|
380
|
+
astro.N,
|
|
381
|
+
astro.pp,
|
|
382
|
+
astro["90"]
|
|
383
383
|
];
|
|
384
384
|
}
|
|
385
|
-
function astronomicSpeed(astro
|
|
385
|
+
function astronomicSpeed(astro) {
|
|
386
386
|
const results = [];
|
|
387
|
-
astronimicDoodsonNumber(astro
|
|
387
|
+
astronimicDoodsonNumber(astro).forEach((number) => {
|
|
388
388
|
results.push(number.speed);
|
|
389
389
|
});
|
|
390
390
|
return results;
|
|
391
391
|
}
|
|
392
|
-
function astronomicValues(astro
|
|
392
|
+
function astronomicValues(astro) {
|
|
393
393
|
const results = [];
|
|
394
|
-
astronimicDoodsonNumber(astro
|
|
394
|
+
astronimicDoodsonNumber(astro).forEach((number) => {
|
|
395
395
|
results.push(number.value);
|
|
396
396
|
});
|
|
397
397
|
return results;
|
|
@@ -940,6 +940,40 @@ var MN4_default = defineCompoundConstituent("MN4", [{
|
|
|
940
940
|
factor: 1
|
|
941
941
|
}]);
|
|
942
942
|
|
|
943
|
+
//#endregion
|
|
944
|
+
//#region src/constituents/P1.ts
|
|
945
|
+
/**
|
|
946
|
+
* Solar diurnal (P1).
|
|
947
|
+
* Principal solar diurnal constituent; one-per-solar-day oscillation.
|
|
948
|
+
* Amplitude typically 1/3 of K1; varies with latitude.
|
|
949
|
+
* Forms key component of diurnal tidal analysis alongside K1 and O1.
|
|
950
|
+
*/
|
|
951
|
+
var P1_default = defineConstituent("P1", [
|
|
952
|
+
1,
|
|
953
|
+
1,
|
|
954
|
+
-2,
|
|
955
|
+
0,
|
|
956
|
+
0,
|
|
957
|
+
0,
|
|
958
|
+
1
|
|
959
|
+
], node_corrections_default.uZero, node_corrections_default.fUnity);
|
|
960
|
+
|
|
961
|
+
//#endregion
|
|
962
|
+
//#region src/constituents/MP1.ts
|
|
963
|
+
/**
|
|
964
|
+
* Solar-lunar diurnal (MP1 = M2 - P1).
|
|
965
|
+
* Combined solar and lunar diurnal constituent from solar-lunar interaction.
|
|
966
|
+
* Amplitude typically small; usually <5% of K1.
|
|
967
|
+
* Rarely significant except in specialized harmonic analyses.
|
|
968
|
+
*/
|
|
969
|
+
var MP1_default = defineCompoundConstituent("MP1", [{
|
|
970
|
+
constituent: M2_default,
|
|
971
|
+
factor: 1
|
|
972
|
+
}, {
|
|
973
|
+
constituent: P1_default,
|
|
974
|
+
factor: -1
|
|
975
|
+
}]);
|
|
976
|
+
|
|
943
977
|
//#endregion
|
|
944
978
|
//#region src/constituents/MS4.ts
|
|
945
979
|
/**
|
|
@@ -1104,24 +1138,6 @@ var OO1_default = defineConstituent("OO1", [
|
|
|
1104
1138
|
-1
|
|
1105
1139
|
], node_corrections_default.uOO1, node_corrections_default.fOO1);
|
|
1106
1140
|
|
|
1107
|
-
//#endregion
|
|
1108
|
-
//#region src/constituents/P1.ts
|
|
1109
|
-
/**
|
|
1110
|
-
* Solar diurnal (P1).
|
|
1111
|
-
* Principal solar diurnal constituent; one-per-solar-day oscillation.
|
|
1112
|
-
* Amplitude typically 1/3 of K1; varies with latitude.
|
|
1113
|
-
* Forms key component of diurnal tidal analysis alongside K1 and O1.
|
|
1114
|
-
*/
|
|
1115
|
-
var P1_default = defineConstituent("P1", [
|
|
1116
|
-
1,
|
|
1117
|
-
1,
|
|
1118
|
-
-2,
|
|
1119
|
-
0,
|
|
1120
|
-
0,
|
|
1121
|
-
0,
|
|
1122
|
-
1
|
|
1123
|
-
], node_corrections_default.uZero, node_corrections_default.fUnity);
|
|
1124
|
-
|
|
1125
1141
|
//#endregion
|
|
1126
1142
|
//#region src/constituents/Q1.ts
|
|
1127
1143
|
/**
|
|
@@ -1364,6 +1380,7 @@ const constituentModules = {
|
|
|
1364
1380
|
"./MKS2.ts": MKS2_default,
|
|
1365
1381
|
"./MM.ts": MM_default,
|
|
1366
1382
|
"./MN4.ts": MN4_default,
|
|
1383
|
+
"./MP1.ts": MP1_default,
|
|
1367
1384
|
"./MS4.ts": MS4_default,
|
|
1368
1385
|
"./MSF.ts": MSF_default,
|
|
1369
1386
|
"./MSQM.ts": MSQM_default,
|
|
@@ -1393,10 +1410,10 @@ const constituentModules = {
|
|
|
1393
1410
|
"./definition.ts": definition_default
|
|
1394
1411
|
};
|
|
1395
1412
|
const constituents = {};
|
|
1396
|
-
for (const [path, module
|
|
1413
|
+
for (const [path, module] of Object.entries(constituentModules)) {
|
|
1397
1414
|
if (path.match(/index|definition/)) continue;
|
|
1398
|
-
module
|
|
1399
|
-
constituents[name] = module
|
|
1415
|
+
module.names.forEach((name) => {
|
|
1416
|
+
constituents[name] = module;
|
|
1400
1417
|
});
|
|
1401
1418
|
}
|
|
1402
1419
|
var constituents_default = constituents;
|
|
@@ -1423,11 +1440,11 @@ const getExtremeLabel = (label, highLowLabels) => {
|
|
|
1423
1440
|
low: "Low"
|
|
1424
1441
|
}[label];
|
|
1425
1442
|
};
|
|
1426
|
-
const predictionFactory = ({ timeline, constituents
|
|
1443
|
+
const predictionFactory = ({ timeline, constituents, start }) => {
|
|
1427
1444
|
const getLevel = (hour, modelBaseSpeed, modelU, modelF, modelBaseValue) => {
|
|
1428
1445
|
const amplitudes = [];
|
|
1429
1446
|
let result = 0;
|
|
1430
|
-
constituents
|
|
1447
|
+
constituents.forEach((constituent) => {
|
|
1431
1448
|
const amplitude = constituent.amplitude;
|
|
1432
1449
|
const phase = constituent.phase;
|
|
1433
1450
|
const f = modelF[constituent.name];
|
|
@@ -1483,12 +1500,12 @@ const predictionFactory = ({ timeline, constituents: constituents$1, start }) =>
|
|
|
1483
1500
|
const { baseSpeed, u, f, baseValue } = prepare();
|
|
1484
1501
|
timeline.items.forEach((time, index) => {
|
|
1485
1502
|
const hour = timeline.hours[index];
|
|
1486
|
-
const prediction
|
|
1503
|
+
const prediction = {
|
|
1487
1504
|
time,
|
|
1488
1505
|
hour,
|
|
1489
1506
|
level: getLevel(hour, baseSpeed, u[index], f[index], baseValue)
|
|
1490
1507
|
};
|
|
1491
|
-
results.push(prediction
|
|
1508
|
+
results.push(prediction);
|
|
1492
1509
|
});
|
|
1493
1510
|
return results;
|
|
1494
1511
|
};
|
|
@@ -1498,7 +1515,7 @@ const predictionFactory = ({ timeline, constituents: constituents$1, start }) =>
|
|
|
1498
1515
|
const baseSpeed = {};
|
|
1499
1516
|
const u = [];
|
|
1500
1517
|
const f = [];
|
|
1501
|
-
constituents
|
|
1518
|
+
constituents.forEach((constituent) => {
|
|
1502
1519
|
const model = constituents_default[constituent.name];
|
|
1503
1520
|
if (!model) return;
|
|
1504
1521
|
const value = model.value(baseAstro);
|
|
@@ -1510,7 +1527,7 @@ const predictionFactory = ({ timeline, constituents: constituents$1, start }) =>
|
|
|
1510
1527
|
const uItem = {};
|
|
1511
1528
|
const fItem = {};
|
|
1512
1529
|
const itemAstro = astronomy_default(time);
|
|
1513
|
-
constituents
|
|
1530
|
+
constituents.forEach((constituent) => {
|
|
1514
1531
|
const model = constituents_default[constituent.name];
|
|
1515
1532
|
if (!model) return;
|
|
1516
1533
|
const constituentU = modulus(model.u(itemAstro), 360);
|
|
@@ -1556,15 +1573,15 @@ const getTimeline = (start, end, seconds = 600) => {
|
|
|
1556
1573
|
};
|
|
1557
1574
|
const harmonicsFactory = ({ harmonicConstituents, offset }) => {
|
|
1558
1575
|
if (!Array.isArray(harmonicConstituents)) throw new Error("Harmonic constituents are not an array");
|
|
1559
|
-
const constituents
|
|
1576
|
+
const constituents = [];
|
|
1560
1577
|
harmonicConstituents.forEach((constituent) => {
|
|
1561
1578
|
if (typeof constituent.name === "undefined") throw new Error("Harmonic constituents must have a name property");
|
|
1562
|
-
if (constituents_default[constituent.name] !== void 0) constituents
|
|
1579
|
+
if (constituents_default[constituent.name] !== void 0) constituents.push({
|
|
1563
1580
|
...constituent,
|
|
1564
1581
|
phase: d2r * constituent.phase
|
|
1565
1582
|
});
|
|
1566
1583
|
});
|
|
1567
|
-
if (offset !== false) constituents
|
|
1584
|
+
if (offset !== false) constituents.push({
|
|
1568
1585
|
name: "Z0",
|
|
1569
1586
|
phase: 0,
|
|
1570
1587
|
amplitude: offset
|
|
@@ -1581,7 +1598,7 @@ const harmonicsFactory = ({ harmonicConstituents, offset }) => {
|
|
|
1581
1598
|
harmonics.prediction = (options) => {
|
|
1582
1599
|
return prediction_default({
|
|
1583
1600
|
timeline: getTimeline(start, end, (typeof options !== "undefined" ? options : { timeFidelity: 600 }).timeFidelity),
|
|
1584
|
-
constituents
|
|
1601
|
+
constituents,
|
|
1585
1602
|
start
|
|
1586
1603
|
});
|
|
1587
1604
|
};
|
|
@@ -1591,9 +1608,9 @@ var harmonics_default = harmonicsFactory;
|
|
|
1591
1608
|
|
|
1592
1609
|
//#endregion
|
|
1593
1610
|
//#region src/index.ts
|
|
1594
|
-
const tidePredictionFactory = (constituents
|
|
1611
|
+
const tidePredictionFactory = (constituents, options = {}) => {
|
|
1595
1612
|
const harmonicsOptions = {
|
|
1596
|
-
harmonicConstituents: constituents
|
|
1613
|
+
harmonicConstituents: constituents,
|
|
1597
1614
|
offset: false,
|
|
1598
1615
|
...options
|
|
1599
1616
|
};
|