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
2 changes: 1 addition & 1 deletion packages/neaps/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
"prepack": "npm run build"
},
"dependencies": {
"@neaps/tide-database": "0.2",
"@neaps/tide-predictor": "^0.2.0",
"@neaps/tide-database": "0.1",
"geolib": "^3.3.4"
}
}
5 changes: 1 addition & 4 deletions packages/neaps/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,7 @@ export function useStation(station: Station, distance?: number) {
offset = mslOffset - datumOffset
}

return tidePredictor(harmonic_constituents, {
phaseKey: 'phase_UTC',
offset
})
return tidePredictor(harmonic_constituents, { offset })
}

return {
Expand Down
24 changes: 10 additions & 14 deletions packages/tide-predictor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,15 @@ import TidePredictor from '@neaps/tide-predictor'

const constituents = [
{
phase_GMT: 98.7,
phase_local: 313.7,
phase: 98.7,
amplitude: 2.687,
name: 'M2',
speed: 28.984104
}
//....there are usually many, read the docs
]

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

- `constituents` - An array of [constituent objects](#constituent-object)
- `options` - An object with one of:
- `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`).
- `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.

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

- `name` - **string** - The NOAA constituent name, all upper-case.
- `amplitude` - **float** - The constituent amplitude
- `[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.
- `phase` - **float** - The phase of the constituent.

```
```json
[
{
name: '[constituent name]',
amplitude: 1.3,
phase: 1.33
"name": "[constituent name]",
"amplitude": 1.3,
"phase": 1.33
},
{
name: '[constituent name 2]',
amplitude: 1.3,
phase: 1.33
"name": "[constituent name 2]",
"amplitude": 1.3,
"phase": 1.33
}
]
```
Expand Down
6 changes: 2 additions & 4 deletions packages/tide-predictor/src/harmonics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export type * from './prediction.js'

export interface HarmonicsOptions {
harmonicConstituents: HarmonicConstituent[]
phaseKey: string
offset: number | false
}

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

const harmonicsFactory = ({
harmonicConstituents,
phaseKey,
offset
}: HarmonicsOptions): Harmonics => {
if (!Array.isArray(harmonicConstituents)) {
Expand All @@ -69,7 +67,7 @@ const harmonicsFactory = ({
constituents.push({
...constituent,
_model: constituentModels[constituent.name],
_phase: d2r * constituent[phaseKey]
phase: d2r * constituent.phase
})
}
})
Expand All @@ -78,7 +76,7 @@ const harmonicsFactory = ({
constituents.push({
name: 'Z0',
_model: constituentModels.Z0,
_phase: 0,
phase: 0,
amplitude: offset
})
}
Expand Down
9 changes: 4 additions & 5 deletions packages/tide-predictor/src/harmonics/prediction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ export interface Timeline {
export interface HarmonicConstituent {
name: string
amplitude: number
// This needs refactored to support generics with the `phaseKey` option
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[key: string]: any
phase: number
speed?: number
description?: string
}

export interface InternalHarmonicConstituent extends HarmonicConstituent {
_phase: number
_model: Constituent | CompoundConstituent
}

Expand Down Expand Up @@ -141,7 +140,7 @@ const predictionFactory = ({

constituents.forEach((constituent) => {
const amplitude = constituent.amplitude
const phase = constituent._phase
const phase = constituent.phase
const f = modelF[constituent.name]
const speed = modelBaseSpeed[constituent.name]
const u = modelU[constituent.name]
Expand Down
2 changes: 0 additions & 2 deletions packages/tide-predictor/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import type {
} from './harmonics/prediction.js'

export interface TidePredictionOptions {
phaseKey?: string
offset?: number | false
}

Expand Down Expand Up @@ -38,7 +37,6 @@ const tidePredictionFactory = (
): TidePrediction => {
const harmonicsOptions = {
harmonicConstituents: constituents,
phaseKey: 'phase_GMT',
offset: false as number | false,
...options
}
Expand Down
Loading