def test_centroids_check_pass(self): """Test vector data in Centroids""" data_vec = TestVector.data_vector() centr = Centroids() centr.lat, centr.lon, centr.geometry = data_vec centr.check() self.assertEqual(centr.crs, data_vec[2].crs) self.assertIsInstance(centr.total_bounds, tuple) for i in range(4): self.assertEqual(centr.total_bounds[i], data_vec[2].total_bounds[i]) self.assertIsInstance(centr.lat, np.ndarray) self.assertIsInstance(centr.lon, np.ndarray) self.assertIsInstance(centr.coord, np.ndarray) self.assertTrue(np.array_equal(centr.lat, VEC_LAT)) self.assertTrue(np.array_equal(centr.lon, VEC_LON)) self.assertTrue( np.array_equal(centr.coord, np.array([VEC_LAT, VEC_LON]).transpose())) self.assertEqual(centr.size, VEC_LON.size) centr.area_pixel = np.array([1]) with self.assertRaises(ValueError): centr.check() centr.area_pixel = np.array([]) centr.dist_coast = np.array([1]) with self.assertRaises(ValueError): centr.check() centr.dist_coast = np.array([]) centr.on_land = np.array([1]) with self.assertRaises(ValueError): centr.check() centr.on_land = np.array([]) centr.region_id = np.array([1]) with self.assertRaises(ValueError): centr.check() centr.region_id = np.array([]) centr.lat = np.array([1]) with self.assertRaises(ValueError): centr.check() centr.lat = np.array([]) centr.lon = np.array([1]) with self.assertRaises(ValueError): centr.check() centr.lon = np.array([]) centr.geometry = gpd.GeoSeries(np.ones(1)) with self.assertRaises(ValueError): centr.check()
def test_remove_duplicate_pass(self): """Test remove_duplicate_points""" centr = Centroids() centr.lat, centr.lon, centr.geometry = data_vector() centr.geometry.crs = 'epsg:4326' # create duplicates manually: centr.geometry.values[100] = centr.geometry.values[101] centr.geometry.values[120] = centr.geometry.values[101] centr.geometry.values[5] = Point([-59.7, 12.5]) centr.geometry.values[133] = Point([-59.7, 12.5]) centr.geometry.values[121] = Point([-59.7, 12.5]) centr.lon = centr.geometry.apply(lambda pt: pt.x).values centr.lat = centr.geometry.apply(lambda pt: pt.y).values self.assertEqual(centr.size, 296) rem_centr = centr.remove_duplicate_points() self.assertEqual(centr.size, 296) self.assertEqual(rem_centr.size, 292) rem2_centr = rem_centr.remove_duplicate_points() self.assertEqual(rem_centr.size, 292) self.assertEqual(rem2_centr.size, 292)
def test_centroids_check_pass(self): """Test vector data in Centroids""" data_vec = data_vector() centr = Centroids() centr.lat, centr.lon, centr.geometry = data_vec centr.check() self.assertTrue(u_coord.equal_crs(centr.crs, data_vec[2].crs)) self.assertIsInstance(centr.total_bounds, tuple) for i in range(4): self.assertEqual(centr.total_bounds[i], data_vec[2].total_bounds[i]) self.assertIsInstance(centr.lat, np.ndarray) self.assertIsInstance(centr.lon, np.ndarray) self.assertIsInstance(centr.coord, np.ndarray) self.assertTrue(np.array_equal(centr.lat, VEC_LAT)) self.assertTrue(np.array_equal(centr.lon, VEC_LON)) self.assertTrue( np.array_equal(centr.coord, np.array([VEC_LAT, VEC_LON]).transpose())) self.assertEqual(centr.size, VEC_LON.size) centr.area_pixel = np.array([1]) with self.assertRaises(ValueError): centr.check() centr.area_pixel = np.array([]) centr.dist_coast = np.array([1]) with self.assertRaises(ValueError): centr.check() centr.dist_coast = np.array([]) centr.on_land = np.array([1]) with self.assertRaises(ValueError): centr.check() centr.on_land = np.array([]) centr.region_id = np.array([1]) with self.assertRaises(ValueError): centr.check() centr.region_id = np.array([]) centr.lat = np.array([1]) with self.assertRaises(ValueError): centr.check() centr.lat = np.array([]) centr.lon = np.array([1]) with self.assertRaises(ValueError): centr.check() centr.lon = np.array([]) centr.geometry = gpd.GeoSeries(np.ones(1)) with self.assertRaises(ValueError): centr.check() cen = Centroids() cen.meta = { 'width': 10, 'height': 20, 'transform': rasterio.Affine(0.1, 0, 0, 0, 0.1, 0), 'crs': DEF_CRS, } with self.assertRaises(ValueError): cen.check()