A rather common hydrological analysis is to take the some result, and sum flows across zones, e.g. administrative areas.
This is a trivial exercise for the boundary conditions of boundary elements (e.g. precipitation on a cell or network node): simply assign the zone identifier, then use it to groupby-sum the data.
However, for internodal/interfacial flows, it isn't as trivial:
- Assign zone indentifiers
- Identify interzone connections (zone_left != zone_right)
- Groupby left-right, then sum (generally)
However, a complication is edge orientation and flow sign convention.
For a 2D mesh:
- Flows can be stored on the edge, but;
- Incoming flow is generally positive, outgoing flow is negative (from the perspective of a cell)
- There are obviously two edge values, with opposite signs (such that they sum to zero for mass conservation)
- We need a convention to render it a unique value. One might consider the edge normal and determine sign that way, or we might simply orient it with increasing x and increasing y, etc.
- This direction then needs to be taken into account while summing.
For a network ("1D"):
- Flow is along edge, instead of across it.
- This makes it at least unique (one flow for each edge)
- Edge directionality is the obvious convention to define sign (flow along direction of edge is positive)
- There may, however, be duplicate connection or in reversed direction (e.g. a bypass flow)
Secondly, in terms of efficiency: UGRID defines a static network; the Xarray data structure (or rather CF conventions) defines the transient nature.
At any rate, we can efficiently map from flows to the interzonal flows using a static weighting. In practice, a CSR matrix seems like the most obvious candidate (with shape (n_zone_connection, n_edge)). The aggregation is just a dot product, then.
There are two obvious ways to return the results:"
- As a table with explicit connectivity via
from_zone, to_zone, flow
- Or as a Ugrid1d network / graph; this can also be easily converted to a geodataframe using existing xugrid utilities.
The second is spatially meaningful, but then requires spatial coordinates for the zones. These can either be automatically generated (some centroid), or perhaps provided by the user.
A rather common hydrological analysis is to take the some result, and sum flows across zones, e.g. administrative areas.
This is a trivial exercise for the boundary conditions of boundary elements (e.g. precipitation on a cell or network node): simply assign the zone identifier, then use it to groupby-sum the data.
However, for internodal/interfacial flows, it isn't as trivial:
However, a complication is edge orientation and flow sign convention.
For a 2D mesh:
For a network ("1D"):
Secondly, in terms of efficiency: UGRID defines a static network; the Xarray data structure (or rather CF conventions) defines the transient nature.
At any rate, we can efficiently map from flows to the interzonal flows using a static weighting. In practice, a CSR matrix seems like the most obvious candidate (with shape
(n_zone_connection, n_edge)). The aggregation is just a dot product, then.There are two obvious ways to return the results:"
from_zone,to_zone,flowThe second is spatially meaningful, but then requires spatial coordinates for the zones. These can either be automatically generated (some centroid), or perhaps provided by the user.