Before starting, make sure you understand these terms. They appear throughout all code blocks in this course.
| Term | Full Name | What it means in simple words |
|---|---|---|
| NO2 | Nitrogen Dioxide | A harmful air pollutant produced by combustion processes. |
| Sentinel-5P | Sentinel-5 Precursor | A European Space Agency mission for monitoring air pollution. |
| TROPOMI | Tropospheric Monitoring Instrument | The main instrument on Sentinel-5P, measuring atmospheric composition. |
| QA_value | Quality Assurance Value | A measure of the quality and reliability of the satellite data. |
| GEE | Google Earth Engine | A cloud-based platform for geospatial analysis. |
| Image Collection | Image Collection | A series of images in GEE, typically from the same sensor. |
| Image | Image | A single raster dataset in GEE. |
| Band | Band | A single layer of data within an image. |
| Median | Median | The middle value in a set of numbers, used for reducing noise. |
| Cloud Masking | Cloud Masking | The process of removing or reducing the effect of clouds in satellite imagery. |
| Visualization | Visualization | The process of displaying data in a graphical format. |
| DeepSeek | DeepSeek Coder | An AI coding assistant for generating code. |
| AI | Artificial Intelligence | Computer systems that can perform tasks that normally require human intelligence. |
| Rif Mountains | Rif Mountains | A mountain range in northern Morocco. |
| Middle Atlas | Middle Atlas | A mountain range in central Morocco. |
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.
COPERNICUS/S5P/OFFL/L3_NO2You need two browser tabs open side by side throughout this course.
Course13_Air Quality Mapping with Sentinel-5P NO2 and DeepSeek
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.
Paste the following code into your GEE code editor and click Run. Read the beginner notes below to understand what each line does.
// 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);
};
Add this block after the previous code. It continues the analysis with additional processing 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');
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 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
});
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.
To get the best results from DeepSeek for GEE tasks, always include these elements in your prompts:
| Element | Example |
|---|---|
| Exact dataset ID | COPERNICUS/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" |