The Step-by-Step Explanation is also available as a PDF, which can be downloaded here.
Before the Flood
There are multiple steps in this practice, you can already perform before a flood hits your Area of Interest (AOI). This will help you to save crucial time during the disaster, to ensure a rapid response.
1. Create your AOI on GFM
First, make a user account on GFM: Global Flood Monitoring.
To access the data, you need to create an AOI, which will be stored in your GFM account. You need to assign a name and a description to your AOI. Then click on “Next step”.
In the next step, you can choose between giving the Coordinates to your AOI, drawing the AOI or selecting a region. Most of the time, drawing the AOI is the best idea. Therefore, select the square to the right of the panel, draw the AOI and select Save AOI.
2. Check GloFAS regularly
To know when floods are likely to hit your region, check GloFAS regularly. Check if there are any unusually high precipitations forecasted.
3. Download the FABDEM of your AOI
The FABDEM is a 30m open-access Digital Terrain Model. You can find all necessary information in this Data Application of the Month or in this Scientific Publication: https://iopscience.iop.org/article/10.1088/1748-9326/ac4d4f/meta.
Among other options, the FABDEM can be downloaded with Google Earth Engine. With the link below, you can download the FABDEM for your AOI. By clicking on the rectangle tool, you can draw a polygon of your AOI. Then you can click on Run, to run the script. Under tasks, you will see the FABDEM popping up. Click on RUN. When the task is finished, you can download the DTM from your Google Drive.
Using other DTMs, for example a high-resolution national DTM or commercial DTMs is also possible. The spatial resolution and accuracy of the DTM is one of the key points to the success of this practice.
4. Setup Python
This is a step-by-step procedure to setup the Python environment, in which the FLEXTH algorithm will work. If you already have a Python installation on your computer, it still makes sense to follow this guide, to ensure all libraries are installed properly.
We need to install the latest version of Miniforge, which is a light-weight Python distribution. Follow this Link, which leads you to a repository storing the Miniforge3 installers for the different operating systems (OS). If you are using a Windows 64bit machine, click on „latest“ in the respective row. On the next page look for „Miniforge3-Windows-x86_64.exe“. Click on the link to download the executable.
Double click the executable to start the setup. In the setup menu, click on „Next“ , then on „I agree“. Install for „Just Me (recommended)“.
For the Install Location, you can just go with the default folder. Click „next“. For the Advanced Installation Options, you can also go with the default selection. Click „install“.
After the installation click „next“ and then „Finish“. Open the Miniforge Prompt. This is a command line interface. First, we create a new virtual environment for the practice called „flexth_env“. Then we install the necessary libraries into the new environment:
mamba create –n flexth_env python=3.12
mamba activate flexth_env
mamba install numpy scipy rasterio astropy opencv gdal scikit-image matplotlib geopandas spyder jupyterlab
jupyter lab
Press Enter after every line of code. You will be asked to confirm some changes with a „Y“ and pressing Enter. Care, that you don‘t add or miss any spaces in the text.
After activating the environment, you should see the name of the environment in brackets at the beginning of the line. A Python interface called Jupyter Lab will open after the last line of code.
The installation of the libraries will take some time. You will see a progress bar in the terminal window, and it will print „done“ once the installation is terminated.
5. Make yourself familiar with the FLEXTH tool
If everything worked out, you are now able to open Jupyter Lab by writing jupyterlab into the console and executing the command (the last line in the previous code).
The script is divided into 6 sections:
Loading necessary libraries.
Specifing user specific input and output directories.
Selecting the AOI and DTM source.
Setting further Parameters
Mosaicing and Reprojecting GFM outputs.
FLEXTH
In Jupyter Lab, on the left side, you can see your directories. Browse to the directory of the FLEXTH script “GFM2FLEXTHnb.ipynb”. Go to the first cell and click on the “Run current Cell” symbol on the task bar.
You can download the .py or .ipynb from here: https://github.com/UN-SPIDER/radar-based-flood-mapping-dtm/blob/main/S1/GFM2FLEXTHnb.ipynb
If the execution of the first cell works without any error messages, you will read “Libraries are loaded” in the console.
Now you are prepared to use the tool in case of a flood.
During the Flood
This practice uses the outputs from the Global Food Monitoring Database, as it provides timely and state-of the art flood delineations. Furthermore, it also fulfills the requirement of an exclusion mask.
Still, it is also possible and encouraged, to use own flood delineations in this practice. If you want to use your own flood delineation, we ask you, to use the original script developed by Andrea Betterle, accessible via this link:
The code runs in the same environment. You will still need an exclusion mask, a DTM and if available a mask for the permanent and seasonal waterbodies.
6. Download the Input Layers from GFM
On the task bar, go to Products, select your created AOI and set the Start and End date. If you select „Retrieve latest product“, you will get the latest acquisitions overlapping with your AOI.
Select one of the scenes, ideally the scene should be acquired only a few days after the flooding. In the example the scene from 2024-11-02 over the Philippines is selected. The Sentinel-1 footprint will show within a dashed line. Care that the AOI is completely covered by the footprint as in the example.
You can browse through the different layers. In the example, the exclusion mask is visualized.
Now, click on „Download Layers“. The download will start automatically.
7. The Likelihood Layer vs. The Flood Extend
GFM also provides a likelihood layer, in which pixels are assigned a likelihood of flooding. Detailed documentation on how these values is calculated is provided here: GFM Product Output Layers | EODC Public Wiki
This is useful in case there are not enough pixels classified as flooded in the Observed Flood Extent Layer. In that case this layer is thresholded with a likelihood threshold, for example pixels with a likelihood > 40% are considered as flooded.
Also, the Reference Water Mask is used in the FLEXTH tool. Like that, water bodies will not be detected as flood.
8. Open Python
Now we will go again into our Python environment. Therefore, execute the code below as you did before during the Python setup.
mamba activate flexth_env
jupyter lab
9. Prepare Input and Output directories
Unzip the downloaded folder from GFM and Google Drive and move them to your directory. In the same directory, create a folder called „output“. The directory should look something like this:
Copy the folder paths to the script, input_dir being the unzipped download folder from GFM, and output_dir being the newly created output folder.
Unzip the downloaded folder and move them to your directory. In the same directory, create a folder called „output“. Copy the file paths into the FLEXTH script.
Under „Setting further Parameters“, you can specify a few more things:
If you want to use the likelihood layer instead of the flood layer, specify likelihood = True. Per default 40% is used as a threshold. You can change it of course in likelihood_threshold.
All outputs will transform into EPSG 3857 per default. If you want to use a national or regional coordinate system, please provide the epsg code in dst_crs in the format EPSG:XXXX.
10. AOI DTM
In order not to process the entire Sentinel-1 scene, it is possible to specify an AOI, which should be either a geopackage (.gpkg) or a shapefile (.shp).
Specify the path to your AOI in roi_path.
If you do not wish to select an AOI, just write None.
Specify the path to your dtm in the variable dtm_path. It should be a tif, for example the FABDEM, which we downloaded with the Google Earth Engine during the first steps of this practice.
11. Hydrological Parameters
Testing showed that the default values are effective and robust in a wide range of settings. Nonetheless, parameters can be tweaked to match specific needs and/or use cases.
Parameters may require adjustments for resolutions much larger/smaller than 10m.
If the flood does not propagate far enough into urban and vegetated areas, the parameter A1/2 (param_distance_range) is the most responsive one. The parameter can be interpreted like: if you have an area of 10 km2 flooded, then the water will propagate 5 km into areas of the exclusion mask. If you lower the size of the area or increase the maximum propagation distance, the flooded area will increase.
12. Troubleshooting
If you don‘t have enough RAM on your machine, you will get the error message: …unable to allocate … for an array with size. Consider tiling your input data, and if you did already, consider reducing the tile size
The code does not overwrite the raster automatically. You have to delete the mosaics and reprojected raster before reprocessing the inputs (cell …). Or you move them to another directory.
13. Visualize and Compare the Output
By executing the last cell 7. Quick Output Summary, the area flooded before FLEXTH, and the area flooded after FLEXTH will be output.