Step by step: Radar-based flood mapping with Python

A static Jupyter Notebook for automatic radar-based flood extent mapping is shown below. The notebook can be accessed on GitHub or directly executed in Binder or Google Colab. Please find below the links to the respective platforms: [![GitHub stars](]( [![Binder](]( [![Open In Colab](](

The objective of this Recommended Practice is to determine the extent of flooded areas. The usage of Synthetic Aperture Radar (SAR) satellite imagery for flood extent mapping constitutes a viable solution with fast image processing, providing near real-time flood information to relief agencies for supporting humanitarian action. The high data reliability as well as the absence of geographical constraints, such as site accessibility, emphasize the technology’s potential in the field.

This Jupyter Notebook covers the full processing chain from data query and download up to the export of a final flood mask product by utilizing open access Sentinel-1 SAR data. The tool's workflow follows the UN-SPIDER Recommended Practice on Radar-based Flood Mapping and is illustrated in the chart below. After entering user specifications, Sentinel-1 data can directly be downloaded from the Copernicus Open Access Hub. Subsequently, the data is processed and stored in a variety of output formats.

File Structure
The Jupyter Notebook file constitutes the directory of origin. Additional data is contained in subfolders. Sentinel-1 images need to be stored in a subfolder called 'input'. If no image is provided, the subfolder will automatically be created when accessing and downloading data from the Copernicus Open Access Hub through this tool. If an area of interest (AOI) file is available (supported formats: GeoJSON, SHP, KML, KMZ), it needs to be placed in a subfolder called 'AOI'. If none are available, an interactive map will allow to manually draw the area of interest. For reasons of automatic file selection, it is recommended to place only one AOI file in the respective folder. However, if multiple files exist, GeoJSON files are prioritized followed by SHP, KML, and KMZ. The processed data is stored in a subfolder called 'output'.
In order to run the tool with no user interaction, all inputs must be clearly defined. This means that the 'input' subfolder must include one single Sentinel-1 image and the 'AOI' subfolder one single AOI file. All other scenarios do require manual interaction such as downloading data or defining an AOI.

Difficulties in detecting flooded vegetation and floods in urban areas due to double bounce backscatter. If water and non-water are very unequally distributed in the image, the histogram might not have a clear local minimum, leading to incorrect results in the automatic binarization process.

Important The Jupyter Notebook takes advantage of the ESA SNAP API Engine and requires installation of the SNAP-Python interface snappy. Click here for further information. Furthermore, the Jupyter Notebook Extensions Codefolding, ExecuteTime and Table of Contents (2) are used for the most convene performance.

User Input

Please specify in the code cell below i) the polarisation to be processed, ii) whether data shall be downloaded from the Copernicus Open Access Hub with respective sensing period and login details, and iii) whether intermediate results should be plotted during the process.

# polarisations to be processed
polarisations = 'VH'                              # 'VH', 'VV', 'both'

# download image from Copernicus Open Access Hub
download = {
    'imageDownload'     : True,                   # 'True', 'False'
    'period_start'      : [2020, 11, 5],          # format: [Year, Month, Day]
    'period_stop'       : [2020, 11, 13],         # format: [Year, Month, Day]
    'username'          : 'username',             # username for login
    'password'          : 'password'              # password for login

# show intermediate results if set to 'True'
plotResoluts = True                               # 'True', 'False'


This section loads relevant Python modules for the following analysis and initializes basic functionalities.

# Click to run

Download Image

This section allows interactive data access and download from the Copernicus Open Access Hub. If an AOI file is given in the 'AOI' subfolder, the tool searches and displays available Sentinel-1 images accordingly. If no AOI file is provided, the search bar on the left side of the interactive map can be used to find the desired region. The AOI can be then be selected and manipulated manually by using the drawing tool. Clicking the Search button below the map will load available images. If multiple AOIs are drawn, only the last one is considered. When hovering over a Sentinel-1 image, the tile index and ingestion date are shown. The table below summarizes information on all available tiles and allows the download. The data is stored in the automatically created 'input' subfolder. The Open Access Hub maintains an online archive of at least the latest year of products for immediate download. Access to previous products that are no longer available online will automatically trigger the retrieval from the long term archives. The actual download can be initiated by the user once the data are restored (within 24 hours).

# Click to run

Successfully connected to Copernicus Open Access Hub.

Product 9d5fefa0-7d53-461c-804a-61fb01ce64b5 is online. Starting download.

Downloading: 100%|██████████| 991M/991M [00:44scikit-image implementations and a combined use of the <a href="">minimum method</a> and <a href="">Otsu's method</a>. The <a href="">GlobCover</a> layer of the European Space Agency is used to mask out permanent water bodies.
  1. Speckle Filtering: A Median filter with an X, Y size of 7, 7 is used in this step.
# Click to run

Subset successfully generated.  

1. Apply Orbit File:                 ---  0.02 seconds ---
2. Thermal Noise Removal:            ---  0.01 seconds ---
3. Radiometric Calibration:          ---  0.03 seconds ---
4. Speckle Filtering:                ---  0.01 seconds ---
5. Terrain Correction:               ---  0.05 seconds ---
6. Binarization:                     --- 14.39 seconds ---
7. Speckle Filtering:                ---  0.01 seconds ---
8. Plot:                             --- 55.75 seconds ---

Data Export

The processed flood mask is exported as GeoTIFF, SHP, KML, and GeoJSON and stored in the 'output' subfolder. An interactive map shows the flood mask.

# Click to run

1. GeoTIFF:                   --- 31.88 seconds ---
2. SHP:                       --- 23.53 seconds ---
3. KML:                       ---  0.55 seconds ---
4. GeoJSON:                   ---  1.68 seconds ---

Files successfuly stored under /home/eouser/Desktop/Recommended Practices/output.