Performance analysis over Python and R for raster algebra - a case of NDVI calculation

We believe that tasks / studies that involve the massive analysis of vector and raster spatial data would become more popular in the near future. With massive analysis some factors became more relevant such as the computer memory, processor type, operating system and the programming language or platform used for the calculation.

We make a case study of raster analysis in Windows where the Python and R were installed with their spatial packages from conda repositories. Our computer skills don't allow us to have a sense of the differences in the performance of these scripts in Linux.

We have separated the performance on two parts:

  1. The raster algebra of the NDVI = (NIR - RED) / (NIR+RED)

  2. The whole script that imports the bands, performs the algebra and saves a geospatial raster.

Performance on raster algebra

The raster algebra among the two Landsat bands took 0.28 seg on R while on Python it took 0.1 seg. From those times the Python script is almost 3 times faster than R on that part of the calculation.

Pyhon

R

Whole script

Both scripts were launched on an Anaconda terminal with different conda environments for Python and R. The purpose of this comparison was to measure the time the whole raster processing that includes the raster upload, the NDVI calculation as a function and the save of a geospatial raster. The R code has some warnings that could come with some incompatibilites from the Conda recipe.

Python script takes 1.5 seg while the R package takes 3.34 seg. Python is around 2.2x faster than R for this study case.

Python

R

Finally, we just want to mention that this is just a simple performance analysis of both programming languages. Criteria for the selection and use of a geospatial programming languaje should be evaluated on more complete evaluation.

2 Comments

Saul Montoya

Saul Montoya es Ingeniero Civil graduado de la Pontificia Universidad Católica del Perú en Lima con estudios de postgrado en Manejo e Ingeniería de Recursos Hídricos (Programa WAREM) de la Universidad de Stuttgart con mención en Ingeniería de Aguas Subterráneas y Hidroinformática.

 

Suscribe to our online newsletter

Subscribe for free newsletter, receive news, interesting facts and dates of our courses in water resources.