# Flow Accumulation Python or MATLAB Script

does anyone have any resources for scripting the D8 flow accumulation in Python or MATLAB after obtaining the flow direction values and filling in 'sinks' and 'flats'?

I am trying to understand the logic so that I can apply a similar algorithm to a land use raster.

• Thanks for the link. I am looking for more of the source program so that I can better understand how they process the flow direction values to determine flow accumulation. Dec 5, 2015 at 22:13

You might want to have a look at these Matlab functions

http://www.mathworks.com/matlabcentral/fileexchange/50124-topotoolbox

More specificaly, you can generate a flow accumulation matrix using

DEM = GRIDobj('YourRaster.tif');
FD = FLOWobj(DEM,'preprocess','carve');
A = flowacc(FD);
• I think he/she wants the source not the arguments. Jan 15, 2016 at 16:27
• Hein? He is asking for a Matlab or Python source program. Just click on the link download the functions, open it and read ? Feb 2, 2016 at 14:52

David Tarboton does a good job of breaking it down at http://hydrology.usu.edu/taudem/taudem5/help53/D8FlowDirections.html

basically as does Jenson.

Jenson, S. K., and J. O. Domingue. 1988. "Extracting Topographic Structure from Digital Elevation Data for Geographic Information System Analysis." Photogrammetric Engineering and Remote Sensing 54 (11): 1593–1600.

It is really quite simple.

1. Slope (usually standard nine pixel Kernel using rise over run)

1. Convert steepest slope of each pixel to a convention, see center small bit below. North is 64 in this convention.

1. Now accumulate.

When two slopes are equal in step 2 just expand the search region (using only the equal slopes) until one becomes steeper.

If you are talking about Deterministic Modelling, you can look at PCRaster Python Framework

There is a chapter which talks about Deterministic Modelling and provides examples.