Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

📦🐍 Python package to model and forecast the risk of deforestation

License

NotificationsYou must be signed in to change notification settings

ghislainv/forestatrisk

Repository files navigation

Logo forestatrisk

forestatrisk Python package

Python versionPyPI versionGitHub ActionsLicense GPLv3ZenodoJOSS

Overview

Theforestatrisk Python package can be used tomodel thetropical deforestation spatially,predict the spatial risk ofdeforestation, andforecast the future forest cover in thetropics. It provides functions to estimate the spatial probability ofdeforestation 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 previousdeforestation), or land conservation status (eg. protected area) forexample.

banner_forestatrisk

Scientific publication

Vieilledent G. 2021.forestatrisk: a Python package formodelling 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 mainfactors determining the spatial risk of deforestation and quantifyingtheir relative effects. Forecasting forest cover change is paramountas it allows anticipating the consequences of deforestation (in termsof carbon emissions or biodiversity loss) under various technological,political and socio-economic scenarios, and informs decision makersaccordingly. Because both biodiversity and carbon vary greatly inspace, it is necessary to provide spatial forecasts of forest coverchange to properly quantify biodiversity loss and carbon emissionsassociated with future deforestation.

Theforestatrisk Python package can be used to model the tropicaldeforestation spatially, predict the spatial risk of deforestation,and forecast the future forest cover in the tropics. The spatial dataused to model deforestation come from georeferenced raster files,which can be very large (several gigabytes). The functions availablein theforestatrisk package process large rasters by blocks ofdata, making calculations fast and efficient. This allowsdeforestation to be modeled over large geographic areas (e.g. at thescale of a country) and at high spatial resolution(eg. ≤ 30 m). Theforestatrisk package offers the possibilityof using logistic regression with auto-correlated spatial randomeffects to model the deforestation process. The spatial random effectsmake possible to structure the residual spatial variability of thedeforestation process, not explained by the variables of the model andoften very large. In addition to these new features, theforestatrisk Python package is open source (GPLv3 license),cross-platform, scriptable (via Python), user-friendly (functionsprovided with full documentation and examples), and easily extendable(with additional statistical models for example). TheforestatriskPython package has been used to model deforestation and predict futureforest cover by 2100 across the humid tropics(https://forestatrisk.cirad.fr).

Installation

You will need several dependencies to run theforestatrisk Pythonpackage. The best way to install the package is to create a Pythonvirtual environment, either throughconda (recommended) orvirtualenv.

Usingvirtualenv

The easiest way to install theforestatrisk Python package is viapip in theOSGeo4W Shell for Windows or in a virtual environment for Linux.

For Linux, create and activate a virtual environment before installinggeefcc withpip:

cd~# Create a directory for virtual environmentsmkdir venvs# Create the virtual environment with venvpython3 -m venv~/venvs/venv-geefcc# Activate (start) the virtual environmentsource~/venvs/venv-geefcc/bin/activate

Install Python dependencies andforestatrisk in theOSGeo4W Shell or in the newly created virtual environment:

# Upgrade pip, setuptools, and wheelpython3 -m pip install --upgrade pip setuptools wheel# Install numpypython3 -m numpy# Install gdal Python bindings (the correct version)python3 -m pip install gdal==$(gdal-config --version)# Install forestatrisk. This will install all other dependenciespython3 -m pip install forestatrisk

If you want to install the development version offorestatrisk, replace the last line with:

python3 -m pip install https://github.com/ghislainv/forestatrisk/archive/master.zip

To deactivate and delete the virtual environment:

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

Usingconda

You first need to haveminiconda3 installed (seehere).

Then, create a conda environment (detailshere)and install theforestatrisk package with the following commands:

conda create --name conda-far -c conda-forge python gdal numpy matplotlib pandas patsy pip statsmodels earthengine-api --yesconda activate conda-farpip install pywdpa scikit-learn# Packages not available with condapip 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 deactivateconda env remove --name conda-far

Installation testing

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

forestatrisk

This should return a short description of theforestatrisk packageand 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 theGetstartedtutorial.

Main functionalities

Sample

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

Model

Function.model_binomial_iCAR() can be used to fit thedeforestation model. A linear Binomial logistic regression model isused in this case. The model includes an intrinsic ConditionalAutoregressive (iCAR) process to account for the spatialautocorrelation of the observations. Parameter inference is done in ahierarchical Bayesian framework. The function calls a Gibbs samplerwith a Metropolis algorithm written in pure C code to reducecomputation time.

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

Predict and project

Function.predict() allows predicting the deforestationprobability on the whole study area using the deforestation modelfitted with.model_*() functions. The prediction is done by blockto allow the computation on large study areas (e.g. country orcontinental scale) with a high spatial resolution (e.g. 30m).

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

Validate

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

Contributing

Theforestatrisk Python package is Open Source and released undertheGNU GPL version 3 license. Anybodywho is interested can contribute to the package development followingourCommunity guidelines. Everycontributor must agree to follow the project'sCode of conduct.


[8]ページ先頭

©2009-2025 Movatter.jp