def test_without_region_pass(self): """Append centroids without region id.""" centr1 = Centroids() centr1.tag = Tag('file_1.mat', 'description 1') centr1.coord = np.array([[1, 2], [3, 4], [5, 6]]) centr1.id = np.array([5, 7, 9]) centr2 = Centroids() centr2.tag = Tag('file_2.mat', 'description 2') centr2.coord = np.array([[1, 2], [3, 4], [5, 6]]) centr2.id = np.array([5, 7, 9]) centr2.region_id = np.array([1, 1, 1]) centr1.append(centr2) self.assertTrue(np.array_equal(centr1.region_id, np.array([], int))) centr1 = Centroids() centr1.tag = Tag('file_1.mat', 'description 1') centr1.coord = np.array([[1, 2], [3, 4], [5, 6]]) centr1.id = np.array([5, 7, 9]) centr1.region_id = np.array([1, 1, 1]) centr2 = Centroids() centr2.tag = Tag('file_2.mat', 'description 2') centr2.coord = np.array([[1, 2], [3, 4], [5, 6]]) centr2.id = np.array([5, 7, 9]) centr1.append(centr2) self.assertTrue(np.array_equal(centr1.region_id, np.array([1, 1, 1])))
def test_new_elem_pass(self): """Append a centroids with a new element.""" centr1 = Centroids() centr1.tag = Tag('file_1.mat', 'description 1') centr1.coord = np.array([[1, 2], [3, 4], [5, 6]]) centr1.id = np.array([5, 7, 9]) centr1.region_id = np.array([1, 2, 3]) centr1.dist_coast = np.array([1.5, 2.6, 3.5]) centr2 = Centroids() centr2.tag = Tag('file_2.mat', 'description 2') centr2.coord = np.array([[1, 2], [3, 4], [5, 6], [7, 8]]) centr2.id = np.array([6, 7, 9, 1]) centr2.region_id = np.array([3, 4, 5, 6]) centr2.dist_coast = np.array([4.5, 5.6, 6.5, 7.8]) centr1.append(centr2) self.assertEqual(len(centr1.tag.file_name), 2) self.assertEqual(len(centr1.tag.description), 2) self.assertEqual(centr1.coord.shape, (4, 2)) self.assertTrue(np.array_equal(centr1.coord[0, :], [1, 2])) self.assertTrue(np.array_equal(centr1.coord[1, :], [3, 4])) self.assertTrue(np.array_equal(centr1.coord[2, :], [5, 6])) self.assertTrue(np.array_equal(centr1.coord[3, :], [7, 8])) self.assertEqual(centr1.id.shape, (4, )) self.assertTrue(np.array_equal(centr1.id, np.array([5, 7, 9, 1]))) self.assertTrue( np.array_equal(centr1.region_id, np.array([1, 2, 3, 6]))) self.assertTrue( np.array_equal(centr1.dist_coast, np.array([1.5, 2.6, 3.5, 7.8])))
def good_centroids(): """Define well a Centroids""" cen = Centroids() cen.coord = np.array([[1, 2], [3, 4], [5, 6]]) cen.id = np.array([1, 2, 3]) cen.region_id = np.array([1, 2, 3]) return cen
def test_select_pass(self): """ Select successfully.""" centr_brb = Centroids(CENTR_BRB) centr_brb.region_id = np.arange(centr_brb.size) sel_brb = centr_brb.select(reg_id=5) self.assertEqual(sel_brb.size, 1) self.assertEqual(sel_brb.id.size, 1) self.assertEqual(sel_brb.region_id.size, 1) self.assertEqual(sel_brb.dist_coast.size, 1) self.assertEqual(sel_brb.region_id[0], 5) self.assertEqual(sel_brb.coord.shape, (1, 2))
def test_select_prop_list_pass(self): """ Select successfully with a property set.""" centr_brb = Centroids(CENTR_BRB) centr_brb.region_id = np.arange(centr_brb.size) centr_brb.set_on_land() sel_brb = centr_brb.select(reg_id=[4, 5]) self.assertEqual(sel_brb.size, 2) self.assertEqual(sel_brb.id.size, 2) self.assertEqual(sel_brb.region_id.size, 2) self.assertEqual(sel_brb.on_land.size, 2) self.assertEqual(sel_brb.dist_coast.size, 2) self.assertTrue(np.array_equal(sel_brb.region_id, [4, 5])) self.assertEqual(sel_brb.coord.shape, (2, 2))