Practical Course 20

Informal Settlement Mapping with Sentinel-2 and DeepSeek

Learn to map informal settlements in North Morocco using Sentinel-2 satellite imagery and the DeepSeek AI model within the Google Earth Engine platform.
North Morocco ~2 hours Master - Climate Change and GeoAI
Dataset: COPERNICUS/S2_SR_HARMONIZED Sentinel-2 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
Informal SettlementInformal SettlementAn area characterized by a lack of formal planning, infrastructure, and security of tenure.
Sentinel-2Sentinel-2A European Space Agency (ESA) Earth observation mission providing high-resolution optical imagery.
Surface ReflectanceSurface ReflectanceThe proportion of solar radiation reflected from the Earth's surface.
GEEGoogle Earth EngineA cloud-based platform for planetary-scale geospatial analysis.
BandSpectral BandA specific range of wavelengths in the electromagnetic spectrum.
NDVINormalized Difference Vegetation IndexA measure of vegetation greenness calculated from red and near-infrared light.
DeepSeekDeepSeek AIAn AI model for image analysis and feature extraction.
ClassificationImage ClassificationThe process of assigning pixels in an image to different categories or classes.
ROIRegion of InterestA specific area selected for analysis.
False Color CompositeFalse Color CompositeA color image created by assigning different bands to red, green, and blue channels.
ThresholdingThresholdingA technique to segment an image by setting a cutoff value.
Cloud MaskingCloud MaskingThe process of removing clouds from satellite imagery.
Spectral SignatureSpectral SignatureThe reflectance or emittance of an object as a function of wavelength.

Contents

  1. Introduction to Informal Settlements
  2. Introduction to Sentinel-2 and GEE
  3. Data Acquisition and Preprocessing
  4. Visualizing Sentinel-2 Imagery
  5. Introduction to DeepSeek AI
  6. Using DeepSeek in GEE
  7. Identifying Informal Settlements with DeepSeek
  8. Post-processing and Accuracy Assessment
  9. Exporting Results
  10. Conclusion and Further Exploration
1
Introduction
10 min

Informal settlements are a growing concern worldwide, particularly in rapidly urbanizing regions. This course will guide you through the process of mapping these settlements in North Morocco using Sentinel-2 satellite imagery and the DeepSeek AI model, all within the Google Earth Engine environment.

GEE Asset ID
COPERNICUS/S2_SR_HARMONIZED
Dataset Name
Sentinel-2 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 Informal Settlement Mapping with Sentinel-2 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 Course20_Informal Settlement Mapping with Sentinel-2 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
Identify and delineate informal settlements using Sentinel-2 imagery from COPERNICUS/S2_SR_HARMONIZED in the Rif Mountains and Middle Atlas regions of North Morocco between 2022-01-01 and 2022-12-31. Use bands B2, B3, B4, B8. Focus on areas with high building density and irregular street patterns. Output a shapefile of polygons representing the boundaries of the identified informal settlements.
✨
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 Preprocessing
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 Preprocessing
// Define the region of interest (North Morocco).
var roi = ee.Geometry.Polygon([[[-5.5, 35], [-3, 35], [-3, 33], [-5.5, 33]]]);

// Define the date range.
var startDate = '2022-01-01';
var endDate = '2022-12-31';

// Load Sentinel-2 SR data.
var s2 = ee.ImageCollection('COPERNICUS/S2_SR_HARMONIZED')
    .filterBounds(roi)
    .filterDate(startDate, endDate)
    .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 20));

// Function to mask clouds using the QA band.
function maskS2clouds(image) {
  var qa = image.select('QA60');
  var cloudBitMask = 1 << 10;
  var cirrusBitMask = 1 << 11;
  var mask = qa.bitwiseAnd(cloudBitMask).eq(0)
      .and(qa.bitwiseAnd(cirrusBitMask).eq(0));
  return image.updateMask(mask).clip(roi);
}

// Apply cloud masking.
var s2_masked = s2.map(maskS2clouds);

// Composite the images.
var s2_composite = s2_masked.median();
🔑
Beginner note: This code block defines the region of interest (North Morocco), date range, and loads Sentinel-2 surface reflectance data. It then applies a cloud masking function using the QA60 band to remove cloudy pixels. Finally, it creates a median composite image from the cloud-masked images. ee.Geometry.Polygon defines the area. ee.ImageCollection loads the Sentinel-2 data. filterBounds, filterDate, and filter are used to refine the dataset. The maskS2clouds function uses the QA band for cloud masking. updateMask applies the mask. median() creates a composite image.

5
NDVI Calculation and Visualization
10 min

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

NDVI Calculation and Visualization
// Calculate NDVI.
var ndvi = s2_composite.normalizedDifference(['B8', 'B4']).rename('NDVI');

// Define visualization parameters.
var s2_vis_params = {
  min: 0,
  max: 3000,
  bands: ['B4', 'B3', 'B2']
};

var ndvi_vis_params = {
  min: -0.2,
  max: 0.8,
  palette: ['blue', 'white', 'green']
};

// Display the composite and NDVI.
Map.centerObject(roi, 10);
Map.addLayer(s2_composite, s2_vis_params, 'Sentinel-2 Composite');
Map.addLayer(ndvi, ndvi_vis_params, 'NDVI');
🔑
Beginner note: This code calculates the Normalized Difference Vegetation Index (NDVI) using the near-infrared (B8) and red (B4) bands. It then defines visualization parameters for both the Sentinel-2 composite and the NDVI. Finally, it adds the layers to the map for visualization. normalizedDifference calculates NDVI. rename renames the band. The vis_params objects define the color ranges. Map.centerObject centers the map. Map.addLayer adds layers to the map display.

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 image to Google Drive.
Export.image.toDrive({
  image: s2_composite,
  description: 'Sentinel2_Composite_NorthMorocco',
  folder: 'GEE_Exports',
  scale: 10,
  region: roi,
  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.

Exploring Different Date Ranges

  1. Change the startDate and endDate variables to explore Sentinel-2 imagery from different years.
  2. Observe how the NDVI changes with different seasons.

Experimenting with Band Combinations

  1. Create a false-color composite using different Sentinel-2 bands (e.g., B11, B8A, B4).
  2. Analyze how different band combinations highlight different features.

Adjusting Cloud Masking

  1. Modify the cloudBitMask and cirrusBitMask values in the maskS2clouds function.
  2. Assess the impact of different masking thresholds on the resulting imagery.

Analyzing NDVI Thresholds

  1. Experiment with different NDVI thresholds to identify areas with varying vegetation density.
  2. Relate the NDVI values to the presence of informal settlements.

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 IDCOPERNICUS/S2_SR_HARMONIZED
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 20 - Informal Settlement Mapping with Sentinel-2 and DeepSeek | GeoAI for Climate Change | Dr. Ayoub Lahlouh | UM6P/CUS | 2025/2026