This repository has been archived by the owner on Jan 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathswell.go
104 lines (86 loc) · 2.45 KB
/
swell.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package surfnerd
import (
"math"
)
type Swell struct {
WaveHeight float64
Period float64
Direction float64
CompassDirection string
// Metadata
MaxEnergy float64 `json:",omitempty"`
FrequencyIndex int `json:",omitempty"`
Units UnitSystem
}
func (s *Swell) ChangeUnits(newUnits UnitSystem) {
if s.Units == newUnits {
return
} else if !s.IsValid() {
s.Units = newUnits
return
}
switch newUnits {
case Metric:
s.WaveHeight = FeetToMeters(s.WaveHeight)
case English:
s.WaveHeight = MetersToFeet(s.WaveHeight)
default:
}
s.Units = newUnits
}
// Tests if the swell has valid numbers or if it is just maxed out to show null
func (s *Swell) IsValid() bool {
if s.WaveHeight > 1000 {
return false
}
return true
}
// Interpolates the approximate breaking wave heights using the contained swell data. Data must
// be in metric units prior to calling this function. The depth argument must be in meters.
func (s *Swell) BreakingWaveHeights(beachAngle, depth, beachSlope float64) (minimumBreakHeight, maximumBreakHeight float64) {
if !s.IsValid() {
return
}
var waveBreakingHeight float64 = 0.0
if s.WaveHeight < 1000 {
incidentAngle := math.Mod(math.Abs(s.Direction-beachAngle), 360.0)
if incidentAngle < 90 {
waveBreakingHeight, _ = SolveBreakingCharacteristics(s.Period, incidentAngle, s.WaveHeight, beachSlope, depth)
}
}
// Take the maximum breaking height and give it a scale factor of 0.9 for refraction
// or anything we are not checking for.
breakingHeight := 0.8 * waveBreakingHeight
// For now assume this is significant wave height as the max and the rms as the min
maximumBreakHeight = breakingHeight
minimumBreakHeight = breakingHeight / 1.4
return
}
func NewSwellWithDirection(waveHeight, period, direction float64) Swell {
swell := Swell{
WaveHeight: waveHeight,
Period: period,
Direction: direction,
CompassDirection: DegreeToDirection(direction),
}
return swell
}
func NewSwellWithCompassDirection(waveHeight, period float64, direction string) Swell {
swell := Swell{
WaveHeight: waveHeight,
Period: period,
Direction: DirectionToDegree(direction),
CompassDirection: direction,
}
return swell
}
type ByMaxEnergy []Swell
func (b ByMaxEnergy) Len() int {
return len(b)
}
func (b ByMaxEnergy) Swap(i, j int) {
b[i], b[j] = b[j], b[i]
}
func (b ByMaxEnergy) Less(i, j int) bool {
return b[i].MaxEnergy < b[j].MaxEnergy
}