Giter Site home page Giter Site logo

molgor / forestatrisk Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ghislainv/forestatrisk

0.0 2.0 0.0 77.05 MB

:package: :snake: Python package to model and forecast the risk of deforestation

Home Page: https://ecology.ghislainv.fr/forestatrisk

License: GNU General Public License v3.0

C 14.46% Python 71.15% Shell 4.67% C++ 0.29% Makefile 0.24% CSS 0.02% TeX 9.16%

forestatrisk's Introduction

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

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

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

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

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.

forestatrisk's People

Contributors

ghislainv avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.