@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.js CHANGED
@@ -60,16 +60,16 @@ var coefficients_default = coefficients;
60
60
 
61
61
  //#endregion
62
62
  //#region src/astronomy/index.ts
63
- const polynomial = (coefficients$1, argument) => {
63
+ const polynomial = (coefficients, argument) => {
64
64
  const result = [];
65
- coefficients$1.forEach((coefficient, index) => {
65
+ coefficients.forEach((coefficient, index) => {
66
66
  result.push(coefficient * Math.pow(argument, index));
67
67
  });
68
68
  return result.reduce((a, b) => a + b);
69
69
  };
70
- const derivativePolynomial = (coefficients$1, argument) => {
70
+ const derivativePolynomial = (coefficients, argument) => {
71
71
  const result = [];
72
- coefficients$1.forEach((coefficient, index) => {
72
+ coefficients.forEach((coefficient, index) => {
73
73
  result.push(coefficient * index * Math.pow(argument, index - 1));
74
74
  });
75
75
  return result.reduce((a, b) => a + b);
@@ -304,57 +304,57 @@ var node_corrections_default = corrections;
304
304
 
305
305
  //#endregion
306
306
  //#region src/constituents/definition.ts
307
- function defineConstituent(name, coefficients$1, u, f) {
308
- if (!coefficients$1) throw new Error("Coefficient must be defined for a constituent");
307
+ function defineConstituent(names, coefficients, u, f) {
308
+ if (!coefficients) throw new Error("Coefficient must be defined for a constituent");
309
309
  return Object.freeze({
310
- name,
311
- coefficients: coefficients$1,
312
- value: (astro$1) => {
313
- return dotArray(coefficients$1, astronomicValues(astro$1));
310
+ names: Array.isArray(names) ? names : [names],
311
+ coefficients,
312
+ value: (astro) => {
313
+ return dotArray(coefficients, astronomicValues(astro));
314
314
  },
315
- speed(astro$1) {
316
- return dotArray(coefficients$1, astronomicSpeed(astro$1));
315
+ speed(astro) {
316
+ return dotArray(coefficients, astronomicSpeed(astro));
317
317
  },
318
318
  u: typeof u !== "undefined" ? u : node_corrections_default.uZero,
319
319
  f: typeof f !== "undefined" ? f : node_corrections_default.fUnity
320
320
  });
321
321
  }
322
- function defineCompoundConstituent(name, members) {
323
- const coefficients$1 = [];
322
+ function defineCompoundConstituent(names, members) {
323
+ const coefficients = [];
324
324
  members.forEach(({ constituent, factor }) => {
325
325
  constituent.coefficients.forEach((coefficient, index) => {
326
- if (typeof coefficients$1[index] === "undefined") coefficients$1[index] = 0;
327
- coefficients$1[index] += coefficient * factor;
326
+ if (typeof coefficients[index] === "undefined") coefficients[index] = 0;
327
+ coefficients[index] += coefficient * factor;
328
328
  });
329
329
  });
330
330
  return Object.freeze({
331
- name,
332
- coefficients: coefficients$1,
333
- speed: (astro$1) => {
331
+ names: Array.isArray(names) ? names : [names],
332
+ coefficients,
333
+ speed: (astro) => {
334
334
  let speed = 0;
335
335
  members.forEach(({ constituent, factor }) => {
336
- speed += constituent.speed(astro$1) * factor;
336
+ speed += constituent.speed(astro) * factor;
337
337
  });
338
338
  return speed;
339
339
  },
340
- value: (astro$1) => {
340
+ value: (astro) => {
341
341
  let value = 0;
342
342
  members.forEach(({ constituent, factor }) => {
343
- value += constituent.value(astro$1) * factor;
343
+ value += constituent.value(astro) * factor;
344
344
  });
345
345
  return value;
346
346
  },
347
- u: (astro$1) => {
347
+ u: (astro) => {
348
348
  let u = 0;
349
349
  members.forEach(({ constituent, factor }) => {
350
- u += constituent.u(astro$1) * factor;
350
+ u += constituent.u(astro) * factor;
351
351
  });
352
352
  return u;
353
353
  },
354
- f: (astro$1) => {
354
+ f: (astro) => {
355
355
  const f = [];
356
356
  members.forEach(({ constituent, factor }) => {
357
- f.push(Math.pow(constituent.f(astro$1), Math.abs(factor)));
357
+ f.push(Math.pow(constituent.f(astro), Math.abs(factor)));
358
358
  });
359
359
  return f.reduce((previous, value) => previous * value);
360
360
  }
@@ -370,27 +370,27 @@ function dotArray(a, b) {
370
370
  });
371
371
  return results.reduce((total, value) => total + value);
372
372
  }
373
- function astronimicDoodsonNumber(astro$1) {
373
+ function astronimicDoodsonNumber(astro) {
374
374
  return [
375
- astro$1["T+h-s"],
376
- astro$1.s,
377
- astro$1.h,
378
- astro$1.p,
379
- astro$1.N,
380
- astro$1.pp,
381
- astro$1["90"]
375
+ astro["T+h-s"],
376
+ astro.s,
377
+ astro.h,
378
+ astro.p,
379
+ astro.N,
380
+ astro.pp,
381
+ astro["90"]
382
382
  ];
383
383
  }
384
- function astronomicSpeed(astro$1) {
384
+ function astronomicSpeed(astro) {
385
385
  const results = [];
386
- astronimicDoodsonNumber(astro$1).forEach((number) => {
386
+ astronimicDoodsonNumber(astro).forEach((number) => {
387
387
  results.push(number.speed);
388
388
  });
389
389
  return results;
390
390
  }
391
- function astronomicValues(astro$1) {
391
+ function astronomicValues(astro) {
392
392
  const results = [];
393
- astronimicDoodsonNumber(astro$1).forEach((number) => {
393
+ astronimicDoodsonNumber(astro).forEach((number) => {
394
394
  results.push(number.value);
395
395
  });
396
396
  return results;
@@ -712,7 +712,7 @@ var K2_default = defineConstituent("K2", [
712
712
  * Amplitude typically <5% of M2; important in detailed constituent analysis.
713
713
  * IHO standard designation (previously abbreviated as LAM2).
714
714
  */
715
- var LAMBDA2_default = defineConstituent("LAMBDA2", [
715
+ var LAMBDA2_default = defineConstituent(["LAM2", "LAMBDA2"], [
716
716
  2,
717
717
  1,
718
718
  -2,
@@ -722,15 +722,6 @@ var LAMBDA2_default = defineConstituent("LAMBDA2", [
722
722
  2
723
723
  ], node_corrections_default.uM2, node_corrections_default.fM2);
724
724
 
725
- //#endregion
726
- //#region src/constituents/LAM2.ts
727
- /**
728
- * Alias for compatibility between NOAA and IHO
729
- *
730
- * @see LAMBDA2
731
- */
732
- var LAM2_default = LAMBDA2_default;
733
-
734
725
  //#endregion
735
726
  //#region src/constituents/M1.ts
736
727
  /**
@@ -948,6 +939,40 @@ var MN4_default = defineCompoundConstituent("MN4", [{
948
939
  factor: 1
949
940
  }]);
950
941
 
942
+ //#endregion
943
+ //#region src/constituents/P1.ts
944
+ /**
945
+ * Solar diurnal (P1).
946
+ * Principal solar diurnal constituent; one-per-solar-day oscillation.
947
+ * Amplitude typically 1/3 of K1; varies with latitude.
948
+ * Forms key component of diurnal tidal analysis alongside K1 and O1.
949
+ */
950
+ var P1_default = defineConstituent("P1", [
951
+ 1,
952
+ 1,
953
+ -2,
954
+ 0,
955
+ 0,
956
+ 0,
957
+ 1
958
+ ], node_corrections_default.uZero, node_corrections_default.fUnity);
959
+
960
+ //#endregion
961
+ //#region src/constituents/MP1.ts
962
+ /**
963
+ * Solar-lunar diurnal (MP1 = M2 - P1).
964
+ * Combined solar and lunar diurnal constituent from solar-lunar interaction.
965
+ * Amplitude typically small; usually <5% of K1.
966
+ * Rarely significant except in specialized harmonic analyses.
967
+ */
968
+ var MP1_default = defineCompoundConstituent("MP1", [{
969
+ constituent: M2_default,
970
+ factor: 1
971
+ }, {
972
+ constituent: P1_default,
973
+ factor: -1
974
+ }]);
975
+
951
976
  //#endregion
952
977
  //#region src/constituents/MS4.ts
953
978
  /**
@@ -1112,24 +1137,6 @@ var OO1_default = defineConstituent("OO1", [
1112
1137
  -1
1113
1138
  ], node_corrections_default.uOO1, node_corrections_default.fOO1);
1114
1139
 
1115
- //#endregion
1116
- //#region src/constituents/P1.ts
1117
- /**
1118
- * Solar diurnal (P1).
1119
- * Principal solar diurnal constituent; one-per-solar-day oscillation.
1120
- * Amplitude typically 1/3 of K1; varies with latitude.
1121
- * Forms key component of diurnal tidal analysis alongside K1 and O1.
1122
- */
1123
- var P1_default = defineConstituent("P1", [
1124
- 1,
1125
- 1,
1126
- -2,
1127
- 0,
1128
- 0,
1129
- 0,
1130
- 1
1131
- ], node_corrections_default.uZero, node_corrections_default.fUnity);
1132
-
1133
1140
  //#endregion
1134
1141
  //#region src/constituents/Q1.ts
1135
1142
  /**
@@ -1189,7 +1196,7 @@ var R3_default = defineCompoundConstituent("R3", [{
1189
1196
  * Amplitude typically very small; rarely significant.
1190
1197
  * Found only in shallow-water regions with strong tidal distortion.
1191
1198
  */
1192
- var RHO1_default = defineCompoundConstituent("RHO1", [{
1199
+ var RHO1_default = defineCompoundConstituent(["RHO", "RHO1"], [{
1193
1200
  constituent: NU2_default,
1194
1201
  factor: 1
1195
1202
  }, {
@@ -1197,15 +1204,6 @@ var RHO1_default = defineCompoundConstituent("RHO1", [{
1197
1204
  factor: -1
1198
1205
  }]);
1199
1206
 
1200
- //#endregion
1201
- //#region src/constituents/RHO.ts
1202
- /**
1203
- * Alias for compatibility between NOAA and IHO
1204
- *
1205
- * @see RHO1
1206
- */
1207
- var RHO_default = RHO1_default;
1208
-
1209
1207
  //#endregion
1210
1208
  //#region src/constituents/S1.ts
1211
1209
  /**
@@ -1273,7 +1271,7 @@ var S6_default = defineCompoundConstituent("S6", [{
1273
1271
  * Solar annual (Sa).
1274
1272
  * Long-term constituent driven by solar declination variations over the year.
1275
1273
  */
1276
- var SA_default = defineConstituent("Sa", [
1274
+ var SA_default = defineConstituent(["SA", "Sa"], [
1277
1275
  0,
1278
1276
  0,
1279
1277
  1,
@@ -1291,7 +1289,7 @@ var SA_default = defineConstituent("Sa", [
1291
1289
  *
1292
1290
  * Note: Often has small amplitude; closely related to K1 and O1 variations.
1293
1291
  */
1294
- var SGM_default = defineConstituent("SGM", [
1292
+ var SGM_default = defineConstituent(["SGM", "SIGMA1"], [
1295
1293
  1,
1296
1294
  -3,
1297
1295
  2,
@@ -1307,7 +1305,7 @@ var SGM_default = defineConstituent("SGM", [
1307
1305
  * Solar semi-annual (Ssa).
1308
1306
  * Semi-annual constituent from solar declination with twice-yearly periodicity.
1309
1307
  */
1310
- var SSA_default = defineConstituent("Ssa", [
1308
+ var SSA_default = defineConstituent(["Ssa", "SSA"], [
1311
1309
  0,
1312
1310
  0,
1313
1311
  2,
@@ -1367,7 +1365,6 @@ const constituentModules = {
1367
1365
  "./K1.ts": K1_default,
1368
1366
  "./K2.ts": K2_default,
1369
1367
  "./L2.ts": L2_default,
1370
- "./LAM2.ts": LAM2_default,
1371
1368
  "./LAMBDA2.ts": LAMBDA2_default,
1372
1369
  "./M1.ts": M1_default,
1373
1370
  "./M2.ts": M2_default,
@@ -1382,6 +1379,7 @@ const constituentModules = {
1382
1379
  "./MKS2.ts": MKS2_default,
1383
1380
  "./MM.ts": MM_default,
1384
1381
  "./MN4.ts": MN4_default,
1382
+ "./MP1.ts": MP1_default,
1385
1383
  "./MS4.ts": MS4_default,
1386
1384
  "./MSF.ts": MSF_default,
1387
1385
  "./MSQM.ts": MSQM_default,
@@ -1396,7 +1394,6 @@ const constituentModules = {
1396
1394
  "./Q1.ts": Q1_default,
1397
1395
  "./R2.ts": R2_default,
1398
1396
  "./R3.ts": R3_default,
1399
- "./RHO.ts": RHO_default,
1400
1397
  "./RHO1.ts": RHO1_default,
1401
1398
  "./S1.ts": S1_default,
1402
1399
  "./S2.ts": S2_default,
@@ -1413,10 +1410,10 @@ const constituentModules = {
1413
1410
  };
1414
1411
  const constituents = {};
1415
1412
  for (const [path, module] of Object.entries(constituentModules)) {
1416
- if (path.includes("index.ts")) continue;
1417
- const name = path.split("/").pop()?.replace(/\..*$/, "") ?? "";
1418
- if (name === "definition") continue;
1419
- constituents[name] = module;
1413
+ if (path.match(/index|definition/)) continue;
1414
+ module.names.forEach((name) => {
1415
+ constituents[name] = module;
1416
+ });
1420
1417
  }
1421
1418
  var constituents_default = constituents;
1422
1419
 
@@ -1442,11 +1439,11 @@ const getExtremeLabel = (label, highLowLabels) => {
1442
1439
  low: "Low"
1443
1440
  }[label];
1444
1441
  };
1445
- const predictionFactory = ({ timeline, constituents: constituents$1, start }) => {
1442
+ const predictionFactory = ({ timeline, constituents, start }) => {
1446
1443
  const getLevel = (hour, modelBaseSpeed, modelU, modelF, modelBaseValue) => {
1447
1444
  const amplitudes = [];
1448
1445
  let result = 0;
1449
- constituents$1.forEach((constituent) => {
1446
+ constituents.forEach((constituent) => {
1450
1447
  const amplitude = constituent.amplitude;
1451
1448
  const phase = constituent.phase;
1452
1449
  const f = modelF[constituent.name];
@@ -1502,12 +1499,12 @@ const predictionFactory = ({ timeline, constituents: constituents$1, start }) =>
1502
1499
  const { baseSpeed, u, f, baseValue } = prepare();
1503
1500
  timeline.items.forEach((time, index) => {
1504
1501
  const hour = timeline.hours[index];
1505
- const prediction$1 = {
1502
+ const prediction = {
1506
1503
  time,
1507
1504
  hour,
1508
1505
  level: getLevel(hour, baseSpeed, u[index], f[index], baseValue)
1509
1506
  };
1510
- results.push(prediction$1);
1507
+ results.push(prediction);
1511
1508
  });
1512
1509
  return results;
1513
1510
  };
@@ -1517,7 +1514,7 @@ const predictionFactory = ({ timeline, constituents: constituents$1, start }) =>
1517
1514
  const baseSpeed = {};
1518
1515
  const u = [];
1519
1516
  const f = [];
1520
- constituents$1.forEach((constituent) => {
1517
+ constituents.forEach((constituent) => {
1521
1518
  const model = constituents_default[constituent.name];
1522
1519
  if (!model) return;
1523
1520
  const value = model.value(baseAstro);
@@ -1529,7 +1526,7 @@ const predictionFactory = ({ timeline, constituents: constituents$1, start }) =>
1529
1526
  const uItem = {};
1530
1527
  const fItem = {};
1531
1528
  const itemAstro = astronomy_default(time);
1532
- constituents$1.forEach((constituent) => {
1529
+ constituents.forEach((constituent) => {
1533
1530
  const model = constituents_default[constituent.name];
1534
1531
  if (!model) return;
1535
1532
  const constituentU = modulus(model.u(itemAstro), 360);
@@ -1575,15 +1572,15 @@ const getTimeline = (start, end, seconds = 600) => {
1575
1572
  };
1576
1573
  const harmonicsFactory = ({ harmonicConstituents, offset }) => {
1577
1574
  if (!Array.isArray(harmonicConstituents)) throw new Error("Harmonic constituents are not an array");
1578
- const constituents$1 = [];
1575
+ const constituents = [];
1579
1576
  harmonicConstituents.forEach((constituent) => {
1580
1577
  if (typeof constituent.name === "undefined") throw new Error("Harmonic constituents must have a name property");
1581
- if (constituents_default[constituent.name] !== void 0) constituents$1.push({
1578
+ if (constituents_default[constituent.name] !== void 0) constituents.push({
1582
1579
  ...constituent,
1583
1580
  phase: d2r * constituent.phase
1584
1581
  });
1585
1582
  });
1586
- if (offset !== false) constituents$1.push({
1583
+ if (offset !== false) constituents.push({
1587
1584
  name: "Z0",
1588
1585
  phase: 0,
1589
1586
  amplitude: offset
@@ -1600,7 +1597,7 @@ const harmonicsFactory = ({ harmonicConstituents, offset }) => {
1600
1597
  harmonics.prediction = (options) => {
1601
1598
  return prediction_default({
1602
1599
  timeline: getTimeline(start, end, (typeof options !== "undefined" ? options : { timeFidelity: 600 }).timeFidelity),
1603
- constituents: constituents$1,
1600
+ constituents,
1604
1601
  start
1605
1602
  });
1606
1603
  };
@@ -1610,9 +1607,9 @@ var harmonics_default = harmonicsFactory;
1610
1607
 
1611
1608
  //#endregion
1612
1609
  //#region src/index.ts
1613
- const tidePredictionFactory = (constituents$1, options = {}) => {
1610
+ const tidePredictionFactory = (constituents, options = {}) => {
1614
1611
  const harmonicsOptions = {
1615
- harmonicConstituents: constituents$1,
1612
+ harmonicConstituents: constituents,
1616
1613
  offset: false,
1617
1614
  ...options
1618
1615
  };