Practical Course 13

Air Quality Mapping with Sentinel-5P NO2 and DeepSeek

Explore nitrogen dioxide pollution in North Morocco using satellite data and AI-powered code generation.
North Morocco ~2 hours Master - Climate Change and GeoAI
Dataset: COPERNICUS/S5P/OFFL/L3_NO2 Sentinel-5P Nitrogen Dioxide

📖 Key Terms for Beginners

Before starting, make sure you understand these terms. They appear throughout all code blocks in this course.

TermFull NameWhat it means in simple words
NO2Nitrogen DioxideA harmful air pollutant produced by combustion processes.
Sentinel-5PSentinel-5 PrecursorA European Space Agency mission for monitoring air pollution.
TROPOMITropospheric Monitoring InstrumentThe main instrument on Sentinel-5P, measuring atmospheric composition.
QA_valueQuality Assurance ValueA measure of the quality and reliability of the satellite data.
GEEGoogle Earth EngineA cloud-based platform for geospatial analysis.
Image CollectionImage CollectionA series of images in GEE, typically from the same sensor.
ImageImageA single raster dataset in GEE.
BandBandA single layer of data within an image.
MedianMedianThe middle value in a set of numbers, used for reducing noise.
Cloud MaskingCloud MaskingThe process of removing or reducing the effect of clouds in satellite imagery.
VisualizationVisualizationThe process of displaying data in a graphical format.
DeepSeekDeepSeek CoderAn AI coding assistant for generating code.
AIArtificial IntelligenceComputer systems that can perform tasks that normally require human intelligence.
Rif MountainsRif MountainsA mountain range in northern Morocco.
Middle AtlasMiddle AtlasA mountain range in central Morocco.

Contents

  1. Introduction to Air Quality and NO2
  2. Sentinel-5P Data Overview
  3. Setting up Google Earth Engine
  4. Data Filtering and Cloud Masking
  5. Calculating Monthly Averages
  6. Visualizing NO2 Concentrations
  7. Analyzing Spatial Patterns
  8. Using DeepSeek for Code Generation
  9. Exporting Results
  10. Conclusion and Further Exploration
1
Introduction
10 min

Nitrogen dioxide (NO2) is a significant air pollutant affecting human health and the environment. This course will guide you through mapping NO2 concentrations in North Morocco using Sentinel-5P satellite data and leveraging the power of DeepSeek for code generation in Google Earth Engine.

GEE Asset ID
COPERNICUS/S5P/OFFL/L3_NO2
Dataset Name
Sentinel-5P Nitrogen Dioxide
Study Area
North Morocco
AI Tool
DeepSeek (free, no API key needed)
🌍
What you will build: By the end of this course you will have a working GEE script that analyzes Air Quality Mapping with Sentinel-5P NO2 and DeepSeek, computes statistics, visualizes results on an interactive map, and exports data to Google Drive.

2
Setup: GEE + DeepSeek
5 min

You need two browser tabs open side by side throughout this course.

1
Open chat.deepseek.com -- free account, no API key needed
2
Open code.earthengine.google.com in a second tab
3
Create a new GEE script named Course13_Air Quality Mapping with Sentinel-5P NO2 and DeepSeek
💡
Workflow: Write a prompt in DeepSeek describing your task with exact dataset IDs and requirements. Copy the generated GEE JavaScript. Paste into GEE code editor. Click Run. Inspect results. Iterate.

3
Crafting the DeepSeek Prompt
15 min

The prompt is the core skill of this course. A good prompt includes the exact dataset ID, band names, study area coordinates, dates, preprocessing steps, and desired outputs.

📋 Main Prompt -- copy and paste this into DeepSeek
Generate a Google Earth Engine script to visualize monthly average NO2 tropospheric vertical column density (tropospheric_NO2_column_number_density) from the COPERNICUS/S5P/OFFL/L3_NO2 dataset over North Morocco (32N, -6W, 36N, -2W) for the year 2023. Include cloud masking using the QA_value band (threshold > 0.75). Display the results with a color palette ranging from blue to red, showing NO2 values from 0 to 0.0002. Add a legend and map title. Also, calculate and print the mean NO2 value for January 2023.
✨
After pasting the prompt: Wait 20-30 seconds for DeepSeek to generate the full GEE script. Copy the entire code block it produces. If the output is cut short, type "Continue the code" to get the rest.

4
Data Import and Filtering
10 min

Paste the following code into your GEE code editor and click Run. Read the beginner notes below to understand what each line does.

Data Import and Filtering
// Define the region of interest (North Morocco)
var roi = ee.Geometry.Rectangle([-6, 32, -2, 36]);

// Define the date range
var startDate = '2023-01-01';
var endDate = '2023-12-31';

