-
Notifications
You must be signed in to change notification settings - Fork 0
/
inversion.go
64 lines (51 loc) · 1.51 KB
/
inversion.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
package inversion
import (
"errors"
"github.com/babattles/snoqualmie-crust-calculator/models"
)
var (
ErrImproperElevationOrdering = errors.New("improper elevation ordering")
)
type InversionData struct {
LowerElevationFt int
HigherElevationFt int
InversionPresent bool
}
// for each elevation band, return if there was an inversion between it and the above elevation band
// (the uppermost elevation band will always be false)
func FindInversionsAbove(data []models.WeatherStationData) []bool {
// sort first for peace of mind
models.SortByElevation(data)
res := make([]bool, len(data))
for i, layer := range(data) {
// uppermost layer
if i == len(data) - 1 {
res[i] = false
return res
}
res[i] = temperatureInversionExists(layer, data[i+1])
}
return res
}
// for each elevation band, return if there was an inversion between it and the elevation band below
// (the lowest elevation band will always be false)
func FindInversionsBelow(data []models.WeatherStationData) []bool {
// sort first for peace of mind
models.SortByElevation(data)
res := make([]bool, len(data))
for i := len(data)-1; i >= 0; i-- {
// lowest layer
if i == 0 {
res[i] = false
return res
}
res[i] = temperatureInversionExists(data[i-1], data[i])
}
return res
}
// calculates if there was a temperature inversion between two elevation bands
func temperatureInversionExists(
lowerBand models.WeatherStationData, higherBand models.WeatherStationData,
) bool {
return higherBand.TemperatureF > lowerBand.TemperatureF
}