A frame of an animation of inundation in the Amazon rain forest. Credit: Chapman, Guritz 2016; RTC: ASF 2015; Includes Material © JAXA/METI 2007.
Source: Bruce Chapman, JPL, and Rick Guritz, ASF. Adapted to QGIS and GIMP by Eric Anderson, ESSC, English translation Jagan Nautiyal
◆ Advanced (OSX): Use QGIS and GIMP to classify and map regional inundation.
Background
The all-weather ability of synthetic aperture radar (SAR) to penetrate cloud cover and low-light conditions to acquire imagery of the Earth’s surface is well known. Given the availability of high-resolution terrain models at 30 meters from the Shuttle Radar Topography Mission (SRTM) and an interest to make SAR data easier to use, the Alaska Satellite Facility (ASF) offers radiometric terrain corrected (RTC) L-band image products from ALOS PALSAR data.
At longer wavelengths such as L-band, SAR can penetrate surface vegetation including the Amazon rain forest, and flooding events can be mapped very accurately at high resolution. With the availability of RTC data, it is now relatively easy to do accurate flood mapping using PALSAR data. In this recipe, we describe methods used to (a) create an inundation image animation from 18 PALSAR RTC products and (b) produce an inundation map that quantifies the number of flooding events from the given set of data.
Prerequisites
Materials List for Generating an Animation:
- Windows, Mac OS X
- ALOS-1 PALSAR RTC products
- For this tutorial you may use the sample granule list below, or download your own RTC products using Vertex
- For help using Vertex, refer to the Vertex Getting Started User Guide
- For this tutorial you may use the sample granule list below, or download your own RTC products using Vertex
- QGIS (version 2.18.12 used in this recipe) with Orfeo Toolbox (Windows users see How to Access Orfeo Toolbox (Windows))
- GIMP (version 2.8 used in this recipe)
Materials List for Generating a Colorized Map:
- Filtered PALSAR images that were previously generated in Part 1 — Exclude Erroneous Pixels at the Edge of Your Images
Sample Granule List
Click on the product names to download each granule individually.
Granule Name | Product Name |
---|---|
ALPSRP048877090 | AP_04887_FBS_F7090_RT1.zip |
ALPSRP075717090 | AP_07571_FBD_F7090_RT1.zip |
ALPSRP082427090 | AP_08242_FBD_F7090_RT1.zip |
ALPSRP102557090 | AP_10255_FBS_F7090_RT1.zip |
ALPSRP115977090 | AP_11597_FBS_F7090_RT1.zip |
ALPSRP122687090 | AP_12268_FBD_F7090_RT1.zip |
ALPSRP129397090 | AP_12939_FBD_F7090_RT1.zip |
ALPSRP136107090 | AP_13610_FBD_F7090_RT1.zip |
ALPSRP156237090 | AP_15623_FBS_F7090_RT1.zip |
ALPSRP183077090 | AP_18307_FBD_F7090_RT1.zip |
ALPSRP189787090 | AP_18978_FBD_F7090_RT1.zip |
ALPSRP209917090 | AP_20991_FBS_F7090_RT1.zip |
ALPSRP223337090 | AP_22333_FBS_F7090_RT1.zip |
ALPSRP230047090 | AP_23004_FBD_F7090_RT1.zip |
ALPSRP243467090 | AP_24346_FBD_F7090_RT1.zip |
ALPSRP263597090 | AP_26359_FBS_F7090_RT1.zip |
ALPSRP270307090 | AP_27030_FBS_F7090_RT1.zip |
ALPSRP236757090 | AP_23675_FBD_F7090_RT1.zip |
Part 1: Generating an Inundation Animation
Download and Organize the Data
- Download the granules from the Prerequisites section.
- Extract data from the downloaded .zip files and copy the HH image from each granule into a new folder (e.g., HH).
Convert Images to Decibels in QGIS
- Create a new directory to place your output images (e.g., db_HH)
- Open QGIS and use the Open Raster button to load the HH images from the folder you created in the Download and Organize the Data step.
- Ensure that your HH images are open in the Layers Panel (there should be 18 of them)
- Ensure that your Processing Toolbox is open and ready (Processing menu > Toolbox)
- Within the Processing Toolbox, search for “raster calculator”
- Right-click on Raster calculator (GDAL) and execute as batch process.
- In the Parameters tab, click on “…” next to the first box within Input Layer A
- Select from open layers and click Select All
- Click OK to add all image layers to Input Layer A
- Drag the navigation bar over until you see “Calculation in gdalnumeric syntax…”
- In the first box, enter “10*log10(A)”
- Double-click on the title above where you just entered your formula
- To the right of the Calculation header, find “Output raster type“
- Under Output raster type, change the selection from “Byte” to “Float32”
- Double-click on Output raster type to apply to all
- To the right of Output raster type, find Calculated
- Navigate to the directory/folder you created and enter “db_” and click Save
- When prompted, select Fill with parameter values and click OK
- To the right of Calculated find “Load in QGIS”
- Change the first “Yes” to “No” and double-click on Load in QGIS
- Click Run to begin batch processing
- Close Batch Processing dialog window once complete
- Close all images in QGIS using the Layers Panel close button.
Apply Despeckling to dB Converted Images
- Create a new directory to place your output images (e.g., sf_db_HH)
- In QGIS, use the Open Raster button to load the decibel-converted images you created in the Convert Images to Decibels in QGIS step.
- Within the Processing Toolbox, search for “Despeckle”
- Right-click on Despeckle (lee) (Orfeo) and execute as batch process.
- Under “Input Image,” click the “…” and select from open Layers
- Click “Select All” and click OK to add all images
- Scroll right until you find “Output Image” and select “…“
- Navigate to the directory/folder you created and enter “sf_” and click Save
- When prompted, select “Fill with parameter values” and click OK
- To the right of “Fill with parameters values” find “Load in QGIS”
- Select “No” and double-click on “Load in QGIS” to apply to all
- Click Run to begin batch processing
- Close Batch Processing dialog window once complete
- Close all images in QGIS using the Layers Panel close button
Exclude Erroneous Pixels at the Edge of Your Images
The Despeckle tool leaves a strip of extra pixels with very negative values to the edge of the images, which must be removed before the following analysis. When you open the despeckle images, you will find that the images are not correctly rendering due to these negative values.
- Create a new directory to place your output images (e.g., xsf_db_HH)
- In QGIS, use the Open Raster button to load the images created in the Apply Despeckling to dB Converted Images step.
- Within the Processing Toolbox, search for “raster calculator”
- Right-click on Raster calculator (GDAL) and execute as batch process
- In the Parameters tab, click on “…” next to the first box within Input Layer A
- Select from open layers and click Select All
- Click OK to add all image layers to Input Layer A
- Drag the window bar over until you see “Calculation in gdalnumeric syntax…”
- In the first box, enter “(A>-9999)*A”
- Double-click on Calculation in gdalnumeric syntax… to apply to all
- To the right of Calculation, find “Set output nodata value”
- Enter “0” in the first box and double-click on Set output nodata value
- To the right of the Calculation, find “Output raster type”
- Under Output raster type, change the selection from “Byte” to “Float32.”
- Double-click on Output raster type to apply to all
- To the right of Output raster type, find “Calculated”
- Click on “…” next to the first box within Calculated
- Navigate to the directory/folder you created and enter “x” and click Save
- When prompted, select Fill with parameter values and click OK
- To the right of Calculated find “load in QGIS”
- Change the first “Yes” to “No” and double-click on Load in QGIS
- Click Run to begin batch processing
- Close the Batch Processing dialog window once complete
- Close all images in QGIS using the Layers Panel close button.
Classify the Images using a Threshold
This step assumes that your images have a bimodal distribution of pixel values in the image. If you are using different data, the class values will vary and it may take several iterations to determine the appropriate thresholds. For the process of determining the appropriate thresholds, it is good practice to consider one image representing the maximum flooding and another image representing the minimum flooding. Knowledge of the geographical coverage of seasonal flooding helps confirm whether the results are correct.
- In QGIS, use the Open Raster button to load the images created in the Exclude Erroneous Pixels at the Edge of Your Images step.
- Right-click on the first image in the Layers Panel and choose Properties
- In the Style menu, change the Render type to Singleband pseudocolor
- Click on the Histogram tab from the Layer Properties window you have open.
- View the histogram to interpret the distribution of pixel values in the image
Note: You should see a clearly bi-modal histogram with water pixels appearing significantly darker than the main image data.
- To separate water from the rest of the image, pick a threshold at (or near) the minimum between the two modes of the distribution (e.g., -13)
- Return to the Style tab of the Layer Properties window and change the Interpolation to Discrete
- Next to Classify, click on the green cross button three times to add your class value.
- Change the value of the classes to the following: “-13; “-2”; “inf”
- Double-click on the Color to change the class colors
- Set “-13” to blue to represent the main channels of water. Refine the breakpoint values until water is mostly contained within river channels and a very small number of blue dots show on land outside of river channels.
- Set “-2” to black to represent land
- Set “inf” to yellow to represent brighter areas because of double-bounce, which indicates flooded vegetation. To increase the prominence of double-bounce, you must adjust “-2” to a lower value, which adjusts the breakpoint of your second threshold value.
- Adjust the following values until you are satisfied. The class values will be determined by the pixel values in the image.
- Optional — You may adjust Resampling in the Style menu to smooth rendered pixels
- Apply the same Style properties to all images by right-clicking on the image with the desired classification and select Styles > Copy Style
- Click the up button in the Layers Panel to collapse all layers and select all other layers (using Shift)
- Right-click on any of the selected images and click on Paste Style
Export Classified Images as PNG Image Files
- Create a new directory to save your exported images (e.g., Flood_PNG)
- In QGIS, ensure that all of your images are still open in the Layers Panel
- After applying the correct thresholds and colors to all images, turn off visibility for all layers except the first one (xsf_db_AP_27030_FBS_F7090_RT1_HH) by clicking on the checkbox next to the raster layer’s name
- Use the magnification button in the Map Navigation toolbar to center your image to prepare for PNG exporting.
- Navigate to Project > Save as Image
Tip: These steps can be cumbersome if you manually type in each file name. To speed up the process, right-click on each image and select “Rename.” Once highlighted, you can copy the name of the file before saving your image and simply paste the filename in the box, then add a “.png” file extension.
- Save as xsf_db_AP_27030_FBS_F7090_RT1_HH.png and click OK
- Turn off the first image and select the next image
- Repeat steps 1-5 for all images until you have 18 PNG image files
Generate and Display Animated GIF with GIMP
- Select or create a directory to save your animated GIF file
- Open GIMP 2 and select File > Open as Layers…
- Navigate to the directory where your image files are located and select all
- Once all images are loaded, select File > Export As
- Select the directory you chose to save your animation and save the animation as Flood_Animation.gif and an Export GIF dialog window will appear.
- Check the As animation box and set Delay between frames to 500
- Check Use delay entered above for all frames and click Export
- Navigate to the Flood_Animation.gif file and open the animation in a browser by using right-click Open as…
Sample Inundation Animation
Part 2: Generating a Colorized Inundation Map
Classify the Images Using a Threshold in QGIS
Classify each image to separate water (1) from land (0).
- Create a new directory to save your output files (e.g., Reclass _HH)
- In QGIS, use the Open Raster button to load the images created in Part 1 — Exclude Erroneous Pixels at the Edge of Your Images (e.g., xsf_db_AP_10255_FBS_F7090_RT1_HH)
- Within the Processing Toolbox, search for “reclassify”
- Right-click on Reclassify values (simple) (SAGA) and run as batch process.
- Click on “…” next to the first box within Grid
- Select from open layers and click Select All
- Click OK to add all image layers to Grid
- To the right of Grid, find “Replace Condition”
- Change the condition to (1) Low value < grid value < high value
- Double-click on Replace Condition to apply to all
- To the right of Replace Condition find lookup Table
- Click on “…” to the right of the first box within Lookup Table
- In the Fixed table window, assign the following values seen in the image to the right.
- Repeat for all images (batch process won’t allow applying to all)
- To the right of Lookup Table, find Changed Grid
- Click on “…” next to the first box within Changed Grid
- Navigate to the directory you created and enter “r_” and click Save
- When prompted, fill with parameter values and click OK
- To the right of Changed Grid, find “Load in QGIS”
- Change the first option to “No” and double-click “Load in QGIS” to apply to all
- Click Run to begin batch processing
- Close Batch Processing dialog window once complete
- Close all images in QGIS using the Layers Panel close button
Create the Final Product
- Choose a directory to save your colorized inundation map
- In QGIS, use the Open Raster button to load your reclassified images created in Part 2 — Classify the Images Using a Threshold in QGIS
- Open the Raster Calculator by navigating to Raster > Raster Calculator
- Double-click on the first image and click on the “+” operator
- Continue adding each image and symbol until all images are in the equation
- Set the Output Layer to a name and directory of your choosing (e.g., count.tif)
- Click OK to run the Raster Calculator
Note: The combined image will display as a range of gray values. To change this, you may classify the pixel values of the image for analysis. It is good to assign values 0 and 1 to black because these values are usually a result of speckling that remained after filtering. It helps to choose colors that are distinguishable and have logic in terms of the combined image (higher values indicate more frequent flooding).
- Right-click on the image and click on Properties
- In the Style tab, change render type to singleband pseudocolor
- Under Color options, select a color ramp from the list or choose random colors
- Change the classification method to Equal Interval
- Change the number of classes to “19”
- Optional: adjust resampling type to smooth the rendered image
- When you are satisfied, click OK to see the results
Sample Colorized Inundation Maps
How to Access Orfeo Toolbox (Windows)
To use the despeckle tool, you must have access to the Orfeo Toolbox, which is not included with the Windows standalone version of QGIS 2.18.12. To add the toolbox, you must download it using the OSGeo4W installer.
Note: For these steps to work properly, you must have QGIS pre-installed.
- Navigate to QGIS.org
- Select Download Now
- Under Advanced Users, download OSGeo4W setup
- Open OSGeo4W setup
- From the dialog window, select Advanced Install and click Next
- Select Install from Internet and click Next
- Select Root Install Directory (e.g., C:\OSGeo4W) and click Next
- Select Local Package Directory (default works fine) and click Next
- Select Direct Connection and click Next
- Click on https://download.osgeo.org to select and click Next
- In Select Packages menu, type in “otb” in the search box
- Click on Libs to expand
- Under Libs, click on each Skip once and click Next
- Leave all defaults and click Next
- Click on the checkbox and click Next
- Your download will begin
- Click Finish once installation completes
- Open QGIS 2.18.12
- Select Processing from the main menu bar
- Click on Options…
- Click on Providers to expand
- Click on GRASS commands to expand
- Double-click in blank space to the right of Msys folder
- Delete the existing path for “Msys folder”
- Click on Orfeo Toolbox to expand
- Ensure Activate is checked
- Double-click in blank space to the right of OTB applications folder
- Enter the path of your OTB applications folder in the box (e.g., “C:\OSGeo4W64\bin”)
- Double-click in blank space to the right of OTB command line tools folder
- Enter the path of the OSGeo4W64 bin folder in the box (e.g., “C:\OSGeo4W64\bin”)
- Exit QGIS and restart the application
- In the Toolbox menu on the right, the Orfeo Toolbox will now appear
- Return to Prerequisites