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 pathbuoydataitem.go
95 lines (83 loc) · 2.98 KB
/
buoydataitem.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
package surfnerd
import (
"math"
"time"
)
// Holds all of the data that a buoy could report in either the Standard Meteorological Data
// or the Detailed Wave Data reports. Refer to http://www.ndbc.noaa.gov/data/realtime2/ for
// detailed descriptions. All
type BuoyDataItem struct {
Date time.Time
// Wind
WindDirection float64 `json:",omitempty"`
WindSpeed float64 `json:",omitempty"`
WindGust float64 `json:",omitempty"`
// Waves
WaveSummary Swell `json:",omitempty"`
SwellComponents []Swell `json:",omitempty"`
Steepness string `json:",omitempty"`
AveragePeriod float64 `json:",omitempty"`
WaveSpectra BuoySpectraItem `json:",omitempty"`
// Meteorology
Pressure float64 `json:",omitempty"`
AirTemperature float64 `json:",omitempty"`
WaterTemperature float64 `json:",omitempty"`
DewpointTemperature float64 `json:",omitempty"`
Visibility float64 `json:",omitempty"`
PressureTendency float64 `json:",omitempty"`
WaterLevel float64 `json:",omitempty"`
// Units
Units UnitSystem
}
func (b *BuoyDataItem) ChangeUnits(newUnits UnitSystem) {
if newUnits == b.Units {
return
}
switch newUnits {
case Metric:
b.WindSpeed = MilesPerHourToMetersPerSecond(b.WindSpeed)
b.WindGust = MilesPerHourToMetersPerSecond(b.WindGust)
b.AirTemperature = FahrenheitToCelsius(b.AirTemperature)
b.WaterTemperature = FahrenheitToCelsius(b.WaterTemperature)
b.DewpointTemperature = FahrenheitToCelsius(b.DewpointTemperature)
b.Pressure = InchMercuryToHectoPascal(b.Pressure)
b.PressureTendency = InchMercuryToHectoPascal(b.PressureTendency)
b.WaterLevel = FeetToMeters(b.WaterLevel)
case English:
b.WindSpeed = MetersPerSecondToMilesPerHour(b.WindSpeed)
b.WindGust = MetersPerSecondToMilesPerHour(b.WindGust)
b.AirTemperature = CelsiusToFahrenheit(b.AirTemperature)
b.WaterTemperature = CelsiusToFahrenheit(b.WaterTemperature)
b.DewpointTemperature = CelsiusToFahrenheit(b.DewpointTemperature)
b.Pressure = HectoPascalToInchMercury(b.Pressure)
b.PressureTendency = HectoPascalToInchMercury(b.Pressure)
b.WaterLevel = FeetToMeters(b.WaterLevel)
}
b.WaveSummary.ChangeUnits(newUnits)
for i, _ := range b.SwellComponents {
b.SwellComponents[i].ChangeUnits(newUnits)
}
b.Units = newUnits
}
// Finds the dominant wave direction
func (b *BuoyDataItem) InterpolateDominantWaveDirection() {
minPeriodDiff := math.Inf(1)
for _, swell := range b.SwellComponents {
periodDiff := math.Abs(swell.Period - b.WaveSummary.Period)
if periodDiff < minPeriodDiff {
minPeriodDiff = periodDiff
b.WaveSummary.CompassDirection = swell.CompassDirection
}
}
}
// Finds the dominant wave period
func (b *BuoyDataItem) InterpolateDominantPeriod() {
minHeightDiff := math.Inf(1)
for _, swell := range b.SwellComponents {
heightDiff := math.Abs(swell.WaveHeight - b.WaveSummary.WaveHeight)
if heightDiff < minHeightDiff {
minHeightDiff = heightDiff
b.WaveSummary.Period = swell.Period
}
}
}