conversion.go 1.88 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
// Z-R relationship
14
type ZR struct {
15
16
17
18
19
	// intermediate caching
	c1 float64 // 10*b
	c2 float64 // a^(-1/b)
	c3 float64 // 10^(1/(10*b))
	c4 float64 // 10 * log10(a)
20
21
22
23
}

// Common Z-R relationships
var (
Jonny Schäfer's avatar
Jonny Schäfer committed
24
	Aniol80          = NewZR(256, 1.42) // operational use in germany, described in [5]
25
26
27
	Doelling98       = NewZR(316, 1.50) // operational use in switzerland
	JossWaldvogel70  = NewZR(300, 1.50)
	MarshallPalmer55 = NewZR(200, 1.60) // operational use in austria
28
29
)

30
31
32
33
34
35
36
37
38
39
// New Z-R returns a Z-R relationship mathematically expressed as Z = a * R^b
func NewZR(A, B float64) ZR {
	c1 := 10.0 * B
	c2 := math.Pow(A, -1.0/B)
	c3 := math.Pow(10.0, 1/c1)
	c4 := 10.0 * math.Log10(A)

	return ZR{c1, c2, c3, c4}
}

Jonny Schäfer's avatar
Jonny Schäfer committed
40
// PrecipitationRate returns the estimated precipitation rate in mm/h for the given
41
// reflectivity factor and Z-R relationship.
42
func PrecipitationRate(relation ZR, dBZ float32) (rate float64) {
43
	return relation.c2 * math.Pow(relation.c3, float64(dBZ))
Jonny Schäfer's avatar
Jonny Schäfer committed
44
45
}

Jonny Schäfer's avatar
Jonny Schäfer committed
46
// Reflectivity returns the estimated reflectivity factor for the given precipitation
47
// rate (mm/h) and Z-R relationship.
48
func Reflectivity(relation ZR, rate float64) (dBZ float32) {
49
	return float32(relation.c4 + relation.c1 * math.Log10(rate))
Jonny Schäfer's avatar
Jonny Schäfer committed
50
51
}

52
// toDBZ converts the given radar video processor values (rvp-6) to radar reflectivity
Jonny Schäfer's avatar
Jonny Schäfer committed
53
// factors in decibel relative to Z (dBZ).
54
55
func toDBZ(rvp6 float32) (dBZ float32) {
	return rvp6/2.0 - 32.5
Jonny Schäfer's avatar
Jonny Schäfer committed
56
57
}

58
// toRVP6 converts the given radar reflectivity factors (dBZ) to radar video processor
Jonny Schäfer's avatar
Jonny Schäfer committed
59
// values (rvp-6).
60
61
func toRVP6(dBZ float32) float32 {
	return (dBZ + 32.5) * 2
Jonny Schäfer's avatar
Jonny Schäfer committed
62
63
64
65
}

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