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 |
|---|---|---|
| Turbidity | Turbidity | A measure of water cloudiness caused by suspended particles. |
| Chlorophyll-a | Chlorophyll-a | A pigment found in plants and algae, used as an indicator of phytoplankton biomass. |
| NDWI | Normalized Difference Water Index | An index used to identify water bodies. |
| Eutrophication | Eutrophication | Excessive richness of nutrients in a lake or other body of water, frequently due to runoff from the land, which causes a dense growth of plant life and death of animal life from lack of oxygen. |
| Reflectance | Reflectance | The proportion of incident light or radiation that is reflected by a surface. |
| Sentinel-2 | Sentinel-2 | An Earth observation mission from the Copernicus Programme that systematically acquires optical imagery at high spatial resolution. |
| GEE | Google Earth Engine | A cloud-based platform for planetary-scale geospatial analysis. |
| AI | Artificial Intelligence | The theory and development of computer systems able to perform tasks that normally require human intelligence. |
| Deep Learning | Deep Learning | A type of machine learning based on artificial neural networks with multiple layers. |
| Water Quality Index | Water Quality Index | A single number that represents the overall water quality at a certain location and time, based on several water quality parameters. |
| Remote Sensing | Remote Sensing | The science of obtaining information about an object or area from a distance, typically from aircraft or satellites. |
| Spectral Bands | Spectral Bands | Specific ranges of wavelengths in the electromagnetic spectrum that are used to collect data in remote sensing. |
Water quality is crucial for human health and ecosystem well-being. This course introduces the use of Sentinel-2 satellite imagery and the DeepSeek AI model within Google Earth Engine to monitor water quality in North Morocco. You will learn to process satellite data, calculate water indices, and leverage AI for parameter estimation.
COPERNICUS/S2_SRYou need two browser tabs open side by side throughout this course.
Course11_Water Quality Monitoring with Sentinel-2 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 region of interest (Rif Mountains and Middle Atlas, Morocco)
var roi = ee.Geometry.Rectangle([-5.5, 34, -3.5, 35]);
// Filter Sentinel-2 SR data for the specified period and region
var dataset = ee.ImageCollection('COPERNICUS/S2_SR')
.filterDate('2023-06-01', '2023-09-30')
.filterBounds(roi)
.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 20));
// Print the number of images found
print('Number of Sentinel-2 images:', dataset.size());
// Function to mask clouds using the QA60 band
var maskS2clouds = function(image) {
var qa = image.select('QA60');
// Bits 10 and 11 are clouds and cirrus, respectively.
var cloudBitMask = 1 << 10;
var cirrusBitMask = 1 << 11;
// Both flags should be set to zero, indicating clear conditions.
var mask = qa.bitwiseAnd(cloudBitMask).eq(0)
.and(qa.bitwiseAnd(cirrusBitMask).eq(0));
return image.updateMask(mask).divide(10000);
};
Add this block after the previous code. It continues the analysis with additional processing and visualization.
// Apply cloud masking
var maskedDataset = dataset.map(maskS2clouds);
// Function to calculate NDWI
var calculateNDWI = function(image) {
return image.normalizedDifference(['B3', 'B8']).rename('NDWI');
};
// Calculate NDWI for each image in the collection
var ndwiCollection = maskedDataset.map(calculateNDWI);
// Create a composite image (median NDWI over the time period)
var ndwiComposite = ndwiCollection.median();
// Visualization parameters for NDWI
var ndwiVisParams = {
min: -1,
max: 1,
palette: ['red', 'white', 'blue']
};
// Add the NDWI composite to the map
Map.addLayer(ndwiComposite, ndwiVisParams, 'NDWI Composite');
// Center the map on the region of interest
Map.centerObject(roi, 9);
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 Chlorophyll-a estimation to Google Drive
Export.image.toDrive({
image: /* Chlorophyll-a image from DeepSeek result */,
description: 'Chlorophyll_a_Estimation',
folder: 'GEE_Exports',
scale: 10, // Adjust scale as needed
region: roi,
maxPixels: 1e13
});
// Export the Turbidity estimation to Google Drive
Export.image.toDrive({
image: /* Turbidity image from DeepSeek result */,
description: 'Turbidity_Estimation',
folder: 'GEE_Exports',
scale: 10, // Adjust scale as needed
region: roi,
maxPixels: 1e13
});
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/S2_SR |
| 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" |