Practical Course 15

Glacier Retreat Mapping with Landsat and DeepSeek

Learn to map glacier retreat in North Africa using satellite imagery and the power of AI with Google Earth Engine and DeepSeek.
North Morocco ~2 hours Master - Climate Change and GeoAI
Dataset: LANDSAT/LC08/C01/T1_SR Landsat 8 Surface Reflectance Tier 1

📖 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
GlacierGlacierA large body of ice that moves slowly down a slope or valley.
RetreatGlacier RetreatThe shrinking of a glacier due to melting or evaporation.
LandsatLandsat ProgramA series of Earth-observing satellite missions jointly managed by NASA and the USGS.
Surface ReflectanceSurface ReflectanceThe proportion of light reflected from the Earth's surface.
NDSINormalized Difference Snow IndexAn index used to identify snow and ice using spectral reflectance.
ThresholdThresholdA value used to separate different classes or features in an image.
GEEGoogle Earth EngineA cloud-based platform for planetary-scale geospatial analysis.
AIArtificial IntelligenceThe simulation of human intelligence processes by computer systems.
DeepSeekDeepSeekA large language model (LLM) that can assist with coding in GEE.
BandSpectral BandA specific range of wavelengths in the electromagnetic spectrum.
ImagerySatellite ImageryImages of the Earth's surface captured by satellites.
ClassificationImage ClassificationThe process of assigning pixels in an image to different categories or classes.
ROIRegion of InterestA specific area selected for analysis.

Contents

  1. Introduction to Glacier Retreat
  2. Remote Sensing with Landsat
  3. Introduction to Google Earth Engine
  4. Data Acquisition and Preprocessing
  5. NDSI Calculation
  6. Glacier Mapping and Classification
  7. Using DeepSeek for Code Generation
  8. Accuracy Assessment
  9. Visualization and Export
  10. Conclusion
1
Introduction
10 min

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.

GEE Asset ID
LANDSAT/LC08/C01/T1_SR
Dataset Name
Landsat 8 Surface Reflectance Tier 1
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 Glacier Retreat Mapping with Landsat 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 Course15_Glacier Retreat Mapping with Landsat 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
Write a Google Earth Engine JavaScript code to map glacier extent in the Rif Mountains of Morocco using Landsat 8 Surface Reflectance data (LANDSAT/LC08/C01/T1_SR). Use NDSI to classify glaciers. Filter the data for the years 2015 and 2023. Use bands 'B3' and 'B6' for NDSI calculation. Apply a threshold of 0.4 for NDSI. Visualize the glacier extent in blue. Export the classified images to Google Drive.
✨
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 Acquisition and NDSI Calculation
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 Acquisition and NDSI Calculation
// 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
};
🔑
Beginner note: This code block defines the region of interest, a function to calculate the Normalized Difference Snow Index (NDSI) using Landsat 8 bands B3 (Green) and B6 (SWIR1), and a function to mask clouds using the pixel_qa band. The geometry is a rectangle defining the Rif Mountains. The reflectance values are divided by 10000 to scale them from 0-1.

5
Glacier Mapping and Visualization
10 min

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

Glacier Mapping 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');
🔑
Beginner note: This code block loads Landsat 8 data for 2015 and 2023, filters by date and region, applies cloud masking and NDSI calculation. It then classifies glaciers using an NDSI threshold of 0.4 and visualizes the results on the map. The median NDSI value is used to reduce the effect of outliers.

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 classified image to Google Drive
Export.image.toDrive({
  image: glaciers2023,
  description: 'Glacier_Extent_2023',
  folder: 'GEE_Exports',
  scale: 30,
  region: roi,
  maxPixels: 1e9
});
🔑
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.

Modify the Region of Interest

  1. Change the coordinates of the `roi` variable to focus on a different mountain range in Morocco.
  2. Observe how the mapped glacier extent changes.

Adjust the NDSI Threshold

  1. Modify the `ndsiThreshold` value.
  2. Observe how the mapped glacier extent changes. Experiment with values between 0.2 and 0.6.

Explore Different Years

  1. Change the date ranges for the Landsat 8 data.
  2. Analyze glacier extent over different time periods.

Calculate Glacier Area

  1. Calculate the area (in square kilometers) of the mapped glaciers for each year.
  2. Compare the area changes over time.

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 IDLANDSAT/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"
🧠
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 15 - Glacier Retreat Mapping with Landsat and DeepSeek | GeoAI for Climate Change | Dr. Ayoub Lahlouh | UM6P/CUS | 2025/2026