Python script for comparing "zonal statistics" implementations/algorithms
Thomas Kandler af258e600e Update 5 years ago
LICENSE Initial commit 5 years ago Update 5 years ago New tools 5 years ago New tools 5 years ago Initial commit. 5 years ago New tools 5 years ago New tools 5 years ago


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


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
sudo chmod u+x
sudo ./

-- grass 
sudo apt-get install grass

-- saga
sudo apt-get install saga

3) run the help or read here:

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