Skip to content

Commit eee01d9

Browse files
authored
Merge pull request #184 from neaps/remove-phase-key
Remove support for `phaseKey` option in harmonic constituents.
2 parents c4522be + 15ab4da commit eee01d9

9 files changed

Lines changed: 58 additions & 133 deletions

File tree

packages/neaps/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
"prepack": "npm run build"
3535
},
3636
"dependencies": {
37+
"@neaps/tide-database": "0.2",
3738
"@neaps/tide-predictor": "^0.2.0",
38-
"@neaps/tide-database": "0.1",
3939
"geolib": "^3.3.4"
4040
}
4141
}

packages/neaps/src/index.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,7 @@ export function useStation(station: Station, distance?: number) {
134134
offset = mslOffset - datumOffset
135135
}
136136

137-
return tidePredictor(harmonic_constituents, {
138-
phaseKey: 'phase_UTC',
139-
offset
140-
})
137+
return tidePredictor(harmonic_constituents, { offset })
141138
}
142139

143140
return {

packages/tide-predictor/README.md

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,15 @@ import TidePredictor from '@neaps/tide-predictor'
2424

2525
const constituents = [
2626
{
27-
phase_GMT: 98.7,
28-
phase_local: 313.7,
27+
phase: 98.7,
2928
amplitude: 2.687,
3029
name: 'M2',
3130
speed: 28.984104
3231
}
3332
//....there are usually many, read the docs
3433
]
3534

36-
const highLowTides = TidePredictor(constituents, {
37-
phaseKey: 'phase_GMT'
38-
}).getExtremesPrediction({
35+
const highLowTides = TidePredictor(constituents).getExtremesPrediction({
3936
start: new Date('2019-01-01'),
4037
end: new Date('2019-01-10')
4138
})
@@ -49,7 +46,6 @@ Calling `tidePredictor` will generate a new tide prediction object. It accepts t
4946

5047
- `constituents` - An array of [constituent objects](#constituent-object)
5148
- `options` - An object with one of:
52-
- `phaseKey` - The name of the parameter within constituents that is considered the "phase" because many constituent datum come with multiple phases (in the case of NOAA's data, they are `phase_local` and `phase_GMT`).
5349
- `offset` - A value to add to **all** values predicted. This is useful if you want to, for example, offset tides by mean high water, etc.
5450

5551
### Tide prediction methods
@@ -146,19 +142,19 @@ Tidal constituents should be an array of objects with at least:
146142

147143
- `name` - **string** - The NOAA constituent name, all upper-case.
148144
- `amplitude` - **float** - The constituent amplitude
149-
- `[phase]` - **float** - The phase of the constituent. Because several services provide different phase values, you can choose which one to use when building your tide prediction.
145+
- `phase` - **float** - The phase of the constituent.
150146

151-
```
147+
```json
152148
[
153149
{
154-
name: '[constituent name]',
155-
amplitude: 1.3,
156-
phase: 1.33
150+
"name": "[constituent name]",
151+
"amplitude": 1.3,
152+
"phase": 1.33
157153
},
158154
{
159-
name: '[constituent name 2]',
160-
amplitude: 1.3,
161-
phase: 1.33
155+
"name": "[constituent name 2]",
156+
"amplitude": 1.3,
157+
"phase": 1.33
162158
}
163159
]
164160
```

packages/tide-predictor/src/harmonics/index.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ export type * from './prediction.js'
1111

1212
export interface HarmonicsOptions {
1313
harmonicConstituents: HarmonicConstituent[]
14-
phaseKey: string
1514
offset: number | false
1615
}
1716

@@ -54,7 +53,6 @@ const getTimeline = (start: Date, end: Date, seconds: number = 10 * 60) => {
5453

5554
const harmonicsFactory = ({
5655
harmonicConstituents,
57-
phaseKey,
5856
offset
5957
}: HarmonicsOptions): Harmonics => {
6058
if (!Array.isArray(harmonicConstituents)) {
@@ -69,7 +67,7 @@ const harmonicsFactory = ({
6967
constituents.push({
7068
...constituent,
7169
_model: constituentModels[constituent.name],
72-
_phase: d2r * constituent[phaseKey]
70+
phase: d2r * constituent.phase
7371
})
7472
}
7573
})
@@ -78,7 +76,7 @@ const harmonicsFactory = ({
7876
constituents.push({
7977
name: 'Z0',
8078
_model: constituentModels.Z0,
81-
_phase: 0,
79+
phase: 0,
8280
amplitude: offset
8381
})
8482
}

packages/tide-predictor/src/harmonics/prediction.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@ export interface Timeline {
1111
export interface HarmonicConstituent {
1212
name: string
1313
amplitude: number
14-
// This needs refactored to support generics with the `phaseKey` option
15-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
16-
[key: string]: any
14+
phase: number
15+
speed?: number
16+
description?: string
1717
}
1818

1919
export interface InternalHarmonicConstituent extends HarmonicConstituent {
20-
_phase: number
2120
_model: Constituent | CompoundConstituent
2221
}
2322

@@ -141,7 +140,7 @@ const predictionFactory = ({
141140

142141
constituents.forEach((constituent) => {
143142
const amplitude = constituent.amplitude
144-
const phase = constituent._phase
143+
const phase = constituent.phase
145144
const f = modelF[constituent.name]
146145
const speed = modelBaseSpeed[constituent.name]
147146
const u = modelU[constituent.name]

packages/tide-predictor/src/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import type {
88
} from './harmonics/prediction.js'
99

1010
export interface TidePredictionOptions {
11-
phaseKey?: string
1211
offset?: number | false
1312
}
1413

@@ -38,7 +37,6 @@ const tidePredictionFactory = (
3837
): TidePrediction => {
3938
const harmonicsOptions = {
4039
harmonicConstituents: constituents,
41-
phaseKey: 'phase_GMT',
4240
offset: false as number | false,
4341
...options
4442
}

0 commit comments

Comments
 (0)