Skip to main content

Modelling and forecasting deforestation in the tropics

Project description

Logo forestatrisk

forestatrisk Python package

Python version PyPI version GitHub Actions License GPLv3 Zenodo

Overview

The forestatrisk Python package can be used to model and forecast deforestation 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

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 virtualenv or conda.

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

Using conda

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 python gdal numpy matplotlib pandas patsy pip statsmodels --yes
conda activate conda-far
conda install -c conda-forge earthengine-api --yes
pip install pywdpa sklearn # 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

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

forestatrisk-0.2.tar.gz (71.0 kB view hashes)

Uploaded Source

Built Distributions

forestatrisk-0.2-cp39-cp39-win_amd64.whl (130.0 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

forestatrisk-0.2-cp39-cp39-win32.whl (127.8 kB view hashes)

Uploaded CPython 3.9 Windows x86

forestatrisk-0.2-cp39-cp39-manylinux2010_x86_64.whl (172.2 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.12+ x86-64

forestatrisk-0.2-cp39-cp39-manylinux2010_i686.whl (166.0 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.12+ i686

forestatrisk-0.2-cp39-cp39-manylinux1_x86_64.whl (172.2 kB view hashes)

Uploaded CPython 3.9

forestatrisk-0.2-cp39-cp39-manylinux1_i686.whl (166.0 kB view hashes)

Uploaded CPython 3.9

forestatrisk-0.2-cp39-cp39-macosx_10_9_x86_64.whl (128.4 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

forestatrisk-0.2-cp38-cp38-win_amd64.whl (130.0 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

forestatrisk-0.2-cp38-cp38-win32.whl (127.8 kB view hashes)

Uploaded CPython 3.8 Windows x86

forestatrisk-0.2-cp38-cp38-manylinux2010_x86_64.whl (173.7 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

forestatrisk-0.2-cp38-cp38-manylinux2010_i686.whl (167.4 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.12+ i686

forestatrisk-0.2-cp38-cp38-manylinux1_x86_64.whl (173.7 kB view hashes)

Uploaded CPython 3.8

forestatrisk-0.2-cp38-cp38-manylinux1_i686.whl (167.4 kB view hashes)

Uploaded CPython 3.8

forestatrisk-0.2-cp38-cp38-macosx_10_9_x86_64.whl (128.4 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

forestatrisk-0.2-cp37-cp37m-win_amd64.whl (129.9 kB view hashes)

Uploaded CPython 3.7m Windows x86-64

forestatrisk-0.2-cp37-cp37m-win32.whl (127.8 kB view hashes)

Uploaded CPython 3.7m Windows x86

forestatrisk-0.2-cp37-cp37m-manylinux2010_x86_64.whl (171.9 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.12+ x86-64

forestatrisk-0.2-cp37-cp37m-manylinux2010_i686.whl (165.1 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.12+ i686

forestatrisk-0.2-cp37-cp37m-manylinux1_x86_64.whl (171.9 kB view hashes)

Uploaded CPython 3.7m

forestatrisk-0.2-cp37-cp37m-manylinux1_i686.whl (165.1 kB view hashes)

Uploaded CPython 3.7m

forestatrisk-0.2-cp37-cp37m-macosx_10_9_x86_64.whl (128.4 kB view hashes)

Uploaded CPython 3.7m macOS 10.9+ x86-64

forestatrisk-0.2-cp36-cp36m-win_amd64.whl (129.9 kB view hashes)

Uploaded CPython 3.6m Windows x86-64

forestatrisk-0.2-cp36-cp36m-win32.whl (127.8 kB view hashes)

Uploaded CPython 3.6m Windows x86

forestatrisk-0.2-cp36-cp36m-manylinux2010_x86_64.whl (171.0 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.12+ x86-64

forestatrisk-0.2-cp36-cp36m-manylinux2010_i686.whl (164.2 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.12+ i686

forestatrisk-0.2-cp36-cp36m-manylinux1_x86_64.whl (171.0 kB view hashes)

Uploaded CPython 3.6m

forestatrisk-0.2-cp36-cp36m-manylinux1_i686.whl (164.2 kB view hashes)

Uploaded CPython 3.6m

forestatrisk-0.2-cp36-cp36m-macosx_10_9_x86_64.whl (128.4 kB view hashes)

Uploaded CPython 3.6m macOS 10.9+ x86-64

forestatrisk-0.2-cp35-cp35m-win_amd64.whl (129.9 kB view hashes)

Uploaded CPython 3.5m Windows x86-64

forestatrisk-0.2-cp35-cp35m-win32.whl (127.8 kB view hashes)

Uploaded CPython 3.5m Windows x86

forestatrisk-0.2-cp35-cp35m-manylinux2010_x86_64.whl (170.7 kB view hashes)

Uploaded CPython 3.5m manylinux: glibc 2.12+ x86-64

forestatrisk-0.2-cp35-cp35m-manylinux2010_i686.whl (163.9 kB view hashes)

Uploaded CPython 3.5m manylinux: glibc 2.12+ i686

forestatrisk-0.2-cp35-cp35m-manylinux1_x86_64.whl (170.7 kB view hashes)

Uploaded CPython 3.5m

forestatrisk-0.2-cp35-cp35m-manylinux1_i686.whl (163.9 kB view hashes)

Uploaded CPython 3.5m

forestatrisk-0.2-cp35-cp35m-macosx_10_9_x86_64.whl (127.4 kB view hashes)

Uploaded CPython 3.5m macOS 10.9+ x86-64

forestatrisk-0.2-cp27-cp27mu-manylinux2010_x86_64.whl (167.5 kB view hashes)

Uploaded CPython 2.7mu manylinux: glibc 2.12+ x86-64

forestatrisk-0.2-cp27-cp27mu-manylinux2010_i686.whl (161.4 kB view hashes)

Uploaded CPython 2.7mu manylinux: glibc 2.12+ i686

forestatrisk-0.2-cp27-cp27mu-manylinux1_x86_64.whl (167.5 kB view hashes)

Uploaded CPython 2.7mu

forestatrisk-0.2-cp27-cp27mu-manylinux1_i686.whl (161.4 kB view hashes)

Uploaded CPython 2.7mu

forestatrisk-0.2-cp27-cp27m-manylinux2010_x86_64.whl (167.5 kB view hashes)

Uploaded CPython 2.7m manylinux: glibc 2.12+ x86-64

forestatrisk-0.2-cp27-cp27m-manylinux2010_i686.whl (161.4 kB view hashes)

Uploaded CPython 2.7m manylinux: glibc 2.12+ i686

forestatrisk-0.2-cp27-cp27m-manylinux1_x86_64.whl (167.5 kB view hashes)

Uploaded CPython 2.7m

forestatrisk-0.2-cp27-cp27m-manylinux1_i686.whl (161.4 kB view hashes)

Uploaded CPython 2.7m

forestatrisk-0.2-cp27-cp27m-macosx_10_9_x86_64.whl (127.2 kB view hashes)

Uploaded CPython 2.7m macOS 10.9+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page