conversion.go 1.6 KB
Newer Older
Jonny Schäfer's avatar
Jonny Schäfer committed
1
2
3
4
5
6
package radolan

import (
	"math"
)

7
var NaN = float32(math.NaN())
Jonny Schäfer's avatar
Jonny Schäfer committed
8

9
10
11
func IsNaN(f float32) (is bool) {
	return f != f
}
Jonny Schäfer's avatar
Jonny Schäfer committed
12

13
14
15
16
17
18
19
20
21
22
23
24
25
26
// Z-R relationship mathematically expressed as Z = a * R^b
type ZR struct {
	A float64
	B float64
}

// Common Z-R relationships
var (
	Aniol80          = ZR{256, 1.42} // operational use in germany, described in [6]
	Doelling98       = ZR{316, 1.50} // operational use in switzerland
	JossWaldvogel70  = ZR{300, 1.50}
	MarshallPalmer55 = ZR{200, 1.60} // operational use in austria
)

Jonny Schäfer's avatar
Jonny Schäfer committed
27
// PrecipitationRate returns the estimated precipitation rate in mm/h for the given
28
// reflectivity factor and Z-R relationship.
29
30
func PrecipitationRate(relation ZR, dBZ float32) (rate float64) {
	return math.Pow(math.Pow(10, float64(dBZ)/10)/relation.A, 1/relation.B)
Jonny Schäfer's avatar
Jonny Schäfer committed
31
32
}

Jonny Schäfer's avatar
Jonny Schäfer committed
33
// Reflectivity returns the estimated reflectivity factor for the given precipitation
34
// rate (mm/h) and Z-R relationship.
35
36
func Reflectivity(relation ZR, rate float64) (dBZ float32) {
	return float32(10 * math.Log10(relation.A*math.Pow(float64(rate), relation.B)))
Jonny Schäfer's avatar
Jonny Schäfer committed
37
38
}

39
// toDBZ converts the given radar video processor values (rvp-6) to radar reflectivity
Jonny Schäfer's avatar
Jonny Schäfer committed
40
// factors in decibel relative to Z (dBZ).
41
42
func toDBZ(rvp6 float32) (dBZ float32) {
	return rvp6/2.0 - 32.5
Jonny Schäfer's avatar
Jonny Schäfer committed
43
44
}

45
// toRVP6 converts the given radar reflectivity factors (dBZ) to radar video processor
Jonny Schäfer's avatar
Jonny Schäfer committed
46
// values (rvp-6).
47
48
func toRVP6(dBZ float32) float32 {
	return (dBZ + 32.5) * 2
Jonny Schäfer's avatar
Jonny Schäfer committed
49
50
51
52
}

// rvp6Raw converts the raw value to radar video processor values (rvp-6) by applying the
// products precision field.
53
54
func (c *Composite) rvp6Raw(value int) float32 {
	return float32(value) * float32(math.Pow10(c.precision))
Jonny Schäfer's avatar
Jonny Schäfer committed
55
}