Code Monkey home page Code Monkey logo

unet-defmapping's Introduction

Deforestation mapping using UNets

This repository contains the scripts referring to a methodology that performs the deforestation mapping using UNets and satellite images from Sentinel-2, being part of my master's thesis in Environmental Science and Technology. The methodology was tested for mapping deforestation spots using images from the Amazon and Atlantic Rainforest biomes, located in Brazil. Therefore, the files presented in the "Files" folder refer to UNets trained using images from these both regions. The results of these applications are being evaluated in journals and the access links will be made available as soon as they undergo peer review.

1 Usage

To identify deforestation in areas where UNet has already been trained (Amazon and Atlantic Rainforest), it is possible to directly use the scripts presented in the Deforestation-mapping folder and the files available in "Files". Otherwise, it is necessary to carry out a new training, using the training files of UNet in the folder of the same name. To do so, you must have the training images and their respective masks at hand.

1.1 Training a UNet

The UNet training procedures are described in the README.md file, found in the UNet folder.
For a new training to be used in the deforestation mapping algorithm, pay attention to using Level 2A Sentinel-2 images and a composition of RGB + Near-infrared images (Bands 4-3-2-8). For masks, non-forest regions are represented by the value 0, while forest areas are represented by the value 1.

1.2 Using the mapping deforestation script

The following figure shows the work flow of the proposed method (extracted from Bragagnolo et al., 2021):

drawing

The scripts for this functionality are in the "Deforestation-mapping" folder.
To execute the algorithm, use the file deforestation_main.py, where some information must me added:

# scripts that must be in the same path that this one
from deforestation_mapping import *

# .GEOjson file of the area to be monitored
geojson_file = '/rondonia_square3.geojson'

# path to save the downloaded images
save_imgs = '/Downloaded'

# save RGB files
save_rgb = '/rgb_files'

# save tiles
save_tiles = '/tiles_imgs"

# Unet weights file
unet_weights = "/weights_file_of_trained_UNet.hdf5"

# Unet weights clouds file
unet_clouds = '/weights_file_of_clouds_trained_UNet.hdf5'

# classificated images path
class_path = "/predicted"

# classificated clouds images path
class_clouds = "/predicted_clouds"

# polygons save
poly_path = '/polygons'

# files saved after the trained UNet
percentiles_forest = ["/bands_third.npy",
                       "/bands_nin.npy"]

percentiles_clouds = ["/bands_third_clouds.npy",
                       "/bands_nin_clouds.npy"]

def_main(save_imgs, save_rgb, save_tiles, unet_weights, unet_clouds,
         class_path, class_clouds, poly_path, 
         percentiles_forest, percentiles_clouds, geojson_file)

Some settings must also be made in the file deforestation_mapping.py, as credentials for accessing the Sentinel-Hub (user and passwrod) and defining the time period to be covered by the analysis (parameter date):

# connect to the API
user = 'USERNAME'
password = 'PASSWORD' 

api = SentinelAPI(user, password, 'https://scihub.copernicus.eu/dhus')

# search by polygon
footprint = geojson_to_wkt(read_geojson(boundsdata))

# search for the images
products = api.query(footprint,
                 date = (["NOW-30DAYS","NOW"]),
                 area_relation = 'IsWithin',
                 platformname = 'Sentinel-2',
                 processinglevel = 'Level-2A',
                 #cloudcoverpercentage = (0, 20)
                )

2 Results

At the end of the algorithm, raster images will be obtained indicating the deforestation spots for the given image, as well as vector files, in the shapefile .shp format, also indicating the deforested areas.

References

Bragagnolo, L., Silva, R.V., Grzybowski, J.M.V. (2021) Deforestation mapping in two Brazilian biomes applying U-Net and logistic model. (under evaluation)

System requirements

Python 3.0
Keras and Tensorflow
sklearn
rasterio
rkimage
fiona
cv2
numpy_indexed
sentinelsat
zipfile
glob
matplotlib

unet-defmapping's People

Contributors

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