Open Sustainable Technology

A curated list of open technology projects to sustain a stable climate, energy supply, biodiversity and natural resources.

Browse accepted projects | Review proposed projects | Propose new project | Open Issues

forestatrisk

A Python package to model and forecast the risk of deforestation.
https://github.com/ghislainv/forestatrisk

biodiversity-scenario co2-emissions deforestation deforestation-risk forecasting forest-cover-change ipbes ipcc land-use-change protected-areas python redd roads spatial-analysis spatial-autocorrelation spatial-modelling tropical-forests

Last synced: about 7 hours ago
JSON representation

Repository metadata

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

README

        

..
# ==============================================================================
# author :Ghislain Vieilledent
# email :[email protected], [email protected]
# web :https://ecology.ghislainv.fr
# license :GPLv3
# ==============================================================================

.. image:: https://ecology.ghislainv.fr/forestatrisk/_static/logo-far.svg
:align: right
:target: https://ecology.ghislainv.fr/forestatrisk
:alt: Logo forestatrisk
:width: 140px

``forestatrisk`` Python package
*******************************

|Python version| |PyPI version| |GitHub Actions| |License| |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.

.. image:: https://ecology.ghislainv.fr/forestatrisk/_static/forestatrisk.png
:align: center
:target: https://ecology.ghislainv.fr/forestatrisk
:alt: prob_AFR
:width: 800px

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
(``__).

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:

.. code-block:: shell

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:

.. code-block:: shell

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:

.. code-block:: shell

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:

.. code-block:: shell

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:

.. code-block:: shell

forestatrisk

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

.. code-block:: shell

# 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
`__.

.. |Python version| image:: https://img.shields.io/pypi/pyversions/forestatrisk?logo=python&logoColor=ffd43b&color=306998
:target: https://pypi.org/project/forestatrisk
:alt: Python version

.. |PyPI version| image:: https://img.shields.io/pypi/v/forestatrisk
:target: https://pypi.org/project/forestatrisk
:alt: PyPI version

.. |GitHub Actions| image:: https://github.com/ghislainv/forestatrisk/workflows/PyPkg/badge.svg
:target: https://github.com/ghislainv/forestatrisk/actions
:alt: GitHub Actions

.. |License| image:: https://img.shields.io/badge/licence-GPLv3-8f10cb.svg
:target: https://www.gnu.org/licenses/gpl-3.0.html
:alt: License GPLv3

.. |Zenodo| image:: https://zenodo.org/badge/DOI/10.5281/zenodo.996337.svg
:target: https://doi.org/10.5281/zenodo.996337
:alt: Zenodo

.. |JOSS| image:: https://joss.theoj.org/papers/10.21105/joss.02975/status.svg
:target: https://doi.org/10.21105/joss.02975
:alt: JOSS

.. |pdf| image:: https://ecology.ghislainv.fr/forestatrisk/_static/logo-pdf.png
:target: https://www.theoj.org/joss-papers/joss.02975/10.21105.joss.02975.pdf
:alt: pdf


Owner metadata


GitHub Events

Total
Last Year

Committers metadata

Last synced: 1 day ago

Total Commits: 578
Total Committers: 7
Avg Commits per committer: 82.571
Development Distribution Score (DDS): 0.024

Commits in past year: 60
Committers in past year: 3
Avg Commits per committer in past year: 20.0
Development Distribution Score (DDS) in past year: 0.1

Name Email Commits
Ghislain Vieilledent g****t@c****r 564
Pierrick Rambaud p****9@g****m 8
Daniel S. Katz d****z@i****g 2
thomasarsouze t****e@z****m 1
Ethan White (he/him) e****n@w****g 1
Juan m****r@g****m 1
Katy Barnhart k****t@u****v 1

Committer domains:


Issue and Pull Request metadata

Last synced: 1 day ago

Total issues: 34
Total pull requests: 52
Average time to close issues: about 1 year
Average time to close pull requests: 7 days
Total issue authors: 8
Total pull request authors: 7
Average comments per issue: 1.24
Average comments per pull request: 0.25
Merged pull request: 50
Bot issues: 0
Bot pull requests: 0

Past year issues: 1
Past year pull requests: 2
Past year average time to close issues: about 7 hours
Past year average time to close pull requests: 16 days
Past year issue authors: 1
Past year pull request authors: 1
Past year average comments per issue: 1.0
Past year average comments per pull request: 0.0
Past year merged pull request: 2
Past year bot issues: 0
Past year bot pull requests: 0

More stats: https://issues.ecosyste.ms/repositories/lookup?url=https://github.com/ghislainv/forestatrisk

Top Issue Authors

  • ghislainv (22)
  • ricardozwarg (4)
  • 12rambau (2)
  • molgor (2)
  • datamongerbonny (1)
  • felipedantas-pi (1)
  • soumyadiptapete (1)
  • Wescruise (1)

Top Pull Request Authors

  • ghislainv (42)
  • 12rambau (3)
  • ethanwhite (2)
  • thomasarsouze (2)
  • kbarnhart (1)
  • molgor (1)
  • danielskatz (1)

Top Issue Labels

Top Pull Request Labels


Package metadata

pypi.org: forestatrisk

Modelling and forecasting deforestation in the tropics

  • Homepage: https://github.com/ghislainv/forestatrisk
  • Documentation: https://forestatrisk.readthedocs.io/
  • Licenses: GPLv3
  • Latest release: 1.1.3 (published 4 months ago)
  • Last Synced: 2024-05-10T09:05:22.091Z (1 day ago)
  • Versions: 8
  • Dependent Packages: 0
  • Dependent Repositories: 1
  • Downloads: 852 Last month
  • Rankings:
    • Stargazers count: 6.886%
    • Dependent packages count: 7.31%
    • Forks count: 7.6%
    • Downloads: 9.61%
    • Average: 10.699%
    • Dependent repos count: 22.088%
  • Maintainers (2)

Dependencies

.github/workflows/github-pages.yml actions
  • JamesIves/github-pages-deploy-action v4.4.1 composite
  • actions/checkout v3 composite
  • actions/setup-python v4 composite
.github/workflows/python-package.yml actions
  • actions/checkout v3 composite
  • actions/setup-python v4 composite
.github/workflows/wheel-pypi.yml actions
  • actions/checkout v3 composite
  • actions/download-artifact v3 composite
  • actions/setup-python v4 composite
  • actions/upload-artifact v3 composite
  • pypa/gh-action-pypi-publish release/v1 composite
.github/workflows/lint.yml actions
  • actions/checkout v4 composite
  • actions/setup-python v5 composite
  • pre-commit/action v3.0.0 composite
requirements.txt pypi
  • earthengine-api *
  • gdal *
  • matplotlib *
  • numpy *
  • pandas *
  • patsy *
  • pywdpa *
  • scikit-learn *
setup.py pypi
  • earthengine-api *
  • gdal *
  • matplotlib *
  • numpy *
  • pandas *
  • patsy *
  • pywdpa *
  • scikit-learn *

Score: 13.48333308562593