Skip to content

weights for flow accumulation #3734

Description

@jkingslake

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:hydrologyArea: hydrologyenhancementNew feature or requestproposalIdea that needs design discussion

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions