• Stars
    star
    117
  • Rank 301,828 (Top 6 %)
  • Language
    Python
  • License
    GNU General Publi...
  • Created about 8 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

πŸ“¦πŸ Python package to model and forecast the risk of deforestation
Logo forestatrisk

forestatrisk Python package

Python version PyPI version GitHub Actions License GPLv3 Zenodo JOSS

Overview

The forestatrisk Python package can be used to model the tropical deforestation spatially, predict the spatial risk of deforestation, and forecast the future forest cover in the tropics. It provides functions to estimate the spatial probability of deforestation as a function of various spatial explanatory variables.

Spatial explanatory variables can be derived from topography (altitude, slope, and aspect), accessibility (distance to roads, towns, and forest edge), deforestation history (distance to previous deforestation), or land conservation status (eg. protected area) for example.

prob_AFR

Scientific publication

Vieilledent G. 2021. forestatrisk: a Python package for modelling and forecasting deforestation in the tropics. Journal of Open Source Software. 6(59): 2975. [doi: 10.21105/joss.02975]. pdf

Statement of Need

Spatial modelling of the deforestation allows identifying the main factors determining the spatial risk of deforestation and quantifying their relative effects. Forecasting forest cover change is paramount as it allows anticipating the consequences of deforestation (in terms of carbon emissions or biodiversity loss) under various technological, political and socio-economic scenarios, and informs decision makers accordingly. Because both biodiversity and carbon vary greatly in space, it is necessary to provide spatial forecasts of forest cover change to properly quantify biodiversity loss and carbon emissions associated with future deforestation.

The forestatrisk Python package can be used to model the tropical deforestation spatially, predict the spatial risk of deforestation, and forecast the future forest cover in the tropics. The spatial data used to model deforestation come from georeferenced raster files, which can be very large (several gigabytes). The functions available in the forestatrisk package process large rasters by blocks of data, making calculations fast and efficient. This allows deforestation to be modeled over large geographic areas (e.g. at the scale of a country) and at high spatial resolution (eg. ≀ 30Β m). The forestatrisk package offers the possibility of using logistic regression with auto-correlated spatial random effects to model the deforestation process. The spatial random effects make possible to structure the residual spatial variability of the deforestation process, not explained by the variables of the model and often very large. In addition to these new features, the forestatrisk Python package is open source (GPLv3 license), cross-platform, scriptable (via Python), user-friendly (functions provided with full documentation and examples), and easily extendable (with additional statistical models for example). The forestatrisk Python package has been used to model deforestation and predict future forest cover by 2100 across the humid tropics (https://forestatrisk.cirad.fr).

Installation

You will need several dependencies to run the forestatrisk Python package. The best way to install the package is to create a Python virtual environment, either through conda (recommended) or virtualenv.

Using conda (recommended)

You first need to have miniconda3 installed (see here).

Then, create a conda environment (details here) and install the forestatrisk package with the following commands:

conda create --name conda-far -c conda-forge python=3.9 gdal numpy matplotlib pandas patsy pip statsmodels earthengine-api --yes
conda activate conda-far
pip install pywdpa scikit-learn # Packages not available with conda
pip install forestatrisk # For PyPI version
# pip install https://github.com/ghislainv/forestatrisk/archive/master.zip # For GitHub dev version
# conda install -c conda-forge python-dotenv rclone --yes  # Potentially interesting libraries

To deactivate and delete the conda environment:

conda deactivate
conda env remove --name conda-far

Using virtualenv

You first need to have the virtualenv package installed (see here).

Then, create a virtual environment and install the forestatrisk package with the following commands:

cd ~
mkdir venvs # Directory for virtual environments
cd venvs
virtualenv --python=/usr/bin/python3 venv-far
source ~/venvs/venv-far/bin/activate
# Install numpy first
pip install numpy
# Install gdal (the correct version)
pip install --global-option=build_ext --global-option="-I/usr/include/gdal" gdal==$(gdal-config --version)
pip install forestatrisk # For PyPI version, this will install all other dependencies
# pip install https://github.com/ghislainv/forestatrisk/archive/master.zip # For GitHub dev version
pip install statsmodels # Optional additional packages

To deactivate and delete the virtual environment:

deactivate
rm -R ~/venvs/venv-far # Just remove the repository

Installation testing

You can test that the package has been correctly installed using the command forestatrisk in a terminal:

forestatrisk

This should return a short description of the forestatrisk package and the version number:

# forestatrisk: modelling and forecasting deforestation in the tropics.
# https://ecology.ghislainv.fr/forestatrisk/
# forestatrisk version x.x.

You can also test the package executing the commands in the Get started tutorial.

Main functionalities

Sample

Function .sample() sample observations points from a forest cover change map. The sample is balanced and stratified between deforested and non-deforested pixels. The function also retrieves information from explanatory variables for each sampled point. Sampling is done by block to allow computation on large study areas (e.g. country or continental scale) with a high spatial resolution (e.g. 30m).

Model

Function .model_binomial_iCAR() can be used to fit the deforestation model. A linear Binomial logistic regression model is used in this case. The model includes an intrinsic Conditional Autoregressive (iCAR) process to account for the spatial autocorrelation of the observations. Parameter inference is done in a hierarchical Bayesian framework. The function calls a Gibbs sampler with a Metropolis algorithm written in pure C code to reduce computation time.

Other models (such as a simple GLM or a Random Forest model) can also be used.

Predict and project

Function .predict() allows predicting the deforestation probability on the whole study area using the deforestation model fitted with .model_*() functions. The prediction is done by block to allow the computation on large study areas (e.g. country or continental scale) with a high spatial resolution (e.g. 30m).

Function .deforest() predicts the future forest cover map based on a raster of probability of deforestation (rescaled from 1 to 65535), which is obtained from function .predict(), and an area (in hectares) to be deforested.

Validate

A set of functions (eg. .cross_validation() or .map_accuracy()) is also provided to perform model and map validation.

Contributing

The forestatrisk Python package is Open Source and released under the GNU GPL version 3 license. Anybody who is interested can contribute to the package development following our Community guidelines. Every contributor must agree to follow the project's Code of conduct.

More Repositories

1

riskmapjnr

πŸ“¦πŸ Mapping deforestation risk following JNR methodology
Python
24
star
2

forestatrisk-tropics

🌍 πŸ“ Modelling and forecasting deforestation in the tropics
R
23
star
3

jSDM

πŸ“¦ R package for joint species distribution models
C++
11
star
4

hSDM

πŸ“¦ R package for hierarchical Bayesian species distribution models
C
9
star
5

deforestation-maps-Mada

πŸ“ Sixty years of deforestation and forest fragmentation in Madagascar
TeX
8
star
6

workshopReCaREDD

Scenarios of deforestation for tropical countries
Jupyter Notebook
7
star
7

gecevar

πŸ“¦ 🌎 ⛰️ β˜€οΈ ☁️ 🌱 Get climatic and other environmental variables
R
6
star
8

pywdpa

πŸ“¦ 🐍 pywda Python package for simple access to world's protected areas
Python
5
star
9

cv

Ghislain Vieilledent's curriculum vitae
TeX
3
star
10

ghislainv.github.io

Ghislain Vieilledent's website on ecology and applied statistics
R
3
star
11

MCMCpack-parallel

Parallel processes with MCMCpack
R
3
star
12

forestatrisk-tutorial

Tutorial to use the 'forestatrisk' Python package to model and forecast tropical deforestation
HTML
3
star
13

roads-osm

Extract African roads from OpenStreet Map
Python
3
star
14

menabe

Deforestation in central Menabe, western Madagascar
TeX
3
star
15

carbonmap

Bioclimatic envelope models predict a decrease in tropical forest carbon stocks with climate change in Madagascar
R
3
star
16

JSDM-PyMC

Fitting joint species distribution models with PyMC
CSS
2
star
17

twoe

Estimating tree species demography and simulating forest dynamics
C++
2
star
18

accuracy_NBR

Estimate accuracy of delta NBR for forest degradation
R
2
star
19

ExS-interactions

E x S interactions in high dimension explain species coexistence
R
2
star
20

docker-debian-jupyter

Docker with debian 8 and Jupyter notebook
Shell
2
star
21

docker-forestatrisk

Docker file for R, RStudio, reticulate, Python 3 and forestatrisk
Dockerfile
2
star
22

forestatrisk-newcaledonia

Modelling and forecasting deforestation in New-Caledonia
Jupyter Notebook
2
star
23

speciesatlas

HTML
2
star
24

gorillas

🦍 πŸ‡¨πŸ‡© Estimating Grauer's gorilla distribution and population size in eastern Democratic Republic of the Congo
R
2
star
25

chelsafrica

African climate
R
1
star
26

clean-overlay-vectors

R/GRASS scripts to clean and overlay vector data
R
1
star
27

ghislainv

1
star
28

greta_test

Test of the greta R package
R
1
star
29

ghislainv.fr

Personal website
R
1
star
30

wood-density-Cirad

The Cirad wood density database
TeX
1
star
31

forestatrisk-Mada

Spatial modelling and forecasting of deforestation in Madagascar
R
1
star
32

JSDM-PyMC3

Fitting joint species distribution models with PyMC3
Jupyter Notebook
1
star
33

docker-deforestprob

Docker to run the Python deforestprob module
Shell
1
star
34

U-shape-tree-mortality-DBH

Fitting U shape tree mortality model with DBH
R
1
star
35

lifezones

Global bioclimatic scheme for the classification of land areas
1
star
36

useR-2019-tutorials

useR 2019 tutorials
1
star
37

ecoregions-mada

Plot Madagascar ecoregions
R
1
star
38

jrc-lidar-height-growth

R
1
star
39

geoprocessing-python

Various Python scripts for geoprocessing
HTML
1
star
40

docker-forestatrisk-tropics

🐳 Docker for the forestatrisk-tropics project
Dockerfile
1
star
41

coexist

Theoretical high-dimensional model for species coexistence
R
1
star
42

presentations

πŸ“Ί Oral presentations
TeX
1
star
43

Warton2015-TRENDS

Joint species distribution models from Warton et al. 2015 in Trends in Ecology & Evolution
R
1
star
44

Vieilledent2012-Ecological-Applications

R script and data for Vieilledent2012-Ecological-Applications
PostScript
1
star
45

madaclim

Free climate and environmental data for Madagascar
R
1
star
46

forestatrisk-jupyter-notebook

Jupyer notebook for the `forestatrisk` Python package
Jupyter Notebook
1
star
47

forest-cover-percentage

Compute forest cover percentage at low resolution from a high resolution forest cover map
1
star
48

gdal2tiles-leaflet

Tiling big raster files to plot maps with leaflet
Shell
1
star
49

debian-install

Useful files to install GNU Linux Debian
Shell
1
star
50

FRB-reports-BioSceneMada

Reports for the FRB project BioSceneMada
HTML
1
star
51

box-cyclone-fire

Box for tropical cyclone-fire interaction in Madagascar
R
1
star
52

forecasting-deforestation-Mada

HTML
1
star
53

intraco

Reports and presentations for the INTRACO project
TeX
1
star