@neaps/tide-predictor 0.4.0 → 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 +95 -98
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +94 -97
- 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(
|
|
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
|
-
|
|
312
|
-
coefficients
|
|
313
|
-
value: (astro
|
|
314
|
-
return dotArray(coefficients
|
|
311
|
+
names: Array.isArray(names) ? names : [names],
|
|
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
|
-
function defineCompoundConstituent(
|
|
324
|
-
const coefficients
|
|
323
|
+
function defineCompoundConstituent(names, members) {
|
|
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
|
-
|
|
333
|
-
coefficients
|
|
334
|
-
speed: (astro
|
|
332
|
+
names: Array.isArray(names) ? names : [names],
|
|
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;
|
|
@@ -713,7 +713,7 @@ var K2_default = defineConstituent("K2", [
|
|
|
713
713
|
* Amplitude typically <5% of M2; important in detailed constituent analysis.
|
|
714
714
|
* IHO standard designation (previously abbreviated as LAM2).
|
|
715
715
|
*/
|
|
716
|
-
var LAMBDA2_default = defineConstituent("LAMBDA2", [
|
|
716
|
+
var LAMBDA2_default = defineConstituent(["LAM2", "LAMBDA2"], [
|
|
717
717
|
2,
|
|
718
718
|
1,
|
|
719
719
|
-2,
|
|
@@ -723,15 +723,6 @@ var LAMBDA2_default = defineConstituent("LAMBDA2", [
|
|
|
723
723
|
2
|
|
724
724
|
], node_corrections_default.uM2, node_corrections_default.fM2);
|
|
725
725
|
|
|
726
|
-
//#endregion
|
|
727
|
-
//#region src/constituents/LAM2.ts
|
|
728
|
-
/**
|
|
729
|
-
* Alias for compatibility between NOAA and IHO
|
|
730
|
-
*
|
|
731
|
-
* @see LAMBDA2
|
|
732
|
-
*/
|
|
733
|
-
var LAM2_default = LAMBDA2_default;
|
|
734
|
-
|
|
735
726
|
//#endregion
|
|
736
727
|
//#region src/constituents/M1.ts
|
|
737
728
|
/**
|
|
@@ -949,6 +940,40 @@ var MN4_default = defineCompoundConstituent("MN4", [{
|
|
|
949
940
|
factor: 1
|
|
950
941
|
}]);
|
|
951
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
|
+
|
|
952
977
|
//#endregion
|
|
953
978
|
//#region src/constituents/MS4.ts
|
|
954
979
|
/**
|
|
@@ -1113,24 +1138,6 @@ var OO1_default = defineConstituent("OO1", [
|
|
|
1113
1138
|
-1
|
|
1114
1139
|
], node_corrections_default.uOO1, node_corrections_default.fOO1);
|
|
1115
1140
|
|
|
1116
|
-
//#endregion
|
|
1117
|
-
//#region src/constituents/P1.ts
|
|
1118
|
-
/**
|
|
1119
|
-
* Solar diurnal (P1).
|
|
1120
|
-
* Principal solar diurnal constituent; one-per-solar-day oscillation.
|
|
1121
|
-
* Amplitude typically 1/3 of K1; varies with latitude.
|
|
1122
|
-
* Forms key component of diurnal tidal analysis alongside K1 and O1.
|
|
1123
|
-
*/
|
|
1124
|
-
var P1_default = defineConstituent("P1", [
|
|
1125
|
-
1,
|
|
1126
|
-
1,
|
|
1127
|
-
-2,
|
|
1128
|
-
0,
|
|
1129
|
-
0,
|
|
1130
|
-
0,
|
|
1131
|
-
1
|
|
1132
|
-
], node_corrections_default.uZero, node_corrections_default.fUnity);
|
|
1133
|
-
|
|
1134
1141
|
//#endregion
|
|
1135
1142
|
//#region src/constituents/Q1.ts
|
|
1136
1143
|
/**
|
|
@@ -1190,7 +1197,7 @@ var R3_default = defineCompoundConstituent("R3", [{
|
|
|
1190
1197
|
* Amplitude typically very small; rarely significant.
|
|
1191
1198
|
* Found only in shallow-water regions with strong tidal distortion.
|
|
1192
1199
|
*/
|
|
1193
|
-
var RHO1_default = defineCompoundConstituent("RHO1", [{
|
|
1200
|
+
var RHO1_default = defineCompoundConstituent(["RHO", "RHO1"], [{
|
|
1194
1201
|
constituent: NU2_default,
|
|
1195
1202
|
factor: 1
|
|
1196
1203
|
}, {
|
|
@@ -1198,15 +1205,6 @@ var RHO1_default = defineCompoundConstituent("RHO1", [{
|
|
|
1198
1205
|
factor: -1
|
|
1199
1206
|
}]);
|
|
1200
1207
|
|
|
1201
|
-
//#endregion
|
|
1202
|
-
//#region src/constituents/RHO.ts
|
|
1203
|
-
/**
|
|
1204
|
-
* Alias for compatibility between NOAA and IHO
|
|
1205
|
-
*
|
|
1206
|
-
* @see RHO1
|
|
1207
|
-
*/
|
|
1208
|
-
var RHO_default = RHO1_default;
|
|
1209
|
-
|
|
1210
1208
|
//#endregion
|
|
1211
1209
|
//#region src/constituents/S1.ts
|
|
1212
1210
|
/**
|
|
@@ -1274,7 +1272,7 @@ var S6_default = defineCompoundConstituent("S6", [{
|
|
|
1274
1272
|
* Solar annual (Sa).
|
|
1275
1273
|
* Long-term constituent driven by solar declination variations over the year.
|
|
1276
1274
|
*/
|
|
1277
|
-
var SA_default = defineConstituent("Sa", [
|
|
1275
|
+
var SA_default = defineConstituent(["SA", "Sa"], [
|
|
1278
1276
|
0,
|
|
1279
1277
|
0,
|
|
1280
1278
|
1,
|
|
@@ -1292,7 +1290,7 @@ var SA_default = defineConstituent("Sa", [
|
|
|
1292
1290
|
*
|
|
1293
1291
|
* Note: Often has small amplitude; closely related to K1 and O1 variations.
|
|
1294
1292
|
*/
|
|
1295
|
-
var SGM_default = defineConstituent("SGM", [
|
|
1293
|
+
var SGM_default = defineConstituent(["SGM", "SIGMA1"], [
|
|
1296
1294
|
1,
|
|
1297
1295
|
-3,
|
|
1298
1296
|
2,
|
|
@@ -1308,7 +1306,7 @@ var SGM_default = defineConstituent("SGM", [
|
|
|
1308
1306
|
* Solar semi-annual (Ssa).
|
|
1309
1307
|
* Semi-annual constituent from solar declination with twice-yearly periodicity.
|
|
1310
1308
|
*/
|
|
1311
|
-
var SSA_default = defineConstituent("Ssa", [
|
|
1309
|
+
var SSA_default = defineConstituent(["Ssa", "SSA"], [
|
|
1312
1310
|
0,
|
|
1313
1311
|
0,
|
|
1314
1312
|
2,
|
|
@@ -1368,7 +1366,6 @@ const constituentModules = {
|
|
|
1368
1366
|
"./K1.ts": K1_default,
|
|
1369
1367
|
"./K2.ts": K2_default,
|
|
1370
1368
|
"./L2.ts": L2_default,
|
|
1371
|
-
"./LAM2.ts": LAM2_default,
|
|
1372
1369
|
"./LAMBDA2.ts": LAMBDA2_default,
|
|
1373
1370
|
"./M1.ts": M1_default,
|
|
1374
1371
|
"./M2.ts": M2_default,
|
|
@@ -1383,6 +1380,7 @@ const constituentModules = {
|
|
|
1383
1380
|
"./MKS2.ts": MKS2_default,
|
|
1384
1381
|
"./MM.ts": MM_default,
|
|
1385
1382
|
"./MN4.ts": MN4_default,
|
|
1383
|
+
"./MP1.ts": MP1_default,
|
|
1386
1384
|
"./MS4.ts": MS4_default,
|
|
1387
1385
|
"./MSF.ts": MSF_default,
|
|
1388
1386
|
"./MSQM.ts": MSQM_default,
|
|
@@ -1397,7 +1395,6 @@ const constituentModules = {
|
|
|
1397
1395
|
"./Q1.ts": Q1_default,
|
|
1398
1396
|
"./R2.ts": R2_default,
|
|
1399
1397
|
"./R3.ts": R3_default,
|
|
1400
|
-
"./RHO.ts": RHO_default,
|
|
1401
1398
|
"./RHO1.ts": RHO1_default,
|
|
1402
1399
|
"./S1.ts": S1_default,
|
|
1403
1400
|
"./S2.ts": S2_default,
|
|
@@ -1413,11 +1410,11 @@ const constituentModules = {
|
|
|
1413
1410
|
"./definition.ts": definition_default
|
|
1414
1411
|
};
|
|
1415
1412
|
const constituents = {};
|
|
1416
|
-
for (const [path, module
|
|
1417
|
-
if (path.
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1413
|
+
for (const [path, module] of Object.entries(constituentModules)) {
|
|
1414
|
+
if (path.match(/index|definition/)) continue;
|
|
1415
|
+
module.names.forEach((name) => {
|
|
1416
|
+
constituents[name] = module;
|
|
1417
|
+
});
|
|
1421
1418
|
}
|
|
1422
1419
|
var constituents_default = constituents;
|
|
1423
1420
|
|
|
@@ -1443,11 +1440,11 @@ const getExtremeLabel = (label, highLowLabels) => {
|
|
|
1443
1440
|
low: "Low"
|
|
1444
1441
|
}[label];
|
|
1445
1442
|
};
|
|
1446
|
-
const predictionFactory = ({ timeline, constituents
|
|
1443
|
+
const predictionFactory = ({ timeline, constituents, start }) => {
|
|
1447
1444
|
const getLevel = (hour, modelBaseSpeed, modelU, modelF, modelBaseValue) => {
|
|
1448
1445
|
const amplitudes = [];
|
|
1449
1446
|
let result = 0;
|
|
1450
|
-
constituents
|
|
1447
|
+
constituents.forEach((constituent) => {
|
|
1451
1448
|
const amplitude = constituent.amplitude;
|
|
1452
1449
|
const phase = constituent.phase;
|
|
1453
1450
|
const f = modelF[constituent.name];
|
|
@@ -1503,12 +1500,12 @@ const predictionFactory = ({ timeline, constituents: constituents$1, start }) =>
|
|
|
1503
1500
|
const { baseSpeed, u, f, baseValue } = prepare();
|
|
1504
1501
|
timeline.items.forEach((time, index) => {
|
|
1505
1502
|
const hour = timeline.hours[index];
|
|
1506
|
-
const prediction
|
|
1503
|
+
const prediction = {
|
|
1507
1504
|
time,
|
|
1508
1505
|
hour,
|
|
1509
1506
|
level: getLevel(hour, baseSpeed, u[index], f[index], baseValue)
|
|
1510
1507
|
};
|
|
1511
|
-
results.push(prediction
|
|
1508
|
+
results.push(prediction);
|
|
1512
1509
|
});
|
|
1513
1510
|
return results;
|
|
1514
1511
|
};
|
|
@@ -1518,7 +1515,7 @@ const predictionFactory = ({ timeline, constituents: constituents$1, start }) =>
|
|
|
1518
1515
|
const baseSpeed = {};
|
|
1519
1516
|
const u = [];
|
|
1520
1517
|
const f = [];
|
|
1521
|
-
constituents
|
|
1518
|
+
constituents.forEach((constituent) => {
|
|
1522
1519
|
const model = constituents_default[constituent.name];
|
|
1523
1520
|
if (!model) return;
|
|
1524
1521
|
const value = model.value(baseAstro);
|
|
@@ -1530,7 +1527,7 @@ const predictionFactory = ({ timeline, constituents: constituents$1, start }) =>
|
|
|
1530
1527
|
const uItem = {};
|
|
1531
1528
|
const fItem = {};
|
|
1532
1529
|
const itemAstro = astronomy_default(time);
|
|
1533
|
-
constituents
|
|
1530
|
+
constituents.forEach((constituent) => {
|
|
1534
1531
|
const model = constituents_default[constituent.name];
|
|
1535
1532
|
if (!model) return;
|
|
1536
1533
|
const constituentU = modulus(model.u(itemAstro), 360);
|
|
@@ -1576,15 +1573,15 @@ const getTimeline = (start, end, seconds = 600) => {
|
|
|
1576
1573
|
};
|
|
1577
1574
|
const harmonicsFactory = ({ harmonicConstituents, offset }) => {
|
|
1578
1575
|
if (!Array.isArray(harmonicConstituents)) throw new Error("Harmonic constituents are not an array");
|
|
1579
|
-
const constituents
|
|
1576
|
+
const constituents = [];
|
|
1580
1577
|
harmonicConstituents.forEach((constituent) => {
|
|
1581
1578
|
if (typeof constituent.name === "undefined") throw new Error("Harmonic constituents must have a name property");
|
|
1582
|
-
if (constituents_default[constituent.name] !== void 0) constituents
|
|
1579
|
+
if (constituents_default[constituent.name] !== void 0) constituents.push({
|
|
1583
1580
|
...constituent,
|
|
1584
1581
|
phase: d2r * constituent.phase
|
|
1585
1582
|
});
|
|
1586
1583
|
});
|
|
1587
|
-
if (offset !== false) constituents
|
|
1584
|
+
if (offset !== false) constituents.push({
|
|
1588
1585
|
name: "Z0",
|
|
1589
1586
|
phase: 0,
|
|
1590
1587
|
amplitude: offset
|
|
@@ -1601,7 +1598,7 @@ const harmonicsFactory = ({ harmonicConstituents, offset }) => {
|
|
|
1601
1598
|
harmonics.prediction = (options) => {
|
|
1602
1599
|
return prediction_default({
|
|
1603
1600
|
timeline: getTimeline(start, end, (typeof options !== "undefined" ? options : { timeFidelity: 600 }).timeFidelity),
|
|
1604
|
-
constituents
|
|
1601
|
+
constituents,
|
|
1605
1602
|
start
|
|
1606
1603
|
});
|
|
1607
1604
|
};
|
|
@@ -1611,9 +1608,9 @@ var harmonics_default = harmonicsFactory;
|
|
|
1611
1608
|
|
|
1612
1609
|
//#endregion
|
|
1613
1610
|
//#region src/index.ts
|
|
1614
|
-
const tidePredictionFactory = (constituents
|
|
1611
|
+
const tidePredictionFactory = (constituents, options = {}) => {
|
|
1615
1612
|
const harmonicsOptions = {
|
|
1616
|
-
harmonicConstituents: constituents
|
|
1613
|
+
harmonicConstituents: constituents,
|
|
1617
1614
|
offset: false,
|
|
1618
1615
|
...options
|
|
1619
1616
|
};
|