Skip to content
Ahmad Ammar

1. Before you start

This guide is the notebook version of Reading radar images. That manual explains what radar images show and how they were made in Google Earth Engine; here you work with the images yourself in Python, from opening a file to an area of flooded land with its uncertainty. The images were exported from Earth Engine by the manual’s scripts and are downloaded by the notebook’s first cell, so you need no Earth Engine account.

1.1 What you will learn

  • Data: what a georeferenced raster is (bands, coordinate reference system, pixel size) and how to open one with rasterio.

  • Physics: what a radar measures, why water is dark and buildings bright, what decibels are, what speckle is, and what VV and VH polarisations tell you.

  • Methods: why averages must be taken in linear units, how to measure speckle (the equivalent number of looks), how Otsu’s method chooses a threshold, and how a flood rule is built from two dates and a water record.

  • Reading results: how to read each image, histogram, table and map, and how to report an area with its uncertainty.

1.2 Getting Python and the notebook

Open the Notebooks page of this guide and choose Open in Colab to run it in a web browser with nothing to install; the first cell installs rasterio, which Colab lacks. On your own computer:

conda create -n radar python=3.12 numpy matplotlib rasterio jupyterlab
conda activate radar
jupyter lab

Then open the downloaded radar.ipynb. Boxes labelled In [n] are code and Out [n] what it printed or drew. Run the cells in order from the top.

1.3 Setup

This notebook reads Sentinel-1 radar images with Python. It works the two experiments of the guide Reading radar images step by step: the basics over London, then mapping the 2022 flood in Sindh. The images were exported from Google Earth Engine by the scripts of that guide; here they are small GeoTIFF files, downloaded by the first cell, so no Earth Engine account is needed.

Libraries: rasterio reads and writes georeferenced rasters (GeoTIFF); numpy does arithmetic on whole images; matplotlib draws them. Google Colab does not include rasterio, so the first cell installs it when missing.

In [1]
import importlib.util, json, subprocess, sys, urllib.request
from pathlib import Path
if importlib.util.find_spec("rasterio") is None:
    subprocess.run([sys.executable, "-m", "pip", "install", "-q", "rasterio"], check=True)
import numpy as np
import rasterio
from rasterio.warp import transform as reproject_points
import matplotlib.pyplot as plt

plt.rcParams.update({"figure.dpi": 110})
BASE = "https://raw.githubusercontent.com/AhmadAmmar/AhmadAmmar.github.io/main/guides/radar-python/notebooks/data_local/"
FILES = ["london_mean_vv_10m.tif", "london_single_vv_10m.tif", "london_2024_mean_80m.tif", "sindh_flood_200m.tif", "london_stats.json", "sindh_stats.json"]
DATA, LOCAL = Path("data"), Path("data_local")
DATA.mkdir(exist_ok=True)
for f in FILES:
    if not (DATA / f).exists():
        (DATA / f).write_bytes((LOCAL / f).read_bytes() if (LOCAL / f).exists() else urllib.request.urlopen(BASE + f, timeout=120).read())
    print(f"{f:28s} {(DATA / f).stat().st_size / 1e6:5.2f} MB")
Out [1]
london_mean_vv_10m.tif        2.85 MB
london_single_vv_10m.tif      2.90 MB
london_2024_mean_80m.tif      4.13 MB
sindh_flood_200m.tif          3.91 MB
london_stats.json             0.00 MB
sindh_stats.json              0.00 MB