-
Notifications
You must be signed in to change notification settings - Fork 0
/
endmember.py
201 lines (167 loc) · 5.55 KB
/
endmember.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
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
import numpy as np
import os
import os.path as osp
import cProfile, pstats
import pysptools.util as util
import pysptools.eea as eea
import pysptools.abundance_maps as amp
import numpy as np
_doProfile = False
def profile():
if _doProfile == True:
pr = cProfile.Profile()
pr.enable()
return pr
def stat(pr):
if _doProfile == True:
pr.disable()
ps = pstats.Stats(pr)
ps.strip_dirs()
ps.sort_stats("time")
ps.print_stats()
def ROI(data, path):
r = util.ROIs(data.shape[0], data.shape[1])
r.add("Area", {"rec": (30, 30, 100, 100)})
r.plot(path, colorMap="Accent")
return r
def makeaxes(wvl):
axes = {}
for c in wvl:
axes["wavelength"] = wvl
axes["x"] = "Wavelength"
axes["y"] = "Reflectance"
return axes
def test_amap(data, U, umix_source, path, mask, amaps=None):
if amaps == None:
test_UCLS(data, U, umix_source, mask, path)
test_NNLS(data, U, umix_source, mask, path)
test_FCLS(data, U, umix_source, mask, path)
else:
if "UCLS" in amaps:
test_UCLS(data, U, umix_source, mask, path)
if "NNLS" in amaps:
test_NNLS(data, U, umix_source, mask, path)
if "FCLS" in amaps:
test_FCLS(data, U, umix_source, mask, path)
def test_UCLS(data, U, umix_source, mask, path):
print(" Testing UCLS")
ucls = amp.UCLS()
pr = profile()
if mask is None:
amap = ucls.map(data, U, normalize=True)
else:
amap = ucls.map(data, U, normalize=True, mask=mask)
stat(pr)
print(str(ucls))
ucls.plot(path, suffix=umix_source)
if mask is None:
ucls.plot(path, colorMap="jet", suffix=umix_source + "_mask")
else:
ucls.plot(path, mask=mask, colorMap="jet", suffix=umix_source + "_mask")
ucls.plot(path, interpolation="spline36", suffix=umix_source + "_spline36")
if mask is None:
ucls.plot(
path, interpolation="spline36", columns=2, suffix=umix_source + "_spline36"
)
ucls.plot(path, interpolation="spline36", suffix=umix_source + "_spline36")
else:
ucls.plot(
path,
mask=mask,
interpolation="spline36",
columns=2,
suffix=umix_source + "_spline36",
)
ucls.plot(
path, mask=mask, interpolation="spline36", suffix=umix_source + "_spline36"
)
def test_NNLS(data, U, umix_source, mask, path):
print(" Testing NNLS")
nnls = amp.NNLS()
pr = profile()
amap = nnls.map(data, U, normalize=True)
stat(pr)
print(str(nnls))
nnls.plot(path, colorMap="jet", suffix=umix_source)
if mask is None:
nnls.plot(path, colorMap="jet", suffix=umix_source + "_mask")
else:
nnls.plot(path, mask=mask, colorMap="jet", suffix=umix_source + "_mask")
nnls.plot(path, interpolation="spline36", suffix=umix_source + "_spline36")
def test_FCLS(data, U, umix_source, mask, path):
print(" Testing FCLS")
fcls = amp.FCLS()
pr = profile()
if mask is None:
amap = fcls.map(data, U, normalize=True)
else:
amap = fcls.map(data, U, normalize=True, mask=mask)
stat(pr)
print(str(fcls))
fcls.plot(path, suffix=umix_source)
def test_PPI(data, wvl, path, mask=None):
print("Testing PPI")
ppi = eea.PPI()
pr = profile()
if mask is None:
U = ppi.extract(data, 4, normalize=True)
else:
U = ppi.extract(data, 4, normalize=True, mask=mask)
print(str(ppi))
stat(pr)
print(" End members indexes:", ppi.get_idx())
ppi.plot(path, axes=wvl, suffix="test1")
ppi.plot(path, suffix="test2")
U = U[[0, 1], :]
test_amap(data, U, "PPI", path, mask, amaps="UCLS")
test_amap(data, U, "PPI", path, mask, amaps="NNLS")
test_amap(data, U, "PPI", path, mask, amaps="FCLS")
def test_ATGP(data, wvl, path, mask=None):
print("Testing ATGP")
atgp = eea.ATGP()
pr = profile()
if mask is None:
U = atgp.extract(data, 8, normalize=True)
else:
U = atgp.extract(data, 8, normalize=True, mask=mask)
stat(pr)
print(str(atgp))
print(" End members indexes:", atgp.get_idx())
atgp.plot(path, axes=wvl, suffix="test1")
atgp.plot(path, suffix="test2")
U = U[[0, 1], :]
test_amap(data, U, "ATGP", path, mask, amaps="UCLS")
def test_FIPPI(data, wvl, path, mask=None):
print("Testing FIPPI")
fippi = eea.FIPPI()
pr = profile()
if mask is None:
U = fippi.extract(data, 4, 1, normalize=True)
else:
U = fippi.extract(data, 4, 1, normalize=True, mask=mask)
print(str(fippi))
stat(pr)
print(" End members indexes:", fippi.get_idx())
fippi.plot(path, axes=wvl, suffix="test1")
fippi.plot(path, suffix="test2")
test_amap(data, U, "FIPPI", path, mask, amaps="NNLS")
def test_NFINDR(data, wvl, path, mask=None):
print("Testing NFINDR")
nfindr = eea.NFINDR()
pr = profile()
if mask is None:
U = nfindr.extract(data, 8, maxit=5, normalize=False, ATGP_init=False)
else:
U = nfindr.extract(
data, 8, maxit=5, normalize=False, ATGP_init=False, mask=mask
)
stat(pr)
print(str(nfindr))
print(" Iterations:", nfindr.get_iterations())
print(" End members indexes:", nfindr.get_idx())
nfindr.plot(path, axes=wvl, suffix="test1")
nfindr.plot(path, suffix="test2")
U = U[[0, 1], :]
test_amap(data, U, "NFINDR", path, mask, amaps="UCLS")
test_amap(data, U, "NFINDR", path, mask, amaps="NNLS")
test_amap(data, U, "NFINDR", path, mask, amaps="FCLS")