-
Notifications
You must be signed in to change notification settings - Fork 2
/
var_wisdom.py
134 lines (124 loc) · 3.97 KB
/
var_wisdom.py
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
_var_wisdom = {
'T2' : {
'name' : 'temperature at 2m',
'native_unit' : 'K',
'colorbar_units' : ['C', 'F'],
'colormap' : 'jet',
'scale' : 'original',
'retrieve_as' : lambda d,t: d.variables['T2'][t,:,:]
},
'RH_FIRE' : {
'name' : 'relative humidity',
'native_unit' : '-',
'colorbar_units' : ['-'],
'colormap' : 'jet_r',
'scale' : [0.0, 1.0],
'retrieve_as' : lambda d,t: d.variables['RH_FIRE'][t,:,:]
},
'FIRE_HFX' : {
'name' : 'fire heat flux',
'native_unit' : 'W/m^2',
'colorbar_units' : ['W/m^2'],
'colormap' : 'jet',
'scale' : 'original',
'retrieve_as' : lambda d,t: d.variables['FIRE_HFX'][t,:,:]
},
'F_ROS' : {
'name' : 'fire spread rate',
'native_unit' : 'm/s',
'colorbar_units' : ['m/s', 'ft/s'],
'colormap' : 'jet',
'scale' : [0.0, 2.0],
'retrieve_as' : lambda d,t: d.variables['F_ROS'][t,:,:]
},
'F_INT' : {
'name' : 'fireline intensity',
'native_unit' : 'J/m/s^2',
'colorbar_units' : ['J/m/s^2'],
'colormap' : 'jet',
'scale' : 'original',
'retrieve_as' : lambda d,t: d.variables['F_INT'][t,:,:]
},
'NFUEL_CAT' : {
'name' : 'fuel categories',
'native_unit' : 'fuel_type',
'colorbar_units' : ['fuel_type'],
'colormap' : 'jet',
'scale' : 'original',
'retrieve_as' : lambda d,t: d.variables['NFUEL_CAT'][t,:,:]
},
'ZSF' : {
'name' : 'terrain height',
'native_unit' : 'm',
'colorbar_units' : ['m','ft'],
'colormap' : 'jet',
'scale' : 'original',
'retrieve_as' : lambda d,t: d.variables['ZSF'][t,:,:]
},
'FMC_G' : {
'name' : 'fuel moisture',
'native_unit' : '-',
'colorbar_units' : ['-'],
'colormap' : 'jet_r',
'scale' : [0.0, 0.5],
'retrieve_as' : lambda d,t: d.variables['FMC_G'][t,:,:]
},
'1HR_FM' : {
'name' : '1-HR fuel moisture',
'native_unit' : '-',
'colorbar_units' : ['-'],
'colormap' : 'jet_r',
'scale' : [0.0, 1.0],
'retrieve_as' : lambda d,t: d.variables['FMC_GC'][t,0,:,:]
},
'10HR_FM' : {
'name' : '10-HR fuel moisture',
'native_unit' : '-',
'colorbar_units' : ['-'],
'colormap' : 'jet_r',
'scale' : [0.0, 1.0],
'retrieve_as' : lambda d,t: d.variables['FMC_GC'][t,1,:,:]
},
'100HR_FM' : {
'name' : '100-HR fuel moisture',
'native_unit' : '-',
'colorbar_units' : ['-'],
'colormap' : 'jet_r',
'scale' : [0.0, 1.0],
'retrieve_as' : lambda d,t: d.variables['FMC_GC'][t,2,:,:]
},
'FMC_EQUI' : {
'name' : 'fuel moisture equilibrium',
'native_unit' : '-',
'colorbar_units' : ['-'],
'colormap' : 'jet_r',
'scale' : [0.0, 1.0],
'retrieve_as' : lambda d,t: d.variables['FMC_EQUI'][t,0,:,:]
}
}
# contains functions to transform values from one unit to another in a simple format.
# it's a dictionary with keys in the form (from_unit, to_unit) and the value is a lambda
# that maps the value from <from_unit> to <to_unit>.
_units_wisdom = {
('K', 'C') : lambda x: x - 273.15,
('K', 'F') : lambda x: 9.0 / 5.0 * (x - 273.15) + 32,
('m/s', 'ft/s') : lambda x: 3.2808399 * x,
('m', 'ft') : lambda x: 3.2808399 * x,
('ft/s','m/s') : lambda x: x / 3.2808399,
('ft', 'm') : lambda x: x / 3.2808399
}
def get_wisdom(var_name):
"""Return rendering wisdom for the variable <var_name>."""
return _var_wisdom[var_name]
def get_wisdom_variables():
"""Return the variables for which wisdom is available."""
return _var_wisdom.keys()
def convert_value(unit_from, unit_to, value):
# handle the simple case
if unit_from == unit_to:
return value
func = _units_wisdom.get((unit_from, unit_to))
if func is None:
return None
else:
return func(value)