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 |
|---|---|---|
| Glacier | Glacier | A large body of ice that moves slowly down a slope or valley. |
| Retreat | Glacier Retreat | The shrinking of a glacier due to melting or evaporation. |
| Landsat | Landsat Program | A series of Earth-observing satellite missions jointly managed by NASA and the USGS. |
| Surface Reflectance | Surface Reflectance | The proportion of light reflected from the Earth's surface. |
| NDSI | Normalized Difference Snow Index | An index used to identify snow and ice using spectral reflectance. |
| Threshold | Threshold | A value used to separate different classes or features in an image. |
| GEE | Google Earth Engine | A cloud-based platform for planetary-scale geospatial analysis. |
| AI | Artificial Intelligence | The simulation of human intelligence processes by computer systems. |
| DeepSeek | DeepSeek | A large language model (LLM) that can assist with coding in GEE. |
| Band | Spectral Band | A specific range of wavelengths in the electromagnetic spectrum. |
| Imagery | Satellite Imagery | Images of the Earth's surface captured by satellites. |
| Classification | Image Classification | The process of assigning pixels in an image to different categories or classes. |
| ROI | Region of Interest | A specific area selected for analysis. |
Glacier retreat is a significant indicator of climate change. This course will guide you through mapping glacier retreat in North Morocco using Landsat satellite imagery and the Google Earth Engine platform, enhanced by the AI capabilities of DeepSeek.
LANDSAT/LC08/C01/T1_SRYou need two browser tabs open side by side throughout this course.
Course15_Glacier Retreat Mapping with Landsat 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 (Rif Mountains, Morocco)
var roi = ee.Geometry.Rectangle([-5.0, 34.5, -3.5, 35.5]);
// Function to calculate NDSI
var calculateNDSI = function(image) {
var ndsi = image.normalizedDifference(['B3', 'B6']).rename('NDSI');
return image.addBands(ndsi);
};
// Function to mask clouds using the QA band
var maskL8sr = function(image) {
var cloudShadowBitMask = 1 << 3;
var cloudsBitMask = 1 << 5;
var qa = image.select('pixel_qa');
var mask = qa.bitwiseAnd(cloudShadowBitMask).eq(0)
.and(qa.bitwiseAnd(cloudsBitMask).eq(0));
return image.updateMask(mask).divide(10000); //Scale reflectance
};
Add this block after the previous code. It continues the analysis with additional processing and visualization.
// Load Landsat 8 Surface Reflectance data
var dataset2015 = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR')
.filterDate('2015-01-01', '2015-12-31')
.filterBounds(roi)
.map(maskL8sr)
.map(calculateNDSI);
var dataset2023 = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR')
.filterDate('2023-01-01', '2023-12-31')
.filterBounds(roi)
.map(maskL8sr)
.map(calculateNDSI);
// Define NDSI threshold for glacier classification
var ndsiThreshold = 0.4;
// Classify glaciers based on NDSI threshold
var glaciers2015 = dataset2015.select('NDSI').median().gt(ndsiThreshold).selfMask();
var glaciers2023 = dataset2023.select('NDSI').median().gt(ndsiThreshold).selfMask();
// Visualize glacier extent
Map.centerObject(roi, 10);
Map.addLayer(glaciers2015, {palette: 'blue'}, 'Glaciers 2015');
Map.addLayer(glaciers2023, {palette: 'red'}, 'Glaciers 2023');
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 classified image to Google Drive
Export.image.toDrive({
image: glaciers2023,
description: 'Glacier_Extent_2023',
folder: 'GEE_Exports',
scale: 30,
region: roi,
maxPixels: 1e9
});
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 | LANDSAT/LC08/C01/T1_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" |