Reason or Problem
flow_accumulation only computes a count of upstream cells draining through each cell. There's no way to weight that accumulation by another raster (e.g. precipitation or snowmelt), so getting a physically meaningful accumulated flux currently requires reimplementing the traversal outside the library.
Proposal
Add an optional weight parameter to flow_accumulation_d8 and the other flow_accumulation functions.
Design:
def flow_accumulation_d8(
flow_dir: xr.DataArray,
weight: xr.DataArray | None = None,
name: str = 'flow_accumulation',
) -> xr.DataArray:
When weight is None, behavior is unchanged. When provided, each output cell equals the sum of weight over itself and all upstream cells draining through it, instead of a cell count. I.s. weight acts like a precipitation or surface melt field.
Usage:
melt_accum = flow_accumulation_d8(flow_dir, weight=melt)
weight must be on the same grid as flow_dir.
Stakeholders and Impacts
Anyone using xarray-spatial for hydrology.
Unresolved Questions
How NaN values in weight should be handled (zero contribution vs. propagating as no-data downstream).
Reason or Problem
flow_accumulationonly computes a count of upstream cells draining through each cell. There's no way to weight that accumulation by another raster (e.g. precipitation or snowmelt), so getting a physically meaningful accumulated flux currently requires reimplementing the traversal outside the library.Proposal
Add an optional
weightparameter toflow_accumulation_d8and the other flow_accumulation functions.Design:
When
weightisNone, behavior is unchanged. When provided, each output cell equals the sum ofweightover itself and all upstream cells draining through it, instead of a cell count. I.s. weight acts like a precipitation or surface melt field.Usage:
weightmust be on the same grid asflow_dir.Stakeholders and Impacts
Anyone using xarray-spatial for hydrology.
Unresolved Questions
How NaN values in
weightshould be handled (zero contribution vs. propagating as no-data downstream).