Modelling and forecasting deforestation in the tropics
Project description
forestatrisk Python package
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.
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].
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 virtualenv
The easiest way to install the forestatrisk Python package is via pip in the OSGeo4W Shell for Windows or in a virtual environment for Linux.
For Linux, create and activate a virtual environment before installing geefcc with pip:
cd ~
# Create a directory for virtual environments
mkdir venvs
# Create the virtual environment with venv
python3 -m venv ~/venvs/venv-geefcc
# Activate (start) the virtual environment
source ~/venvs/venv-geefcc/bin/activate
Install Python dependencies and forestatrisk in the OSGeo4W Shell or in the newly created virtual environment:
# Upgrade pip, setuptools, and wheel
python3 -m pip install --upgrade pip setuptools wheel
# Install numpy
python3 -m numpy
# Install gdal Python bindings (the correct version)
python3 -m pip install gdal==$(gdal-config --version)
# Install forestatrisk. This will install all other dependencies
python3 -m pip install forestatrisk
If you want to install the development version of forestatrisk, replace the last line with:
python3 -m pip install https://github.com/ghislainv/forestatrisk/archive/master.zip
To deactivate and delete the virtual environment:
deactivate
rm -R ~/venvs/venv-forestatrisk # Just remove the repository
In case of problem while installing GDAL Python bindings, try the following command:
python3 -m pip install --no-cache-dir --force-reinstall gdal==$(gdal-config --version)
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 -c conda-forge python 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 --yes # Additional libraries if needed
To deactivate and delete the conda environment:
conda deactivate
conda env remove --name conda-far
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 following 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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file forestatrisk-1.2.5.tar.gz
.
File metadata
- Download URL: forestatrisk-1.2.5.tar.gz
- Upload date:
- Size: 123.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 79c4ab6465c9d80fc66a003f0805a762b334bd1a66fd9127aa6b8b3a9ccae913 |
|
MD5 | 561bfb33698689cd6fb88c49cb86ff33 |
|
BLAKE2b-256 | bf60dd7327ba9a7827ecad56a2c7694434e2dc89c20831ddf16a0889fad36818 |
File details
Details for the file forestatrisk-1.2.5-cp312-cp312-win_amd64.whl
.
File metadata
- Download URL: forestatrisk-1.2.5-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 154.9 kB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac6495775a50709fef05b1b9134a8c5d64a83d176649fbf000e52bfbc6eb52f3 |
|
MD5 | ee3a9fe18697b8e26e9d0aedf10093b5 |
|
BLAKE2b-256 | a2ff9692781a8b38915d1d88ad437edcfd1dcf7379dfcd11a56bbaa740c6ed8f |
File details
Details for the file forestatrisk-1.2.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: forestatrisk-1.2.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 196.1 kB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c75c041607d646903473488a5dd8d11c508101ce9f9ba03d4e7e4b180caaebff |
|
MD5 | 02780120a9906fdb1cedb3897ee0ece3 |
|
BLAKE2b-256 | dc7c7e8dcb050f1af8bc8e4235220211f1e601383b10b9d558d1b2d57e065595 |
File details
Details for the file forestatrisk-1.2.5-cp312-cp312-macosx_11_0_arm64.whl
.
File metadata
- Download URL: forestatrisk-1.2.5-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 152.5 kB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b470c2b704135dbeafa9fb4d2f3674f0b50e8e911941d1dc6db1a7b20c830e3 |
|
MD5 | 2713dcb0d986039b1470467d0a755284 |
|
BLAKE2b-256 | 9e47b4764b12f6fedbf57909bc66acd3b8f1e6ef2ae214aeb391f1776eefa8d6 |
File details
Details for the file forestatrisk-1.2.5-cp312-cp312-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: forestatrisk-1.2.5-cp312-cp312-macosx_10_9_x86_64.whl
- Upload date:
- Size: 157.1 kB
- Tags: CPython 3.12, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 59effc6ce9395527d778b94920751b797af56b40fdf6c8a7c65e36f8f7117fba |
|
MD5 | 9c797f15773f1381dda75302a26e2e68 |
|
BLAKE2b-256 | 2732cb9f0a06d273fe8065eb7dc9ddeb6cd27ceec79f6813680b8a86d4fbaebd |
File details
Details for the file forestatrisk-1.2.5-cp311-cp311-win_amd64.whl
.
File metadata
- Download URL: forestatrisk-1.2.5-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 154.8 kB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2a5f01dba2f6618e3cf7e66d5bca4df3cc473f63d9507b338a23f01e935bf243 |
|
MD5 | 208614b091931fb801d1b2d80101a39b |
|
BLAKE2b-256 | 2f71374813c3ca02b5717e291e6455f3ad47b84643fbac39fec4526581b8f8b3 |
File details
Details for the file forestatrisk-1.2.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: forestatrisk-1.2.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 195.2 kB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6412e1a94687758a693371593920c2caefe02c519300918e6b9d277e427b99d0 |
|
MD5 | 8d17d6b4cd83b51517cc0dbc5e01b928 |
|
BLAKE2b-256 | 910e9fc2b560aab6e7f4298b45f1ad201b07a9f8772b8255cd567e430466eece |
File details
Details for the file forestatrisk-1.2.5-cp311-cp311-macosx_11_0_arm64.whl
.
File metadata
- Download URL: forestatrisk-1.2.5-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 152.4 kB
- Tags: CPython 3.11, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e6c289b27fc33239dafbcf01fd9ef4c8e516ab82ffe6ed3edb3ecd089ba5b635 |
|
MD5 | e376e302169ae7e2db56f582d9e366dd |
|
BLAKE2b-256 | b127d261aaaac19f7fc9734fd9ef523e18b730fe442ee6984fcc1b718377f0f7 |
File details
Details for the file forestatrisk-1.2.5-cp311-cp311-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: forestatrisk-1.2.5-cp311-cp311-macosx_10_9_x86_64.whl
- Upload date:
- Size: 157.1 kB
- Tags: CPython 3.11, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 259457b621a6786451adfd45f2e9c94e69be8553627e20015e0954cd4487427d |
|
MD5 | 1192b03d72cd5f46dda6d65cd898bd25 |
|
BLAKE2b-256 | 0bbf3b38cc13dfcd18dcc2d0eec52a155a8082f4b8b999505f0f4e428c680a42 |
File details
Details for the file forestatrisk-1.2.5-cp310-cp310-win_amd64.whl
.
File metadata
- Download URL: forestatrisk-1.2.5-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 154.8 kB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 56f733a21e65df6b3c2cf1ee46970c5f7b7fe59948b4e3501f39e1205c0b70f5 |
|
MD5 | d8e8e799520084f034eedc879bdce0e6 |
|
BLAKE2b-256 | d9ddc9d3f8bfdf78c6df6e3c35c5c440d3432a6ae142527516874172b43dc716 |
File details
Details for the file forestatrisk-1.2.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: forestatrisk-1.2.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 194.6 kB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 85394fd8deb281b3ed237471cd2d025f6057db721cfcca3a67173c3dbe6ca2dc |
|
MD5 | 8cdc444903f49a3b259e2b1be2fbd993 |
|
BLAKE2b-256 | 97afa52e0f910a15ed24aa9562f8cf4ab45a95cef3a98ce39474456c1f0a80b6 |
File details
Details for the file forestatrisk-1.2.5-cp310-cp310-macosx_11_0_arm64.whl
.
File metadata
- Download URL: forestatrisk-1.2.5-cp310-cp310-macosx_11_0_arm64.whl
- Upload date:
- Size: 152.4 kB
- Tags: CPython 3.10, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7fe789f611c2febb2c8add768df382c4d4fb94a67e101f99864e8aabd97f7e61 |
|
MD5 | 7e0793da86ebfd63e6e9b83a98a467a1 |
|
BLAKE2b-256 | 7c34f3dc0ecc70d9f2fdf85a15ccd5ffea4016aafe841ea78c0120b3f1ca029c |
File details
Details for the file forestatrisk-1.2.5-cp310-cp310-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: forestatrisk-1.2.5-cp310-cp310-macosx_10_9_x86_64.whl
- Upload date:
- Size: 157.1 kB
- Tags: CPython 3.10, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f2c020d63f6f541e9e5faa1fc2cf00c16ad26bb2ff3facc2ffc79ebf95cee41 |
|
MD5 | 7b620d07250f5da8f192af03c8813f21 |
|
BLAKE2b-256 | 91c2d356fa212724866d378739241fefbe3fc1b5003f7da7b5165a6f568978d4 |
File details
Details for the file forestatrisk-1.2.5-cp39-cp39-win_amd64.whl
.
File metadata
- Download URL: forestatrisk-1.2.5-cp39-cp39-win_amd64.whl
- Upload date:
- Size: 154.8 kB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0ffd505b1b6738b902bffe9616be7ffef17a9face65e89b8577ed5b5cfaca11b |
|
MD5 | 64e894dc8163f2c9b3955f6b66228be2 |
|
BLAKE2b-256 | 7ec181b155613f49f42b30a9084a4b84dcf945cf3c7e7a83501a204ab3999147 |
File details
Details for the file forestatrisk-1.2.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: forestatrisk-1.2.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 194.5 kB
- Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 52f4f99beabcdd6e194be24a156df54e832d7a1d2f52435e28807a1028fb4cbd |
|
MD5 | 1747e121db5808821b4fa46b9aae2a3b |
|
BLAKE2b-256 | ec5a7b0627a0c29962e2a6f44ea59386fa3f97acf9cc80e282a9ce7b1932748e |
File details
Details for the file forestatrisk-1.2.5-cp39-cp39-macosx_11_0_arm64.whl
.
File metadata
- Download URL: forestatrisk-1.2.5-cp39-cp39-macosx_11_0_arm64.whl
- Upload date:
- Size: 152.4 kB
- Tags: CPython 3.9, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e59da861abfefb9eaaeafa96b4395b1ba42b71b99e370e6c1a6dc0e26d2dd9cb |
|
MD5 | 5cc406793d7e8df6dc9d4384cd696476 |
|
BLAKE2b-256 | a7d55d4b72d2c3f1e5d835e49c389316e7fa162f8bbf95c325760960125d0b6b |
File details
Details for the file forestatrisk-1.2.5-cp39-cp39-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: forestatrisk-1.2.5-cp39-cp39-macosx_10_9_x86_64.whl
- Upload date:
- Size: 157.1 kB
- Tags: CPython 3.9, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8045fedefe1595b0ed08678caa78bba1e0ccbbb93f1df239759f0aeac296a39e |
|
MD5 | 0b7e20ee14d2276469a1b230d547e61d |
|
BLAKE2b-256 | b4e0ffe6b56439b840641692e3d001a4c4cd9d197f92fdd4b50a1bd7eb15cb1c |