def test_missing_semantic_label(self): # Prepare imagery group reference struct R = Ref() I_init_group_ref(ctypes.byref(R)) ret = I_add_file_to_group_ref(self.map1, self.mapset, ctypes.byref(R)) self.assertEqual(ret, 0) ret = I_add_file_to_group_ref(self.map2, self.mapset, ctypes.byref(R)) self.assertEqual(ret, 1) ret = I_add_file_to_group_ref(self.map3, self.mapset, ctypes.byref(R)) self.assertEqual(ret, 2) # Prepare signature struct S = Signature() I_init_signatures(ctypes.byref(S), 10) self.assertEqual(S.nbands, 10) sig_count = I_new_signature(ctypes.byref(S)) self.assertEqual(sig_count, 1) S.title = b"Signature title" S.semantic_labels[0] = ctypes.create_string_buffer(b"The_Who") S.sig[0].status = 1 S.sig[0].have_color = 0 S.sig[0].npoints = 42 S.sig[0].desc = b"my label" S.sig[0].mean[0] = 2.5 S.sig[0].var[0][0] = 0.7 # This should result in two error strings in ret ret = I_sort_signatures_by_semantic_label(ctypes.byref(S), ctypes.byref(R)) self.assertTrue(bool(ret)) sig_err = utils.decode(ctypes.cast(ret[0], ctypes.c_char_p).value) ref_err = utils.decode(ctypes.cast(ret[1], ctypes.c_char_p).value) self.assertEqual( sig_err, "<semantic label missing>,<semantic label missing>," + "<semantic label missing>,<semantic label missing>," + "<semantic label missing>,<semantic label missing>," + "<semantic label missing>,<semantic label missing>," + "<semantic label missing>", ) self.assertEqual(ref_err, f"The_Doors,{self.map3}") # Clean up memory to help track memory leaks when run by valgrind S.semantic_labels[0] = None I_free_signatures(ctypes.byref(S)) I_free_group_ref(ctypes.byref(R)) if ret: if ret[0]: self.libc.free(ret[0]) if ret[1]: self.libc.free(ret[1]) self.libc.free(ret)
def test_missing_label(self): # Prepare imagery group reference struct R = Ref() I_init_group_ref(ctypes.byref(R)) ret = I_add_file_to_group_ref(self.map1, self.mapset, ctypes.byref(R)) self.assertEqual(ret, 0) ret = I_add_file_to_group_ref(self.map2, self.mapset, ctypes.byref(R)) self.assertEqual(ret, 1) ret = I_add_file_to_group_ref(self.map3, self.mapset, ctypes.byref(R)) self.assertEqual(ret, 2) # Prepare signature struct S = SigSet() I_InitSigSet(ctypes.byref(S), 10) self.assertEqual(S.nbands, 10) I_NewClassSig(ctypes.byref(S)) self.assertEqual(S.nclasses, 1) I_NewSubSig(ctypes.byref(S), ctypes.byref(S.ClassSig[0])) self.assertEqual(S.ClassSig[0].nsubclasses, 1) S.title = ReturnString("Signature title") S.semantic_labels[0] = ctypes.create_string_buffer(b"The_Who") S.ClassSig[0].used = 1 S.ClassSig[0].classnum = 2 S.ClassSig[0].title = ReturnString("1st class") S.ClassSig[0].type = 1 S.ClassSig[0].SubSig[0].pi = 3.14 S.ClassSig[0].SubSig[0].means[0] = 42.42 S.ClassSig[0].SubSig[0].R[0][0] = 69.69 # This should result in two error strings in ret ret = I_SortSigSetBySemanticLabel(ctypes.byref(S), ctypes.byref(R)) self.assertTrue(bool(ret)) sig_err = utils.decode(ctypes.cast(ret[0], ctypes.c_char_p).value) ref_err = utils.decode(ctypes.cast(ret[1], ctypes.c_char_p).value) self.assertEqual( sig_err, "<semantic label missing>,<semantic label missing>," + "<semantic label missing>,<semantic label missing>," + "<semantic label missing>,<semantic label missing>," + "<semantic label missing>,<semantic label missing>," + "<semantic label missing>", ) self.assertEqual(ref_err, f"The_Doors,{self.map3}") # Clean up memory to help track memory leaks when run by valgrind I_free_group_ref(ctypes.byref(R)) if ret: if ret[0]: self.libc.free(ret[0]) if ret[1]: self.libc.free(ret[1]) self.libc.free(ret)
def test_single_complete_match(self): # Prepare imagery group reference struct R = Ref() I_init_group_ref(ctypes.byref(R)) ret = I_add_file_to_group_ref(self.map1, self.mapset, ctypes.byref(R)) self.assertEqual(ret, 0) # Prepare signature struct S = SigSet() I_InitSigSet(ctypes.byref(S), 1) self.assertEqual(S.nbands, 1) I_NewClassSig(ctypes.byref(S)) self.assertEqual(S.nclasses, 1) I_NewSubSig(ctypes.byref(S), ctypes.byref(S.ClassSig[0])) self.assertEqual(S.ClassSig[0].nsubclasses, 1) S.title = ReturnString("Signature title") S.semantic_labels[0] = ctypes.create_string_buffer(b"The_Doors") S.ClassSig[0].used = 1 S.ClassSig[0].classnum = 2 S.ClassSig[0].title = ReturnString("1st class") S.ClassSig[0].type = 1 S.ClassSig[0].SubSig[0].pi = 3.14 S.ClassSig[0].SubSig[0].means[0] = 42.42 S.ClassSig[0].SubSig[0].R[0][0] = 69.69 # This should result in returning NULL ret = I_SortSigSetBySemanticLabel(ctypes.byref(S), ctypes.byref(R)) self.assertFalse(bool(ret)) semantic_label = utils.decode( ctypes.cast(S.semantic_labels[0], ctypes.c_char_p).value ) self.assertEqual(semantic_label, "The_Doors") self.assertEqual(S.ClassSig[0].SubSig[0].pi, 3.14) self.assertEqual(S.ClassSig[0].SubSig[0].means[0], 42.42) self.assertEqual(S.ClassSig[0].SubSig[0].R[0][0], 69.69) # Clean up memory to help track memory leaks when run by valgrind I_free_group_ref(ctypes.byref(R)) if ret: if ret[0]: self.libc.free(ret[0]) if ret[1]: self.libc.free(ret[1]) self.libc.free(ret)
def test_single_complete_match(self): # Prepare imagery group reference struct R = Ref() I_init_group_ref(ctypes.byref(R)) ret = I_add_file_to_group_ref(self.map1, self.mapset, ctypes.byref(R)) self.assertEqual(ret, 0) # Prepare signature struct S = Signature() I_init_signatures(ctypes.byref(S), 1) self.assertEqual(S.nbands, 1) sig_count = I_new_signature(ctypes.byref(S)) self.assertEqual(sig_count, 1) S.title = b"Signature title" S.semantic_labels[0] = ctypes.create_string_buffer(b"The_Doors") S.sig[0].status = 1 S.sig[0].have_color = 0 S.sig[0].npoints = 42 S.sig[0].desc = b"my label" S.sig[0].mean[0] = 2.5 S.sig[0].var[0][0] = 0.7 # This should result in returning NULL ret = I_sort_signatures_by_semantic_label(ctypes.byref(S), ctypes.byref(R)) self.assertFalse(bool(ret)) semantic_label = utils.decode( ctypes.cast(S.semantic_labels[0], ctypes.c_char_p).value) self.assertEqual(semantic_label, "The_Doors") self.assertEqual(S.sig[0].mean[0], 2.5) self.assertEqual(S.sig[0].var[0][0], 0.7) # Clean up memory to help track memory leaks when run by valgrind S.semantic_labels[0] = None I_free_signatures(ctypes.byref(S)) I_free_group_ref(ctypes.byref(R)) if ret: if ret[0]: self.libc.free(ret[0]) if ret[1]: self.libc.free(ret[1]) self.libc.free(ret)
def test_complete_match_reorder(self): # Prepare imagery group reference struct R = Ref() I_init_group_ref(ctypes.byref(R)) ret = I_add_file_to_group_ref(self.map1, self.mapset, ctypes.byref(R)) self.assertEqual(ret, 0) ret = I_add_file_to_group_ref(self.map2, self.mapset, ctypes.byref(R)) self.assertEqual(ret, 1) # Prepare signature struct S = Signature() I_init_signatures(ctypes.byref(S), 2) self.assertEqual(S.nbands, 2) sig_count = I_new_signature(ctypes.byref(S)) self.assertEqual(sig_count, 1) sig_count = I_new_signature(ctypes.byref(S)) self.assertEqual(sig_count, 2) sig_count = I_new_signature(ctypes.byref(S)) self.assertEqual(sig_count, 3) sig_count = I_new_signature(ctypes.byref(S)) self.assertEqual(sig_count, 4) S.title = b"Signature title" S.semantic_labels[0] = ctypes.create_string_buffer(b"The_Who") S.semantic_labels[1] = ctypes.create_string_buffer(b"The_Doors") S.sig[0].status = 1 S.sig[0].have_color = 0 S.sig[0].npoints = 69 S.sig[0].desc = b"my label2" S.sig[0].mean[0] = 3.3 S.sig[0].mean[1] = 6.6 S.sig[0].var[0][0] = 1.7 S.sig[0].var[1][0] = 1.2 S.sig[0].var[1][1] = 1.8 S.sig[1].status = 1 S.sig[1].have_color = 0 S.sig[1].npoints = 42 S.sig[1].desc = b"my label1" S.sig[1].mean[0] = 2.2 S.sig[1].mean[1] = 4.4 S.sig[1].var[0][0] = 0.7 S.sig[1].var[1][0] = 0.2 S.sig[1].var[1][1] = 0.8 S.sig[2].status = 1 S.sig[2].have_color = 0 S.sig[2].npoints = 12 S.sig[2].desc = b"my label4" S.sig[2].mean[0] = 5.5 S.sig[2].mean[1] = 9.9 S.sig[2].var[0][0] = 0.9 S.sig[2].var[1][0] = 0.8 S.sig[2].var[1][1] = 0.7 S.sig[3].status = 1 S.sig[3].have_color = 0 S.sig[3].npoints = 21 S.sig[3].desc = b"my label3" S.sig[3].mean[0] = 9.9 S.sig[3].mean[1] = 3.3 S.sig[3].var[0][0] = 0.8 S.sig[3].var[1][0] = 0.7 S.sig[3].var[1][1] = 0.6 # This should result in returning NULL ret = I_sort_signatures_by_semantic_label(ctypes.byref(S), ctypes.byref(R)) self.assertFalse(bool(ret)) # semantic labels and sig items should be swapped # Static items self.assertEqual(S.sig[0].npoints, 69) self.assertEqual(S.sig[1].npoints, 42) self.assertEqual(S.sig[2].npoints, 12) self.assertEqual(S.sig[3].npoints, 21) # Reordered items semantic_label1 = utils.decode( ctypes.cast(S.semantic_labels[0], ctypes.c_char_p).value) self.assertEqual(semantic_label1, "The_Doors") semantic_label2 = utils.decode( ctypes.cast(S.semantic_labels[1], ctypes.c_char_p).value) self.assertEqual(semantic_label2, "The_Who") self.assertEqual(S.sig[0].mean[0], 6.6) self.assertEqual(S.sig[0].mean[1], 3.3) self.assertEqual(S.sig[0].var[0][0], 1.8) self.assertEqual(S.sig[0].var[1][0], 1.2) self.assertEqual(S.sig[0].var[1][1], 1.7) self.assertEqual(S.sig[1].mean[0], 4.4) self.assertEqual(S.sig[1].mean[1], 2.2) self.assertEqual(S.sig[1].var[0][0], 0.8) self.assertEqual(S.sig[1].var[1][0], 0.2) self.assertEqual(S.sig[1].var[1][1], 0.7) self.assertEqual(S.sig[2].mean[0], 9.9) self.assertEqual(S.sig[2].mean[1], 5.5) self.assertEqual(S.sig[2].var[0][0], 0.7) self.assertEqual(S.sig[2].var[1][0], 0.8) self.assertEqual(S.sig[2].var[1][1], 0.9) self.assertEqual(S.sig[3].mean[0], 3.3) self.assertEqual(S.sig[3].mean[1], 9.9) self.assertEqual(S.sig[3].var[0][0], 0.6) self.assertEqual(S.sig[3].var[1][0], 0.7) self.assertEqual(S.sig[3].var[1][1], 0.8) # Clean up memory to help track memory leaks when run by valgrind S.semantic_labels[0] = None S.semantic_labels[1] = None I_free_signatures(ctypes.byref(S)) I_free_group_ref(ctypes.byref(R)) if ret: if ret[0]: self.libc.free(ret[0]) if ret[1]: self.libc.free(ret[1]) self.libc.free(ret)
def test_double_complete_match_same_order(self): # Prepare imagery group reference struct R = Ref() I_init_group_ref(ctypes.byref(R)) ret = I_add_file_to_group_ref(self.map2, self.mapset, ctypes.byref(R)) self.assertEqual(ret, 0) ret = I_add_file_to_group_ref(self.map1, self.mapset, ctypes.byref(R)) self.assertEqual(ret, 1) # Prepare signature struct S = SigSet() I_InitSigSet(ctypes.byref(S), 2) self.assertEqual(S.nbands, 2) I_NewClassSig(ctypes.byref(S)) self.assertEqual(S.nclasses, 1) I_NewSubSig(ctypes.byref(S), ctypes.byref(S.ClassSig[0])) self.assertEqual(S.ClassSig[0].nsubclasses, 1) S.title = ReturnString("Signature title") S.semantic_labels[0] = ctypes.create_string_buffer(b"The_Who") S.semantic_labels[1] = ctypes.create_string_buffer(b"The_Doors") S.ClassSig[0].used = 1 S.ClassSig[0].classnum = 2 S.ClassSig[0].title = ReturnString("1st class") S.ClassSig[0].type = 1 S.ClassSig[0].SubSig[0].pi = 3.14 S.ClassSig[0].SubSig[0].means[0] = 42.42 S.ClassSig[0].SubSig[0].means[1] = 24.24 S.ClassSig[0].SubSig[0].R[0][0] = 69.69 S.ClassSig[0].SubSig[0].R[0][1] = 96.96 S.ClassSig[0].SubSig[0].R[1][0] = -69.69 S.ClassSig[0].SubSig[0].R[1][1] = -96.96 # This should result in returning NULL ret = I_SortSigSetBySemanticLabel(ctypes.byref(S), ctypes.byref(R)) self.assertFalse(bool(ret)) # Semantic labels and sig items should not be swapped # Static items self.assertEqual(S.ClassSig[0].SubSig[0].pi, 3.14) # Reordered items semantic_label1 = utils.decode( ctypes.cast(S.semantic_labels[0], ctypes.c_char_p).value ) self.assertEqual(semantic_label1, "The_Who") semantic_label2 = utils.decode( ctypes.cast(S.semantic_labels[1], ctypes.c_char_p).value ) self.assertEqual(semantic_label2, "The_Doors") self.assertEqual(S.ClassSig[0].SubSig[0].means[0], 42.42) self.assertEqual(S.ClassSig[0].SubSig[0].means[1], 24.24) self.assertEqual(S.ClassSig[0].SubSig[0].R[0][0], 69.69) self.assertEqual(S.ClassSig[0].SubSig[0].R[0][1], 96.96) self.assertEqual(S.ClassSig[0].SubSig[0].R[1][0], -69.69) self.assertEqual(S.ClassSig[0].SubSig[0].R[1][1], -96.96) # Clean up memory to help track memory leaks when run by valgrind I_free_group_ref(ctypes.byref(R)) if ret: if ret[0]: self.libc.free(ret[0]) if ret[1]: self.libc.free(ret[1]) self.libc.free(ret)