Practical Course 19

Land Degradation Mapping with NDVI Trends and DeepSeek

Learn to map land degradation in North Morocco using NDVI trends and the DeepSeek AI model within Google Earth Engine.
North Morocco ~2 hours Master - Climate Change and GeoAI
Dataset: LANDSAT/LC08/C01/T1_SR Landsat 8 Surface Reflectance

📖 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
NDVINormalized Difference Vegetation IndexA simple graphical indicator that can be used to analyze remote sensing observations, especially from a space platform, and assess whether the target being observed contains live green vegetation.
Land DegradationLand DegradationThe reduction or loss of the biological or economic productivity and complexity of rainfed cropland, irrigated cropland, or range, pasture, forest and woodlands.
GEEGoogle Earth EngineA cloud-based platform for planetary-scale geospatial analysis.
Remote SensingRemote SensingThe acquisition of information about an object or phenomenon without making physical contact with the object.
Time Series AnalysisTime Series AnalysisA statistical method used to analyze data points collected over time to identify trends and patterns.
LandsatLandsat ProgramA series of Earth-observing satellite missions jointly managed by NASA and the USGS.
Surface ReflectanceSurface ReflectanceThe proportion of solar radiation reflected from the Earth's surface after atmospheric correction.
Linear RegressionLinear RegressionA statistical method used to model the relationship between a dependent variable and one or more independent variables by fitting a linear equation to observed data.
Trend AnalysisTrend AnalysisA technique used to identify patterns and changes in data over time.
Rif MountainsRif MountainsA mountain range in northern Morocco.
Middle AtlasMiddle AtlasA mountain range in Morocco, part of the Atlas Mountains system.
DeepSeekDeepSeekA large language model (LLM) that can be used to generate code and analyze data.

Contents

  1. Introduction to Land Degradation
  2. Remote Sensing and NDVI
  3. Google Earth Engine Setup
  4. Data Acquisition and Preprocessing
  5. NDVI Time Series Analysis
  6. Trend Calculation
  7. DeepSeek Integration for Interpretation
  8. Mapping Land Degradation
  9. Validation and Accuracy Assessment
  10. Conclusion and Further Exploration
1
Introduction
10 min

Land degradation poses a significant threat to ecosystems and livelihoods, particularly in regions like North Morocco. This course introduces you to using Google Earth Engine (GEE) for mapping land degradation by analyzing NDVI trends and leveraging the power of the DeepSeek AI model. You will learn to process satellite imagery, calculate NDVI, and interpret trends to identify areas affected by degradation.

GEE Asset ID
LANDSAT/LC08/C01/T1_SR
Dataset Name
Landsat 8 Surface Reflectance
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 Land Degradation Mapping with NDVI Trends 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 Course19_Land Degradation Mapping with NDVI Trends 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
Analyze the NDVI trend map of North Morocco (Rif Mountains and Middle Atlas) from 2015 to 2023, derived from Landsat 8 Surface Reflectance data (LANDSAT/LC08/C01/T1_SR), using the 'NDVI_trend' band. Identify areas with statistically significant negative trends (p < 0.05) indicating land degradation. Provide a summary of the geographical distribution of degraded areas, potential drivers of degradation based on the location (e.g., deforestation, overgrazing, agricultural expansion), and suggest possible mitigation strategies. Output should include specific locations (latitude/longitude coordinates) and estimated area (in hectares) of severely degraded zones. Also, suggest relevant GEE code snippets to extract time series data for specific locations to validate the analysis.
✨
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 NDVI 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 NDVI Calculation
// Define region of interest (North Morocco).
var geometry = ee.Geometry.Rectangle([-6, 32, -2, 35]);

// Function to calculate NDVI.
var addNDVI = function(image) {
  var ndvi = image.normalizedDifference(['B5', 'B4']).rename('NDVI');
  return image.addBands(ndvi);
};

// Load Landsat 8 data and filter by date and location.
var collection = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR')
    .filterDate('2015-01-01', '2023-12-31')
    .filterBounds(geometry)
    .map(addNDVI);

// Function to mask clouds using the pixel_qa band.
var maskClouds = function(image) {
  var qa = image.select('pixel_qa');
  var cloudShadowBitMask = 1 << 3;
  var cloudsBitMask = 1 << 5;
  var mask = qa.bitwiseAnd(cloudShadowBitMask).eq(0)
      .and(qa.bitwiseAnd(cloudsBitMask).eq(0));
  return image.updateMask(mask);
};

collection = collection.map(maskClouds);
🔑
Beginner note: This code block first defines the region of interest and then calculates the NDVI for each Landsat 8 image. It loads the Landsat 8 Surface Reflectance dataset, filters it by date and location, and applies a cloud masking function to improve data quality. The addNDVI function calculates NDVI using the red (B4) and near-infrared (B5) bands. The maskClouds function uses the pixel_qa band to mask out cloudy pixels.

5
NDVI Trend Analysis
10 min

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

NDVI Trend Analysis
// Create a time series of NDVI.
var ndviTimeSeries = collection.select('NDVI').toBands();

// Calculate a linear trend.
var trend = collection.select(['NDVI', 'system:time_start'])
  .reduce(ee.Reducer.linearFit());

// Get the slope of the trend (NDVI change per unit of time).
var slope = trend.select('scale').rename('NDVI_trend');

// Get the p-value of the trend.
var pValue = trend.select('p');

// Mask out insignificant trends (p > 0.05).
var significantTrend = slope.updateMask(pValue.lte(0.05));

// Display the trend.
Map.addLayer(significantTrend, {min: -0.1, max: 0.1, palette: 'red, white, green'}, 'NDVI Trend');
🔑
Beginner note: This code block performs a linear regression analysis on the NDVI time series to calculate the trend. The `ee.Reducer.linearFit()` function calculates the slope and p-value of the trend. The slope represents the NDVI change over time. The p-value indicates the statistical significance of the trend. The code then masks out insignificant trends (p > 0.05) and displays the significant trends on the map, with red indicating decreasing NDVI (degradation) and green indicating increasing NDVI (improvement).

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 NDVI trend image to Google Drive.
Export.image.toDrive({
  image: slope,
  description: 'NDVI_trend_North_Morocco',
  folder: 'GEE_Exports',
  scale: 30,
  region: geometry,
  maxPixels: 1e13
});
🔑
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.

Explore Different Regions

  1. Modify the geometry to analyze land degradation in a different region of Morocco.
  2. Compare the NDVI trends in the new region with the original study area.

Analyze Different Time Periods

  1. Change the date range to analyze NDVI trends over a different time period.
  2. Observe how the trends change with different time periods.

Refine Cloud Masking

  1. Experiment with different cloud masking techniques to improve the accuracy of the analysis.
  2. Compare the results with the original cloud masking method.

Incorporate Precipitation Data

  1. Add precipitation data to the analysis to investigate the relationship between rainfall and NDVI trends.
  2. Use the `ee.ImageCollection('UCSB-CHG/CHIRPS/DAILY')` dataset for precipitation data.

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 19 - Land Degradation Mapping with NDVI Trends and DeepSeek | GeoAI for Climate Change | Dr. Ayoub Lahlouh | UM6P/CUS | 2025/2026