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_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()