Stream Network Simulation
A demonstration of essential elements.
Example
Doodle of the stream network I'm going to encode. Letters are node labels, numbers are attributes of stream segments.
A minimal description of a stream network topology is a list of numbered nodes (first column below) and the ID# of the node downstream of focal node (second column below). To make it interesting, we can also add attributes of the 'edges' (stream segments) that connects two node (thrid column below). This kind of information should be exportable from GIS. The NaN at x(1,2) indicates that the first node has nothing below it. This is like the point of entry to the ocean.
x=[1 NaN 1
2 1 1
3 2 4
4 3 1
5 2 1
6 3 2
7 4 0.5
8 4 1]
Matrix Form
Now convert the list above into a square matrix. The matrix represents all pairwise connections between nodes. Zeros indicate that there is no connection, and entries are the attributes defined in the third column from above.
M=zeros(length(x));
for i=2:length(x)
M(i,x(i,2))= x(i,3);
end
M
Ploting
Give the nodes names.
nodes={'A','B','C','D','E','F','G','H'};
Plot the example
G=digraph(M',nodes)%transpose reverses flow
plot(G,'EdgeLabel',G.Edges.Weight,'NodeColor','red')
The plot is upsidedown. Node A is the point of ocean entrance, with minor tributaries on the bottom of the plot.The arrows give the direction a fish would travel going upstream. Numerical values on stream segments are the attributes inputed above.
Simulating a Single Iteration with Matrix Algebra.
Now lets do someting. Start with a list containing the number of individuals at each node
N=[3,2,1,10,5,8,4,9]'%This must be a vertical vector
Propagating these individuals through the network and having them "interact" with the edge attribute is accomplished with a simple matrix algebra computation:
N_prime=M*N
Interpretation
The first number in N is 3, meaning that we have 3 individuals at Node A. These individuals were then multiplied by 1 and then the result was moved up to Node B. This result is stored as the second entry into N_prime. We began with 2 individuals at Node B. These individuals were multipled by 1 and then placed in Node E (fifth entry of N_prime). Individuals from Node B were also multiplied by 4 and then placed into Node C (third entry of N_prime).
Take home
We can perform computations on a stream network and simulate movement, reproduction, or death of individuals on actual GIS stream layers. Using matrix algebra means that this compuations will occur with virtually no delay, even on enormous stream networks.