Mapping tree cover and extent with Sentinel-1 and 2
Description
This is the GitHub repository for the Sentinel-1 and Sentinel-2 dataset Tropical Tree Cover, which is viewable on Google Earth Engine here. The asset is public as of May 2023 on Google Earth Engine here. The dataset is published in Remote Sensing of Environment.
This project maps tree extent at the ten-meter scale using open source artificial intelligence and satellite imagery. The data enables accurate reporting of tree cover in urban areas, tree cover on agricultural lands, and tree cover in open canopy and dry forest ecosystems.
This repository contains the source code for the project. A full description of the methodology can be found in the publication. The data product specifications can be accessed on the wiki page.
- Background
- Data Extent
- Methodology
- Validation and Analysis | Jupyter Notebook
- Definitions
- Limitations
Citation
Brandt, J., Ertel, J., Spore, J., & Stolle, F. (2023). Wall-to-wall mapping of tree extent in the tropics with Sentinel-1 and Sentinel-2. Remote Sensing of Environment, 292, 113574. doi:10.1016/j.rse.2023.113574
Brandt, J. & Stolle, F. (2021) A global method to identify trees outside of closed-canopy forests with medium-resolution satellite imagery. International Journal of Remote Sensing, 42:5, 1713-1737, DOI: 10.1080/01431161.2020.1841324
Getting started
An overview Jupyter notebook walking through the creation of the data can be found here
A Google Earth Engine script to export Geotiffs of the extent data by country can be found here
Installation
Utilizing this repository to generate your own data requires:
- Sentinel-Hub API key, see Sentinel-hub
- Amazon Web Services API key (optional) with s3 read/write privileges
The API keys should be stored as config.yaml
in the base directory with the structure:
key: "YOUR-SENTINEL-HUB-API-KEY"
awskey: "YOUR-AWS-API-KEY"
awssecret: "YOUR-AWS-API-SECRET"
The code can be utilized without AWS by setting --ul_flag False
in download_and_predict_job.py
. By default, the pipeline will output satellite imagery and predictions in 6 x 6 km tiles to the --s3_bucket
bucket. NOTE: The specific layer configurations for Sentinel-Hub have not yet been released but are available on request.
With Docker
git clone https://github.com/wri/sentinel-tree-cover
cd sentinel-tree-cover/
touch config.yaml
vim config.yaml # insert your API keys here
docker build -t sentinel_tree_cover .
docker run -it --entrypoint /bin/bash sentinel_tree_cover:latest
cd src
python3 download_and_predict_job.py --country "country" --year year
Without docker
- Clone repository
- Install dependencies
pip3 install -r requirements.txt
- Install GDAL (different process for different operating systems, see https://gdal.org)
- Download model
python3 src/models/download_model.py
- Start Jupyter notebook and navigate to
notebooks/
folder
Usage
The notebooks/
folder contains ordered notebooks for downloading training and testing data and training the model, as follows:
- 1a-download-sentinel-2: downloads monthly mosaic 10 and 20 meter bands for training / testing plots
- 1b-download-sentinel-1: downloads monthly VV-VH db sigma Sentinel-1 imagery for training / testing plots
- 2-data-preprocessing: Combines satellite imagery for training / testing plots with labelled data from Collect Earth Online
- 3-feature-selection: Feature selection for remote sensing indices utilizing random forests
- 4-model: Trains and deploys tree cover model
The src/
folder contains the source code for the project, as well as the primary entrypoint for the Docker container, download_and_predict_job_fast.py
download_and_predict_job_fast.py
can be used as follows, with additional optional arguments listed in the file: python3 download_and_predict_job_fast.py --country $COUNTRY --year $YEAR
Methodology
Model
This model uses a U-Net architecture with the following modifications:
- Convolutional GRU encoder with group normalization to develop temporal features of monthly cloud-free mosaics
- Concurrent spatial and channel squeeze excitation in both the encoder and decoder (https://arxiv.org/abs/1803.02579)
- DropBlock and Zoneout for generalization in both the encoder and decoder
- Group normalization and Swish activation in both the encoder and decoder
- AdaBound optimizer with Stochastic Weight Averaging and Sharpness Aware Minimization
- Binary cross entropy and boundary loss
- Smoothed image predictions across moving windows with Gaussian filters
- A much larger input (28x28) than output (14x14) at training time, with 182x182 and 168x168 input and output size in production, respectively
Data
This project uses Sentinel 1 and Sentinel 2 imagery. Monthly composites of Sentinel 1 VV-VH imagery are fused with the nearest Sentinel 2 10- and 20-meter bands. These images are preprocessed by:
- Super-resolving 20m bands to 10m with DSen2
- Calculating cloud cover and cloud shadow masks
- Removing steps with >30% cloud cover, and linearly interpolating to remove clouds and shadows from <30% cloud cover images
- Applying Whittaker smoothing (lambda = 100) to each time series for each pixel for each band to reduce noise
- Calculating vegetation indices, including EVI, BI, and MSAVI2
The cloud / shadow removal and temporal mosaicing algorithm is summarized below:
- Select all images with <30% cloud cover
- Select up to two images per month with <30% cloud cover, closest to beginning and middle of month
- Select least cloudy image if max CC > 15%, otherwise select the image closest to the middle of the month
- Linearly interpolate clouds and cloud shadows with a rolling median
- Smooth time series data with a rolling median
- Linearly interpolate image stack to a 15 day timestep
- Smooth time stack with Whittaker smoother
License
The code is released under the GNU General Public License v3.0.
Project Organization
βββ LICENSE
βββ Makefile <- Makefile with commands like `make data` or `make train`
βββ README.md <- The top-level README for developers using this project.
βββ docs <- A default Sphinx project; see sphinx-doc.org for details
β
βββ models <- Trained and serialized models, model predictions, or model summaries
β
βββ notebooks <- Jupyter notebooks
βΒ Β βββ baseline
βΒ Β βββ replicate-paper
βΒ Β βββ visualization
β
βββ references <- Data dictionaries, manuals, and all other explanatory materials.
β
βββ requirements.txt <- The requirements file for reproducing the analysis environment, e.g.
β generated with `pip freeze > requirements.txt`
β
βββ setup.py <- makes project pip installable (pip install -e .) so src can be imported
βββ src <- Source code for use in this project.
βΒ Β βββ __init__.py <- Makes src a Python module
β β
βΒ Β βββ data <- Scripts to download or generate data
βΒ Β βΒ Β βββ make_dataset.py
β β
βΒ Β βββ features <- Scripts to turn raw data into features for modeling
βΒ Β βΒ Β βββ build_features.py
β β
βΒ Β βββ models <- Scripts to train models and then use trained models to make
β β β predictions
βΒ Β βΒ Β βββ predict_model.py
βΒ Β βΒ Β βββ train_model.py
β β
βΒ Β βββ visualization <- Scripts to create exploratory and results oriented visualizations
βΒ Β βββ visualize.py
β
βββ tox.ini <- tox file with settings for running tox; see tox.testrun.org