-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdectree_test.py
More file actions
201 lines (162 loc) · 4.76 KB
/
Copy pathdectree_test.py
File metadata and controls
201 lines (162 loc) · 4.76 KB
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
from numba import jit, jitclass, float64
@jit(nopython=True)
def _Radiance_LOW(x):
# Radiance.LOW: inv_ramp(x1=0, x2=50)
if x < 0.0:
return 1.0
if x > 50.0:
return 0.0
return 1.0 - (x - 0.0) / (50.0 - 0.0)
@jit(nopython=True)
def _Radiance_MIDDLE(x):
# Radiance.MIDDLE: triangle(x1=30, x2=50, x3=100)
if x < 30.0:
return 0.0
if x > 100.0:
return 0.0
if x < 50.0:
return (x - 30.0) / (50.0 - 30.0)
return 1.0 - (x - 50.0) / (100.0 - 50.0)
@jit(nopython=True)
def _Radiance_HIGH(x):
# Radiance.HIGH: ramp(x1=50, x2=120)
if x < 50.0:
return 0.0
if x > 120.0:
return 1.0
return (x - 50.0) / (120.0 - 50.0)
@jit(nopython=True)
def _Glint_LOW(x):
# Glint.LOW: inv_ramp()
if x < 0.0:
return 1.0
if x > 0.5:
return 0.0
return 1.0 - (x - 0.0) / (0.5 - 0.0)
@jit(nopython=True)
def _Glint_HIGH(x):
# Glint.HIGH: ramp()
if x < 0.5:
return 0.0
if x > 1.0:
return 1.0
return (x - 0.5) / (1.0 - 0.5)
@jit(nopython=True)
def _Cloudy_True(x):
# Cloudy.True: true()
return 1.0
@jit(nopython=True)
def _Cloudy_False(x):
# Cloudy.False: false()
return 0.0
@jit(nopython=True)
def _Certain_HIGH(x):
# Certain.HIGH: true()
return 1.0
@jit(nopython=True)
def _Certain_LOW(x):
# Certain.LOW: false()
return 0.0
_InputSpec = [
("glint", float64),
("radiance", float64),
]
@jitclass(_InputSpec)
class Input:
def __init__(self):
self.glint = 0.0
self.radiance = 0.0
_OutputSpec = [
("cloudy", float64),
("certain", float64),
]
@jitclass(_OutputSpec)
class Output:
def __init__(self):
self.cloudy = 0.0
self.certain = 0.0
@jit(nopython=True)
def apply_rules(input, output):
t0 = 1.0
# if radiance == HIGH or radiance == MIDDLE:
t1 = min(t0, max(_Radiance_HIGH(input.radiance), _Radiance_MIDDLE(input.radiance)))
# if glint == LOW:
t2 = min(t1, _Glint_LOW(input.glint))
# cloudy: True
output.cloudy = t2
# certain: HIGH
output.certain = t2
# else:
t2 = 1.0 - (t2)
# if glint == HIGH:
t3 = min(t2, _Glint_HIGH(input.glint))
# certain: LOW
output.certain = max(output.certain, 1.0 - (t3))
# else:
t1 = 1.0 - (t1)
# cloudy: False
#output.cloudy = max(output.cloudy, 1.0 - (t1))
# certain: HIGH
output.certain = max(output.certain, t1)
if __name__ == '__main__':
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
fig, axs = plt.subplots(1, 2, sharey=True)
linewidth = 2
ax = axs[0]
ax.set_title('Radiance')
ax.set_ylabel('Truth')
x = np.arange(-10.0, 130.0, 1.0)
y = np.vectorize(_Radiance_LOW)(x)
ax.plot(x, y, label='LOW', linewidth=linewidth)
y = np.vectorize(_Radiance_MIDDLE)(x)
ax.plot(x, y, label='MIDDLE', linewidth=linewidth)
y = np.vectorize(_Radiance_HIGH)(x)
ax.plot(x, y, label='HIGH', linewidth=linewidth)
ax.legend()
ax = axs[1]
ax.set_title('Glint')
ax.set_ylabel('Truth')
x = np.arange(-0.1, 1.1, 0.01)
y = np.vectorize(_Glint_LOW)(x)
ax.plot(x, y, label='LOW', linewidth=linewidth)
y = np.vectorize(_Glint_HIGH)(x)
ax.plot(x, y, label='HIGH', linewidth=linewidth)
ax.legend()
plt.show()
##########################################################
# Make 3D data.
x = np.arange(-10., 130., 1.)
y = np.arange(-0.1, 1.1, 0.01)
x, y = np.meshgrid(x, y)
z1 = np.zeros(shape=x.shape, dtype=np.float64)
z2 = np.zeros(shape=x.shape, dtype=np.float64)
input = Input()
output = Output()
for j in range(x.shape[-2]):
for i in range(x.shape[-1]):
input.radiance = x[j, i]
input.glint = y[j, i]
apply_rules(input, output)
z1[j, i] = output.cloudy
z2[j, i] = output.certain
fig = plt.figure()
ax = fig.gca(projection='3d')
surf = ax.plot_surface(x, y, z1, cmap=cm.coolwarm, linewidth=0, antialiased=True)
ax.set_zlim(0.0, 1.0)
ax.zaxis.set_major_locator(LinearLocator(10))
ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f'))
fig.colorbar(surf, shrink=0.5, aspect=5)
plt.show()
fig = plt.figure()
ax = fig.gca(projection='3d')
surf = ax.plot_surface(x, y, z2, cmap=cm.coolwarm, linewidth=0, antialiased=True)
ax.set_zlim(0.0, 1.0)
ax.zaxis.set_major_locator(LinearLocator(10))
ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f'))
fig.colorbar(surf, shrink=0.5, aspect=5)
plt.show()