Commit 2f0a328d authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

The classification map of kNN_SAM_Classifier is now sorted by ascending SA in the z-dimension.


Signed-off-by: Daniel Scheffler's avatarDaniel Scheffler <danschef@gfz-potsdam.de>
parent 4f27c904
Pipeline #4108 failed with stage
in 2 minutes and 14 seconds
......@@ -342,6 +342,13 @@ class kNN_SAM_Classifier(SAM_Classifier):
if self.n_neighbors < angles.shape[2]:
cmap = np.argpartition(angles, k, axis=2)[:, :, :k].astype(np.int16)
angles_min_k = np.partition(angles, k, axis=2)[:, :, :k].astype(np.float32)
# sort cmap by ascending angles
idx_2D = np.argsort(angles_min_k, axis=2).reshape(-1, cmap.shape[2])
cmap = \
cmap.reshape(-1, cmap.shape[2])[np.arange(cmap.shape[0] * cmap.shape[1])[:, np.newaxis], idx_2D]\
.reshape(*cmap.shape)
angles_min_k = np.sort(angles_min_k, axis=2)
else:
cmap = np.tile(np.arange(angles.shape[2]).reshape(1, 1, -1), (*angles.shape[:2], 1))
angles_min_k = angles
......
......@@ -141,9 +141,7 @@ class Test_kNN_SAM_Classifier(unittest.TestCase):
SC = kNN_SAM_Classifier(cluster_centers, n_neighbors=self.n_neighbors, CPUs=None)
cmap_mp = SC.classify(test_gA_pure_endmembers, in_nodataVal=-9999, cmap_nodataVal=-9999)
for i, cl in enumerate(cluster_labels):
self.assertTrue(cl in cmap_mp[0, i, :])
# self.assertTrue(np.array_equal(cmap_mp.flatten(), cluster_labels)) # TODO sort cmap by SC.angles_deg
self.assertTrue(np.array_equal(cmap_mp[:, :, 0].flatten(), cluster_labels))
def test_label_unclassified_pixels_absolute_th(self):
SC = kNN_SAM_Classifier(cluster_centers, n_neighbors=self.n_neighbors, CPUs=None)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment