def test_regions_eight_pixel_connectivity_float(): arr = np.array([[1, 0, 0, np.nan], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1], [0, 0, 0, 1]], dtype=np.float64) raster = create_test_arr(arr) raster_regions = regions(raster, neighborhood=8) assert len(np.unique(raster_regions.data)) == 3 assert raster.shape == raster_regions.shape
def test_regions_four_pixel_connectivity_int(): arr = np.array( [[0, 0, 0, 0], [0, 4, 0, 0], [1, 4, 4, 0], [1, 1, 1, 0], [0, 0, 0, 0]], dtype=np.int64) raster = create_test_arr(arr) raster_regions = regions(raster, neighborhood=4) assert len(np.unique(raster_regions.data)) == 3 assert raster.shape == raster_regions.shape
def test_regions_four_pixel_connectivity_int(): arr = np.array( [[0, 0, 0, 0], [0, 4, 0, 0], [1, 4, 4, 0], [1, 1, 1, 0], [0, 0, 0, 0]], dtype=np.int64) raster = create_test_arr(arr) # add crs for tests raster = _add_EPSG4326_crs_to_da(raster) raster_regions = regions(raster, neighborhood=4) assert len(np.unique(raster_regions.data)) == 3 assert raster.shape == raster_regions.shape # crs tests assert raster_regions.attrs == raster.attrs for coord in raster.coords: assert np.all(raster_regions[coord] == raster[coord])