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 |
|---|---|---|
| NDWI | Normalized Difference Water Index | A remote sensing index used to detect and monitor changes in water content. |
| Sentinel-2 | Sentinel-2 Mission | An Earth observation mission from the Copernicus Programme that systematically acquires optical imagery at high spatial resolution. |
| Surface Reflectance | Surface Reflectance | The fraction of incoming solar radiation reflected from the Earth's surface. |
| Coastal Erosion | Coastal Erosion | The wearing away and loss of land along the coastline due to natural forces. |
| GEE | Google Earth Engine | A cloud-based platform for planetary-scale geospatial analysis. |
| DeepSeek | DeepSeek LLM | A large language model used for various tasks, including image analysis and interpretation. |
| Band | Spectral Band | A specific range of wavelengths in the electromagnetic spectrum that a sensor is designed to detect. |
| Cloud Masking | Cloud Masking | The process of identifying and removing clouds from satellite imagery. |
| Image Collection | Image Collection | A collection of images organized in Google Earth Engine. |
| Median Composite | Median Composite | A method of combining multiple images to reduce noise and cloud cover by selecting the median pixel value for each location. |
| Classification | Image Classification | The process of assigning pixels in an image to different categories or classes. |
| Feature Extraction | Feature Extraction | The process of identifying and measuring relevant characteristics from an image. |
| GIS | Geographic Information System | A system designed to capture, store, manipulate, analyze, manage, and present spatial or geographic data. |
Coastal erosion is a significant environmental challenge, especially in regions like North Morocco. This course will guide you through using Sentinel-2 satellite imagery and the power of DeepSeek to detect and monitor coastal changes. You'll learn to analyze time series data and develop a workflow for identifying areas at risk of erosion.
COPERNICUS/S2_SRYou need two browser tabs open side by side throughout this course.
Course7_Coastal Erosion Detection 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 the region of interest (North Morocco).
var roi = ee.Geometry.Rectangle([-4.0, 35.0, -3.5, 35.5]);
// Define the date range.
var startDate = '2020-01-01';
var endDate = '2024-01-01';
// 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).clip(roi);
};
// Load Sentinel-2 SR data, filter by region and date, and apply cloud masking.
var collection = ee.ImageCollection('COPERNICUS/S2_SR')
.filterDate(startDate, endDate)
.filterBounds(roi)
.map(maskS2clouds);
Add this block after the previous code. It continues the analysis with additional processing and visualization.
// 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 = collection.map(calculateNDWI);
// Create a median composite of NDWI.
var ndwiMedian = ndwiCollection.median().clip(roi);
// Define visualization parameters.
var ndwiVisParams = {
min: -1,
max: 1,
palette: ['blue', 'white', 'green']
};
// Add the NDWI layer to the map.
Map.addLayer(ndwiMedian, ndwiVisParams, 'NDWI Median');
Map.centerObject(roi, 12);
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 NDWI median composite to Google Drive.
Export.image.toDrive({
image: ndwiMedian,
description: 'NDWI_Median_NorthMorocco',
folder: 'GEE_Exports',
scale: 10, // Sentinel-2 resolution
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" |