Skip to content

Urban Heat Island Mapping with MODIS Land Surface Temperature

image

This notebook demonstrates how to visualize and analyze Urban Heat Island (UHI) effects using MODIS MOD11A2 Land Surface Temperature (LST) data and leafmap.

The Urban Heat Island effect describes how urban areas exhibit significantly higher temperatures than surrounding rural land due to human activity, impervious surfaces, and reduced vegetation. LST derived from thermal infrared satellite sensors is one of the most widely used proxies for quantifying UHI intensity.

Outline: - Install and import dependencies - Download MODIS MOD11A2 LST data via earthaccess - Load and preprocess the LST GeoTIFF - Clip to the study area, apply the scale factor, and mask fill/low-quality pixels - Visualize LST on an interactive leafmap - Compute a split map comparing urban vs. rural thermal patterns - Export results

Install dependencies

Uncomment if running in Google Colab or a fresh environment.

1
# %pip install leafmap earthaccess rioxarray matplotlib

Import libraries

1
2
3
4
import matplotlib.pyplot as plt
import rioxarray as rxr
import earthaccess
import leafmap

Authenticate with NASA Earthdata

A free NASA Earthdata account is required. Register at urs.earthdata.nasa.gov. Credentials are stored in ~/.netrc after first login.

1
earthaccess.login(persist=True)

Search for MODIS MOD11A2 LST data

MOD11A2 provides 8-day composite Land Surface Temperature at 1 km resolution. We search for a summer granule over Lahore, Pakistan — one of South Asia's most prominent Urban Heat Island cities.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# Lahore, Pakistan bounding box [west, south, east, north]
bbox = (73.8, 31.3, 74.6, 31.7)

results = earthaccess.search_data(
    short_name="MOD11A2",
    version="061",
    bounding_box=bbox,
    temporal=("2023-06-01", "2023-06-30"),
)

print(f"Found {len(results)} granule(s)")
if not results:
    raise ValueError(
        "No granules found — check your Earthdata credentials and the search parameters."
    )
results[0]

Download the LST granule

1
2
3
4
5
6
7
files = earthaccess.download(results[:1], local_path="modis_lst")
# earthaccess may return sidecar files (e.g. .hdf.xml) alongside the data file,
# and the ordering is not guaranteed, so select the HDF explicitly.
hdf_path = next((f for f in files if str(f).endswith(".hdf")), None)
if hdf_path is None:
    raise ValueError("Download failed — no HDF file returned by earthaccess.")
print(f"Downloaded: {hdf_path}")

Load and preprocess LST

A MOD11A2 granule covers an entire MODIS tile (~1200 km across), so we first clip it to the Lahore bounding box — otherwise the scene statistics below would describe the whole tile rather than the city.

MOD11A2 stores LST as scaled integers. The LST Day layer (LST_Day_1km) must be multiplied by 0.02 to convert to Kelvin, then subtract 273.15 for Celsius. Fill value 0 is masked out, and the QC_Day layer is used to drop cloud-contaminated and other low-quality retrievals.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
grid = f'HDF4_EOS:EOS_GRID:"{hdf_path}":MODIS_Grid_8Day_1km_LST:'

# Open the daytime LST subdataset and its quality layer
lst_raw = rxr.open_rasterio(grid + "LST_Day_1km", masked=True).squeeze()
qc_day = rxr.open_rasterio(grid + "QC_Day").squeeze()

# Clip the granule to the Lahore bounding box before computing any statistics
lst_raw = lst_raw.rio.clip_box(*bbox, crs="EPSG:4326")
qc_day = qc_day.rio.clip_box(*bbox, crs="EPSG:4326")

# QC_Day bits 0-1 are the mandatory QA flags; 00 means good-quality LST was
# produced. Anything else is cloud-contaminated or otherwise unreliable.
good_quality = (qc_day & 0b11) == 0

# Apply scale factor and convert to Celsius
lst_kelvin = lst_raw.where((lst_raw != 0) & good_quality) * 0.02
lst_celsius = lst_kelvin - 273.15

