def test_regular_grid(): bounds, _, _ = grid.raster_meta('data/small.tif') df = regular_grid(*bounds, 5, 5) assert len(df) == 40000 assert df.total_bounds[0] >= bounds[0] assert df.total_bounds[1] >= bounds[1] assert df.total_bounds[2] <= bounds[2] assert df.total_bounds[3] <= bounds[3] df = regular_grid(*bounds, 200, 200) assert len(df) == 25 assert df.total_bounds[0] >= bounds[0] assert df.total_bounds[1] >= bounds[1] assert df.total_bounds[2] <= bounds[2] assert df.total_bounds[3] <= bounds[3]
def test_regular_grid_oversize(): bounds, _, _ = grid.raster_meta('data/small.tif') df = regular_grid(*bounds, 5000, 5000) assert len(df) == 1 assert df.total_bounds[0] == bounds[0] assert df.total_bounds[1] == bounds[1] assert df.total_bounds[2] >= bounds[2] assert df.total_bounds[3] >= bounds[3]
def test_regular_grid_overlap(): bounds, _, _ = grid.raster_meta('data/small.tif') size = (bounds[2] - bounds[0], bounds[3] - bounds[1]) size = [i / 10 for i in size] df = regular_grid(*bounds, *size, overlap=.5) assert len(df) == 400 assert df.total_bounds[0] >= bounds[0] assert df.total_bounds[1] >= bounds[1] assert df.total_bounds[2] <= bounds[2] assert df.total_bounds[3] <= bounds[3]
def test_mask_samples(): bounds, shape, crs = grid.raster_meta('data/small.tif') minx, miny, maxx, maxy = bounds size = ((maxx - minx) / 10, (maxy - miny) / 10) samples = regular_grid(*bounds, *size, crs=crs) geom = Polygon(((minx, miny), (maxx, maxy), (maxx, miny), (minx, miny))) mask = GeoDataFrame(index=[0], crs=crs, geometry=[geom]) masked_strict = mask_samples(samples, mask) assert len(samples) > len(masked_strict) masked_intersect = mask_samples(samples, mask, strict=False) assert len(masked_intersect) > len(masked_strict)