Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions packages/tide-predictor/src/constituents/LAM2.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/tide-predictor/src/constituents/LAMBDA2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ import nc from "../node-corrections/index.js";
* Amplitude typically <5% of M2; important in detailed constituent analysis.
* IHO standard designation (previously abbreviated as LAM2).
*/
export default defineConstituent("LAMBDA2", [2, 1, -2, 1, 0, 0, 2], nc.uM2, nc.fM2);
export default defineConstituent(["LAM2", "LAMBDA2"], [2, 1, -2, 1, 0, 0, 2], nc.uM2, nc.fM2);
8 changes: 0 additions & 8 deletions packages/tide-predictor/src/constituents/RHO.ts

This file was deleted.

11 changes: 7 additions & 4 deletions packages/tide-predictor/src/constituents/RHO1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import K1 from "./K1.js";
* Amplitude typically very small; rarely significant.
* Found only in shallow-water regions with strong tidal distortion.
*/
export default defineCompoundConstituent("RHO1", [
{ constituent: NU2, factor: 1 },
{ constituent: K1, factor: -1 },
]);
export default defineCompoundConstituent(
["RHO", "RHO1"],
[
{ constituent: NU2, factor: 1 },
{ constituent: K1, factor: -1 },
],
);
2 changes: 1 addition & 1 deletion packages/tide-predictor/src/constituents/SA.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ import nc from "../node-corrections/index.js";
* Solar annual (Sa).
* Long-term constituent driven by solar declination variations over the year.
*/
export default defineConstituent("Sa", [0, 0, 1, 0, 0, 0, 0], nc.uZero, nc.fUnity);
export default defineConstituent(["SA", "Sa"], [0, 0, 1, 0, 0, 0, 0], nc.uZero, nc.fUnity);
2 changes: 1 addition & 1 deletion packages/tide-predictor/src/constituents/SGM.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ import nc from "../node-corrections/index.js";
*
* Note: Often has small amplitude; closely related to K1 and O1 variations.
*/
export default defineConstituent("SGM", [1, -3, 2, 0, 0, 0, -1], nc.uO1, nc.fO1);
export default defineConstituent(["SGM", "SIGMA1"], [1, -3, 2, 0, 0, 0, -1], nc.uO1, nc.fO1);
2 changes: 1 addition & 1 deletion packages/tide-predictor/src/constituents/SSA.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ import nc from "../node-corrections/index.js";
* Solar semi-annual (Ssa).
* Semi-annual constituent from solar declination with twice-yearly periodicity.
*/
export default defineConstituent("Ssa", [0, 0, 2, 0, 0, 0, 0], nc.uZero, nc.fUnity);
export default defineConstituent(["Ssa", "SSA"], [0, 0, 2, 0, 0, 0, 0], nc.uZero, nc.fUnity);
14 changes: 9 additions & 5 deletions packages/tide-predictor/src/constituents/definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { AstroData } from "../astronomy/index.js";
import nodeCorrections, { type NodeCorrectionFunction } from "../node-corrections/index.js";

export interface Constituent {
name: string;
names: string[];
coefficients: number[];
value: (astro: AstroData) => number;
speed: (astro: AstroData) => number;
Expand All @@ -11,7 +11,7 @@ export interface Constituent {
}

export function defineConstituent(
name: string,
names: string | string[],
coefficients: number[],
u?: NodeCorrectionFunction,
f?: NodeCorrectionFunction,
Expand All @@ -21,7 +21,8 @@ export function defineConstituent(
}

return Object.freeze({
name,
names: Array.isArray(names) ? names : [names],

coefficients,

value: (astro: AstroData): number => {
Expand All @@ -43,7 +44,10 @@ export interface ConstituentMember {
factor: number;
}

export function defineCompoundConstituent(name: string, members: ConstituentMember[]): Constituent {
export function defineCompoundConstituent(
names: string | string[],
members: ConstituentMember[],
): Constituent {
const coefficients: number[] = [];
members.forEach(({ constituent, factor }) => {
constituent.coefficients.forEach((coefficient, index) => {
Expand All @@ -55,7 +59,7 @@ export function defineCompoundConstituent(name: string, members: ConstituentMemb
});

return Object.freeze({
name,
names: Array.isArray(names) ? names : [names],
coefficients,

speed: (astro: AstroData): number => {
Expand Down
14 changes: 5 additions & 9 deletions packages/tide-predictor/src/constituents/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,12 @@ const constituents: Record<string, Constituent> = {};

// Extract constituent name from file path and populate the constituents object
for (const [path, module] of Object.entries(constituentModules)) {
// Skip the index file itself
if (path.includes("index.ts")) continue;
// Skip the index and definition files
if (path.match(/index|definition/)) continue;

// Extract filename without extension and .js suffix
const name = path.split("/").pop()?.replace(/\..*$/, "") ?? "";

// Skip module for definition.ts
if (name === "definition") continue;

constituents[name] = module;
module.names.forEach((name) => {
constituents[name] = module;
});
}

export default constituents;