def process_wsheds(bluespots, flowdir, out): """Bluespot watersheds. Assign bluespot ID to all cells within the local bluespot watershed. """ bspot_reader = io.RasterReader(bluespots) flowdir_reader = io.RasterReader(flowdir) wshed_writer = io.RasterWriter(out, bspot_reader.transform, bspot_reader.crs, 0) watersheds = bspot_reader.read() flowdir = flowdir_reader.read() flow.watersheds_from_labels(flowdir, watersheds, unassigned=0) wshed_writer.write(watersheds)
def test_watersheds(flowdirdata, bspotdata): speedups.disable() assert not speedups.enabled watersheds = np.copy(bspotdata) flow.watersheds_from_labels(flowdirdata, watersheds, unassigned=0) labelled_indexes = bspotdata > 0 assert np.all(watersheds[labelled_indexes] == bspotdata[labelled_indexes]) assert np.max(watersheds) == np.max(bspotdata) assert np.sum(watersheds) == 2337891 # Check that all watersheds are a connected component for lbl in range(1, np.max(watersheds) + 1): labeled, nlabels = label.connected_components(watersheds == lbl) assert nlabels == 1, "Watershed {} is not a connected component".format( lbl)