Calculating Satellite Image Cloud Cover

Gamze Ç.
2 min readMay 11, 2024

--

Satellite imagery offers invaluable insights into Earth’s landscapes and features. It serves diverse applications, including Python and Remote Sensing methodologies. However, a notable limitation arises from clouds, which are inevitably captured as satellites orbit the Earth and gather data. Cloud cover not only obstructs clear Earth observation but also hampers remote sensing algorithms. This interference leads to inefficient CPU usage and the introduction of erroneous data values, undermining the accuracy of results.

A cloud mask delineates cloud data within its own raster layer. This raster can serve as a guide during image processing to exclude cloud data or alternatively, facilitate cloud removal from the original image.

Create a cloud mask for a Landsat image using the rasterio module and the rio-l8qa plugin. The cloud mask will be created as a separate image that just contains clouds:

  1. First, we need to download some sample Landsat 8 satellite image data as a ZIP file from http://bit.ly/landsat8data.
  2. Click the download icon in the top right to download the data as a ZIP file, and unzip it to a directory named l8.
  3. Next, make sure you have the raster libraries that we need by running pip:
pip install rasterio
pip install rio-l8qa
  1. Now, we’ll create the cloud mask by first importing the libraries that we need:
import glob
import os
import rasterio
from l8qa.qa import write_cloud_mask
  1. Next, we need to provide a reference to our satellite image directory:
# Directory containing landsat data
landsat_dir = "l8"
  1. Now, we need to locate the quality-assurance metadata for the satellite data, which gives us the information that we need to generate the cloud mask:
src_qa = glob.glob(os.path.join(landsat_dir, '*QA*'))[0]
  1. Finally, we use the quality-assurance file to create a cloud mask TIFF file:
with rasterio.open(src_qa) as qa_raster:
profile = qa_raster.profile
profile.update(nodata=0)
write_cloud_mask(qa_raster.read(1), profile, 'cloudmask.tif')

The following image is just the band 7 (short-wave infrared) image from the Landsat 8 dataset:

The next image is the cloud mask image containing only the location of clouds and shadows:

And finally, here’s the mask over the image, showing the clouds as black:

This example brushes the surface of what you can do with image masking. Another rasterio module, rio-cloudmask, allows you to calculate the cloud mask from scratch without using the quality-assurance data

--

--

Gamze Ç.

Data Scientist | Earth Observation | Location Intelligence | AI for Spatial Data Analyst