Python script for comparing "zonal statistics" implementations/algorithms

README.md 2.3KB

zonalbenchmark

Python script for comparing "zonal statistics" of different implementations/algorithms.

Usage

1) make sure to run in a path without spaces, some implementations (GRASS) can not handle spaces 2) it is assumed you already have the tools installed; if not do (assuming you're using Ubuntu):

-- ubuntu gis repo
sudo add-apt-repository ppa:ubuntugis/ppa
sudo apt-get update

-- pktools
sudo apt-get install pktools

-- oft
sudo apt-get install gcc g++ gdal-bin libgdal1-dev libgsl0-dev libgsl0ldbl libproj-dev python-gdal python-scipy python-tk python-qt4 perl
wget http://foris.fao.org/static/geospatialtoolkit/releases/OpenForisToolkit.run
sudo chmod u+x OpenForisToolkit.run
sudo ./OpenForisToolkit.run

-- grass 
sudo apt-get install grass

-- saga
sudo apt-get install saga

3) run the help or read here:

Usage:
        python zonalStatBenchmark [tools] [input raster] [input mask / shape] [number of runs]
        
        [tools]                 expects a chain of numbers, seperated by a hyphen; 
                                e.g. 1-2-3 for selecting oft-stat, pktools and GRASS
                               
        [input raster]          the raster file for input
        
        [input mask / shape]    the mask shape; expects a vector file which will be
                                automatically rasterized if the selected toos require it
                               
        [number of runs]        the number of runs / repetitions per tool, e.g. "5" means
                                every tool will run 5 times and the average of the runs will
                                be calculated
        
        All arguments are mandatory.
        
        The following tools are available:
        
        1. oft-stat
        2. pktools
        3. GRASS
        4. SAGA

4) example: python zonalStatBenchmark.py 1-2-3-4 test_data/wc2.0_10m_tavg_07.tif test_data/mask.shp 1 5) output:

ID       Tool              seconds (avg)   CPU_load (avg)  No. of runs    
1        Open Foris Tools  0.09            95              1              
2        pktools           0.64            98              1              
3        GRASS             0.81            90              1              
4        SAGA              0.38            95              1  

Feel free to contribute or get in touch.