These are the Google Earth Engine scripts used in my APDC investigação project, at FCT-UNL. These scripts run in the online code editor, you may need to register in order to use the platform. You can access these files in the code editor repositories here.
The main idea of the project was to use Google Earth Engine to detect burnt area. The location chosen was a county in Aveiro, Portugal. This was an iterative project, that started on a simple script 01_DeltaNDVI_Threshold, each file is an and after some revisions ended up with script 06_Masking_Zones.
All the scripts create two images a pre-fire image and a post-fire image from Sentinel-2 images. Below you can see color composite images (R-SWIR, G-NIR, B-RED) of study area pre and post-fire.
Pre-Fire Image | Post-Fire Image |
From these images, the script creates a classification image where, 0 means not burnt 1 means burnt. We need to compare it to our ground truth, a shapefile with the 2016 fires from ICNF. GEE provides metrics like accuracy and kappa but there is also a need to see how the errors are distributed on the map. For that purpose, confusion images are generated. These images show the official classification and the scrip classification at the same time in order to understand where they differ. The following table depicts the color code used and the image is an example of an image using such color code.
Color Code | Example Image |
Classifying burnt area based on a hand-chosen threshold for the difference of NDVI between two dates.
First, the NDVI (an index used in remote sensing) pre and post-fire is calculated in order to calculate the delta NDVI. After creating a histogram for the delta NDVI in the burnt and non-burnt area we can select a range where the best threshold should be.
burnt and non-burnt area delta NDVI histogram
After running the script multiple times with different thresholds the best was -0.24, with a 0.9229 accuracy and 0.7719 kappa.
The same as the previous file but other indices are used, namely: NBR1, NBR2, and EVI.
NDVI is not the best index to use, so other indices were testes, the best was NBR1 with a threshold of -0,240 that attained an accuracy of 0.9236 and kappa of 0,7768.
Classifying the burned area with multiple indices and using the available classifiers GEE provides.
Manually choosing a threshold can become a tedious task, this is a problem we are able to solve with the help of machine learning. The classifiers will receive as input 15 features. The indices used are : NDVI, MIRBI, NBR, BAI, and NBR4. But the classifier will receive the indices pre, post-fire, and their delta. The best classifier was the SVM followed closely by gmoMaxEnt, CART, continuousNaiveBayes, and randomForest. The other classifiers provided unsatisfactory results or arose a server error.
After analyzing the images there is a bit of noise in the classifications, so the next step would be to try to reduce it. There were two main ideas to reduce the noise they are implemented in the files that start with 04_Smoothing. Unfortunatly the results are not as good as an image without anny smoothing.
Applying a basic smoothing algorithm after the classification. This script convolves a Gaussian kernel over the classified image in order to reduce noise.
Applying a basic smoothing algorithm before the classification with hopes to reduce noise. This script uses a custom kernel, with 0 as the center value, that duplicates the input features in order to give the classifier information on the neighboring pixels.
Up until this point the training data has been gatherd using random sampling. This type of sampling does not ensure that every type of terrain is represented during training, that lack of information may lead the classifiers to misclassify some pixels. To solve this issue a stratified random sampling based on land cover was implemented to gather training data.
After analyzing the images we found that a part of a highway was being misclassified. Using masks to never classify certain zones, seemed like a good idea. This script only applies a mask of the highway, but it can easily be extended to mask anything.