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

banner_forestatrisk

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


Download files

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

Source Distribution

forestatrisk-1.3.2.tar.gz (127.3 kB view details)

Uploaded Source

Built Distributions

forestatrisk-1.3.2-cp313-cp313-win_amd64.whl (158.8 kB view details)

Uploaded CPython 3.13Windows x86-64

forestatrisk-1.3.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (199.9 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

forestatrisk-1.3.2-cp313-cp313-macosx_11_0_arm64.whl (156.4 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

forestatrisk-1.3.2-cp313-cp313-macosx_10_13_x86_64.whl (158.9 kB view details)

Uploaded CPython 3.13macOS 10.13+ x86-64

forestatrisk-1.3.2-cp312-cp312-win_amd64.whl (158.8 kB view details)

Uploaded CPython 3.12Windows x86-64

forestatrisk-1.3.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (199.9 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

forestatrisk-1.3.2-cp312-cp312-macosx_11_0_arm64.whl (156.4 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

forestatrisk-1.3.2-cp312-cp312-macosx_10_13_x86_64.whl (158.9 kB view details)

Uploaded CPython 3.12macOS 10.13+ x86-64

forestatrisk-1.3.2-cp311-cp311-win_amd64.whl (158.8 kB view details)

Uploaded CPython 3.11Windows x86-64

forestatrisk-1.3.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (199.1 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

forestatrisk-1.3.2-cp311-cp311-macosx_11_0_arm64.whl (156.3 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

forestatrisk-1.3.2-cp311-cp311-macosx_10_9_x86_64.whl (158.8 kB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

forestatrisk-1.3.2-cp310-cp310-win_amd64.whl (158.8 kB view details)

Uploaded CPython 3.10Windows x86-64

forestatrisk-1.3.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (198.4 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

forestatrisk-1.3.2-cp310-cp310-macosx_11_0_arm64.whl (156.3 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

forestatrisk-1.3.2-cp310-cp310-macosx_10_9_x86_64.whl (158.8 kB view details)

Uploaded CPython 3.10macOS 10.9+ x86-64

File details

Details for the file forestatrisk-1.3.2.tar.gz.

File metadata

  • Download URL: forestatrisk-1.3.2.tar.gz
  • Upload date:
  • Size: 127.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for forestatrisk-1.3.2.tar.gz
Algorithm Hash digest
SHA256 9f8fa025d2aa388279d1f8a2a3c21227d8d24eaabc588ab13197fb9eadce90a0
MD5 996d92c5ab83c1f3fa61dd2aa1209cac
BLAKE2b-256 8f6b245c2d561f61e476da8b377ec7106ef09e0d9a0227c119b14e63585367ca

See more details on using hashes here.

Provenance

The following attestation bundles were made for forestatrisk-1.3.2.tar.gz:

Publisher: wheel-pypi.yml on ghislainv/forestatrisk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file forestatrisk-1.3.2-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for forestatrisk-1.3.2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 f3d606a0f82cdbe51613e40b75c36c5fd76d22288adb46fe3dd9b4731d2ab4da
MD5 7cfe42f4e90f2800acb41d356bcac424
BLAKE2b-256 563cfcfeae3d7ebe96130cebcbd7f4e8e14bfe60c4b12c26697d228c9a2da450

See more details on using hashes here.

Provenance

The following attestation bundles were made for forestatrisk-1.3.2-cp313-cp313-win_amd64.whl:

Publisher: wheel-pypi.yml on ghislainv/forestatrisk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file forestatrisk-1.3.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for forestatrisk-1.3.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0f72bbbc7595aedbbb1cc25f970efeb6d5b6a860eda3f03dcc55b9d943bb918c
MD5 155aada8f18c643080b3eb12f1d0c68d
BLAKE2b-256 9124b8bb6cee050ffc8dbdfd1b6c1d8385c6e57a51c92ae9546db857591d4b83

See more details on using hashes here.

Provenance

The following attestation bundles were made for forestatrisk-1.3.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: wheel-pypi.yml on ghislainv/forestatrisk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file forestatrisk-1.3.2-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for forestatrisk-1.3.2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 550d58820bd94dc0b3edd7f53bc2a2dd59cbb9de441ff85fa9d2b00623cf7ffc
MD5 792f2d223f89b663a3fadab1bde5b761
BLAKE2b-256 2b8ff9a60f819353285a132873106bfc3350b467595daa9c51a07556d25075dc

See more details on using hashes here.

Provenance

The following attestation bundles were made for forestatrisk-1.3.2-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: wheel-pypi.yml on ghislainv/forestatrisk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file forestatrisk-1.3.2-cp313-cp313-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for forestatrisk-1.3.2-cp313-cp313-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 90941d49eb775768c903bf8434bdd0933bcb1dba0acf5b454652233a6019b383
MD5 7cb136da5350a63bd9065b4cbc459a7e
BLAKE2b-256 6acc538ebcfbb0925905caf647dc561e6c9dd9116e0d6fb9d1b28a389304c9bc

See more details on using hashes here.

Provenance

The following attestation bundles were made for forestatrisk-1.3.2-cp313-cp313-macosx_10_13_x86_64.whl:

Publisher: wheel-pypi.yml on ghislainv/forestatrisk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file forestatrisk-1.3.2-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for forestatrisk-1.3.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 67136c0356dc13d08568383d665dde1b60ba75be1a2344e00d435dd3894970a0
MD5 b9ebe4785f660724b0c360e16c4c9e32
BLAKE2b-256 3711d5648ba6a6897a2d3445de9404e758d9c57cc4f696025e95e692d4bf8691

See more details on using hashes here.

Provenance

The following attestation bundles were made for forestatrisk-1.3.2-cp312-cp312-win_amd64.whl:

Publisher: wheel-pypi.yml on ghislainv/forestatrisk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file forestatrisk-1.3.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for forestatrisk-1.3.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 caf44a0b4fe47759280f0972362e5f011e108ea306a1a647a4c6e980518ff49b
MD5 2340ce8b2bc8a004a720f2f361330eb9
BLAKE2b-256 8cf28416e02c40f402f703c4df20e41fed3fec57a737736323312d9a3d3d2a3a

See more details on using hashes here.

Provenance

The following attestation bundles were made for forestatrisk-1.3.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: wheel-pypi.yml on ghislainv/forestatrisk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file forestatrisk-1.3.2-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for forestatrisk-1.3.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 eabf4ef9289139efad61b910d39e1906445e9b3f963ee3f8056cfe3182dd60ad
MD5 64be40cccb4645504ffdac95c6d4a349
BLAKE2b-256 f9536fcaaec2209ff646baa0650f8611537869fcabdbda9a5b5b4e2ecdf8dbb8

See more details on using hashes here.

Provenance

The following attestation bundles were made for forestatrisk-1.3.2-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: wheel-pypi.yml on ghislainv/forestatrisk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file forestatrisk-1.3.2-cp312-cp312-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for forestatrisk-1.3.2-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 b338b7626d0509f9735cce1769ff7e6ce3ddf380205aa9ca35cfb2d90859db8b
MD5 a39d18c2bb6499ad962a167f90f7671e
BLAKE2b-256 b634e4c64dd2c5e730b6832b84272db55f7c1eea200d34fd390cf3fe00950403

See more details on using hashes here.

Provenance

The following attestation bundles were made for forestatrisk-1.3.2-cp312-cp312-macosx_10_13_x86_64.whl:

Publisher: wheel-pypi.yml on ghislainv/forestatrisk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file forestatrisk-1.3.2-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for forestatrisk-1.3.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 30925779236812ef2bbc89c0c9c49af0822250cfcd1fcf9cbb4eb593bea84ff2
MD5 77beb76b2a5018fef5654af2226f7225
BLAKE2b-256 59acfc12720f06efbc10355dff429e62fe8b8c34b00c06cd90699943f47873e6

See more details on using hashes here.

Provenance

The following attestation bundles were made for forestatrisk-1.3.2-cp311-cp311-win_amd64.whl:

Publisher: wheel-pypi.yml on ghislainv/forestatrisk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file forestatrisk-1.3.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for forestatrisk-1.3.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7171d1cfd5be5661d4c49fa588c0c5e0b8027fc67878c3446034f0c84ff30095
MD5 5949a647ecd7a0e6ad47498d3917ddd6
BLAKE2b-256 07838d0e9987ba6279d59b88f014a4f82236374f7bdadcdde6f4d512b3a254f5

See more details on using hashes here.

Provenance

The following attestation bundles were made for forestatrisk-1.3.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: wheel-pypi.yml on ghislainv/forestatrisk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file forestatrisk-1.3.2-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for forestatrisk-1.3.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 575b1e80129bf7a00274d60aced3873ce8a2ce1b92010e54904f18c1ed7e6e5d
MD5 c8146423a825214dc682aad7cd8baff6
BLAKE2b-256 a1070b326dad63bd675f4319448c06dc5d6a7916ba29f43f17c3b30a89f84539

See more details on using hashes here.

Provenance

The following attestation bundles were made for forestatrisk-1.3.2-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: wheel-pypi.yml on ghislainv/forestatrisk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file forestatrisk-1.3.2-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for forestatrisk-1.3.2-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 dd39a67a899240a87ef91a3c728879d4adfef9a0b58a3bc8fd88f7158f3fde86
MD5 774dfe7894dbfd1a6c67a19a8ba0174c
BLAKE2b-256 68cabbc105e330d1595322deccc6ccf0bb5be9639d1adcb76083ec3c282a5be2

See more details on using hashes here.

Provenance

The following attestation bundles were made for forestatrisk-1.3.2-cp311-cp311-macosx_10_9_x86_64.whl:

Publisher: wheel-pypi.yml on ghislainv/forestatrisk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file forestatrisk-1.3.2-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for forestatrisk-1.3.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 f3101c26041df79fd32f94ddfeb9225ca2a089069ae18d4196c155fddc407a7c
MD5 7cf3dc33810ca5b813e84b0b616ba4b3
BLAKE2b-256 f2c634d479f78e7e543ff579ff1339795a4c6b9cbda214fc02f33cd8c54b985a

See more details on using hashes here.

Provenance

The following attestation bundles were made for forestatrisk-1.3.2-cp310-cp310-win_amd64.whl:

Publisher: wheel-pypi.yml on ghislainv/forestatrisk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file forestatrisk-1.3.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for forestatrisk-1.3.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 534fe41d280f465ccc2e5ee49fe48a1f8458fabda5605d739ce4e308488c4d30
MD5 545f52f25c1c600df73a9c4b9e5167d3
BLAKE2b-256 eb46552ecf87a4f51c02c2763d69a420ee8ad781a6ca29d64906eff0b6b982e3

See more details on using hashes here.

Provenance

The following attestation bundles were made for forestatrisk-1.3.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: wheel-pypi.yml on ghislainv/forestatrisk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file forestatrisk-1.3.2-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for forestatrisk-1.3.2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1dbc64c0ab8942c977dcc7715dc47fd8b39578c2f356a02be59d80d474d63d25
MD5 4e77c928e86f36768c028de751dec2a9
BLAKE2b-256 3e6e360e2c825471ec12c8b920051da14ca2f45ac83c7765fde8ec6ebc9e261f

See more details on using hashes here.

Provenance

The following attestation bundles were made for forestatrisk-1.3.2-cp310-cp310-macosx_11_0_arm64.whl:

Publisher: wheel-pypi.yml on ghislainv/forestatrisk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file forestatrisk-1.3.2-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for forestatrisk-1.3.2-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 d7f4fe30d12eb53c9f0d17cd562aa4b6d0fc8103eba8e0ffbcbd93946a7dc884
MD5 a852148dd6f999050103cce16bff86b4
BLAKE2b-256 e73f5dc04091714e4b58411de6ae9fb5b7db676504d150eb15dbd5c3be159f09

See more details on using hashes here.

Provenance

The following attestation bundles were made for forestatrisk-1.3.2-cp310-cp310-macosx_10_9_x86_64.whl:

Publisher: wheel-pypi.yml on ghislainv/forestatrisk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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