print(
    f"LST range: {float(lst_celsius.min()):.1f} °C  to  {float(lst_celsius.max()):.1f} °C"
)
lst_celsius

Quick static plot

A preliminary view before loading into leafmap.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
fig, ax = plt.subplots(figsize=(10, 7))
lst_celsius.plot(
    ax=ax,
    cmap="RdYlBu_r",
    robust=True,
    cbar_kwargs={"label": "Land Surface Temperature (°C)"},
)
ax.set_title("MODIS MOD11A2 — Daytime LST, Lahore, June 2023", fontsize=13)
ax.set_xlabel("Longitude")
ax.set_ylabel("Latitude")
plt.tight_layout()
plt.savefig("lahore_lst.png", dpi=150)
plt.show()

Export preprocessed LST as GeoTIFF

1
2
3
lst_output = "lahore_lst_celsius.tif"
lst_celsius.rio.to_raster(lst_output)
print(f"Saved: {lst_output}")

Visualize on an interactive leafmap

Load the LST raster with a diverging colormap. Warmer colours (red/orange) indicate urban heat pockets; cooler blues indicate vegetated or rural land.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
m = leafmap.Map(center=[31.5, 74.2], zoom=10)
m.add_basemap("OpenStreetMap")

m.add_raster(
    lst_output,
    colormap="RdYlBu_r",
    vmin=20,
    vmax=50,
    layer_name="LST Day (°C)",
    opacity=0.75,
)

# RdYlBu_r: blue (cool) → yellow → red (hot)
lst_colors = ["313695", "74ADD1", "E0F3F8", "FEE090", "F46D43", "D73027"]
m.add_colorbar(colors=lst_colors, vmin=20, vmax=50)

m

Split map — LST vs. satellite

Swipe between the LST raster and the satellite basemap to correlate high-temperature zones with built-up surfaces.

1
2
3
4
5
6
7
8
9
m2 = leafmap.Map(center=[31.5, 74.2], zoom=10)
m2.split_map(
    left_layer=lst_output,
    right_layer="SATELLITE",
    left_args={"colormap": "RdYlBu_r", "vmin": 20, "vmax": 50, "opacity": 0.9},
    left_label="LST Day (°C)",
    right_label="Satellite",
)
m2

Compute UHI intensity

A simple UHI index: difference between each pixel and the mean LST of the study area. Positive values = warmer than average (urban heat zones).

1
2
3
4
5
6
7
8
9
scene_mean = float(lst_celsius.mean())
uhi_index = lst_celsius - scene_mean

uhi_output = "lahore_uhi_index.tif"
uhi_index.rio.to_raster(uhi_output)

print(f"Scene mean LST: {scene_mean:.2f} °C")
print(f"Max UHI intensity: +{float(uhi_index.max()):.2f} °C")
print(f"Min UHI intensity: {float(uhi_index.min()):.2f} °C")

Visualize UHI index

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
m3 = leafmap.Map(center=[31.5, 74.2], zoom=10)
m3.add_basemap("SATELLITE")

m3.add_raster(
    uhi_output,
    colormap="seismic",
    vmin=-5,
    vmax=5,
    layer_name="UHI Index (°C above mean)",
    opacity=0.75,
)

# seismic: blue (below mean) → white → red (above mean / urban heat)
uhi_colors = ["3333CC", "AAAAFF", "FFFFFF", "FFAAAA", "CC3333"]
m3.add_colorbar(colors=uhi_colors, vmin=-5, vmax=5)

m3

Summary

This notebook demonstrated how to:

  1. Search and download MODIS MOD11A2 LST data using earthaccess
  2. Apply scale factors and unit conversions with rioxarray
  3. Visualize LST interactively with leafmap and a diverging colormap
  4. Build a split map to compare LST against basemap layers
  5. Compute a simple Urban Heat Island intensity index

The workflow is applicable to any city worldwide — change bbox and temporal to explore different regions and seasons.

References