// Import the Sentinel-5P NO2 dataset
var no2 = ee.ImageCollection('COPERNICUS/S5P/OFFL/L3_NO2')
  .filterDate(startDate, endDate)
  .filterBounds(roi);

// Function to mask clouds using the QA_value band
var maskClouds = function(image) {
  var qa = image.select('QA_value');
  var cloudMask = qa.gt(0.75);
  return image.updateMask(cloudMask);
};
🔑
Beginner note: This code block imports the Sentinel-5P NO2 dataset, filters it by date and region of interest (North Morocco), and defines a function to mask out cloudy pixels based on the QA_value band. The QA_value band provides a quality assessment score, and we filter out pixels with a score below 0.75.

5
Monthly Averages and Visualization
10 min

Add this block after the previous code. It continues the analysis with additional processing and visualization.

Monthly Averages and Visualization
// Apply cloud masking to the image collection
var no2Masked = no2.map(maskClouds);

// Function to calculate monthly averages
var monthlyAverages = ee.List.sequence(1, 12).map(function(month) {
  var monthString = ee.String(month).format('%02d');
  var monthlyData = no2Masked.filter(ee.Filter.date('2023-' + monthString + '-01', '2023-' + monthString + '-31'))
    .select('tropospheric_NO2_column_number_density')
    .median();
  return monthlyData.set('month', month);
});

// Convert the list of images to an image collection
var monthlyCollection = ee.ImageCollection.fromImages(monthlyAverages);

// Visualization parameters
var visualization = {
  min: 0,
  max: 0.0002,
  palette: ['blue', 'green', 'yellow', 'red']
};

// Add the January average to the map
var januaryAverage = monthlyCollection.filterMetadata('month', 'equals', 1).first();
Map.addLayer(januaryAverage, visualization, 'January 2023 NO2');
🔑
Beginner note: This code block calculates the monthly average NO2 concentration by filtering the masked image collection for each month, selecting the 'tropospheric_NO2_column_number_density' band, and computing the median value. It then defines visualization parameters and adds the January 2023 average NO2 data to the map.

6
Export Results to Google Drive
5 min

Add this block at the end of your script to export the final map as a GeoTIFF to your Google Drive. After clicking Run, go to the Tasks tab in GEE and click Run next to each export task.

Export to Google Drive
// Export the January 2023 average NO2 concentration to Google Drive
Export.image.toDrive({
  image: januaryAverage,
  description: 'January_2023_NO2',
  folder: 'GEE_Exports',
  region: roi,
  scale: 1000, // 1km resolution
  maxPixels: 1e10
});
🔑
Beginner note -- Export.image.toDrive(): This function does not export immediately. It creates a task in the GEE Tasks tab that you must manually start by clicking Run. The file will appear in your Google Drive folder (GEE_Courses) as a GeoTIFF that you can open in QGIS or ArcGIS.

7
Exercises Using DeepSeek Prompts
Homework

Use DeepSeek to extend the script for each exercise below. Write a follow-up prompt describing what you want to add, then copy the generated code and paste it into your GEE script.

Explore different time periods

  1. Change the start and end dates to analyze NO2 concentrations in different years.
  2. Compare the NO2 levels between different years and seasons.

Modify the visualization parameters

  1. Experiment with different color palettes to enhance the visualization.
  2. Adjust the min and max values to better represent the range of NO2 concentrations.

Analyze NO2 concentrations in specific cities

  1. Define new regions of interest around major cities in North Morocco.
  2. Calculate and compare the average NO2 concentrations in these cities.

Investigate the impact of industrial activity

  1. Identify areas with significant industrial activity in North Morocco.
  2. Analyze the NO2 concentrations in these areas and compare them to surrounding regions.

8
Prompt Engineering Tips
Reference

To get the best results from DeepSeek for GEE tasks, always include these elements in your prompts:

ElementExample
Exact dataset IDCOPERNICUS/S5P/OFFL/L3_NO2
Band names"select band 'B4' for red, 'B8' for NIR"
Study area"rectangle [-6.5, 33.0, -1.5, 36.0] North Morocco"
Date range"filter from 2020-01-01 to 2023-12-31"
Output format"print area in hectares, add a legend, export to Drive"
Error fixing"The code gives error X. Please fix it."
Iteration"Add a time series chart for each year 2018-2023"
🧠
Best practice: Start with the main prompt, run the code, then send follow-up prompts to add features one at a time. This gives you cleaner, more reliable code than asking for everything at once.
Course 13 - Air Quality Mapping with Sentinel-5P NO2 and DeepSeek | GeoAI for Climate Change | Dr. Ayoub Lahlouh | UM6P/CUS | 2025/2026