Skip to content

Commit 405a3bc

Browse files
committed
Add D8 flow accumulation module with iterative dask tile sweep
1 parent 5a8952d commit 405a3bc

File tree

3 files changed

+1113
-0
lines changed

3 files changed

+1113
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from xrspatial import flow_direction, flow_accumulation
2+
3+
from .common import Benchmarking, get_xr_dataarray
4+
5+
6+
class FlowAccumulation:
7+
params = ([100, 300, 1000], ["numpy", "dask"])
8+
param_names = ("nx", "type")
9+
10+
def setup(self, nx, type):
11+
ny = nx // 2
12+
elev = get_xr_dataarray((ny, nx), type)
13+
# Compute flow_dir from elevation (materialise for benchmarking)
14+
self.flow_dir = flow_direction(elev)
15+
if hasattr(self.flow_dir.data, 'compute'):
16+
self.flow_dir.data = self.flow_dir.data.compute()
17+
# Re-chunk for dask benchmark
18+
if type == "dask":
19+
import dask.array as da
20+
self.flow_dir.data = da.from_array(
21+
self.flow_dir.data,
22+
chunks=(max(1, ny // 2), max(1, nx // 2)),
23+
)
24+
25+
def time_flow_accumulation(self, nx, type):
26+
result = flow_accumulation(self.flow_dir)
27+
if hasattr(result.data, 'compute'):
28+
result.data.compute()

0 commit comments

Comments
 (0)