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 |
|---|---|---|
| NDVI | Normalized Difference Vegetation Index | A 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 Degradation | Land Degradation | The reduction or loss of the biological or economic productivity and complexity of rainfed cropland, irrigated cropland, or range, pasture, forest and woodlands. |
| GEE | Google Earth Engine | A cloud-based platform for planetary-scale geospatial analysis. |
| Remote Sensing | Remote Sensing | The acquisition of information about an object or phenomenon without making physical contact with the object. |
| Time Series Analysis | Time Series Analysis | A statistical method used to analyze data points collected over time to identify trends and patterns. |
| Landsat | Landsat Program | A series of Earth-observing satellite missions jointly managed by NASA and the USGS. |
| Surface Reflectance | Surface Reflectance | The proportion of solar radiation reflected from the Earth's surface after atmospheric correction. |
| Linear Regression | Linear Regression | A 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 Analysis | Trend Analysis | A technique used to identify patterns and changes in data over time. |
| Rif Mountains | Rif Mountains | A mountain range in northern Morocco. |
| Middle Atlas | Middle Atlas | A mountain range in Morocco, part of the Atlas Mountains system. |
| DeepSeek | DeepSeek | A large language model (LLM) that can be used to generate code and analyze data. |
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.
LANDSAT/LC08/C01/T1_SRYou need two browser tabs open side by side throughout this course.
Course19_Land Degradation Mapping with NDVI Trends 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 (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);
Add this block after the previous code. It continues the analysis with additional processing and visualization.
// 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');
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 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
});
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" |