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 |
|---|---|---|
| Informal Settlement | Informal Settlement | An area characterized by a lack of formal planning, infrastructure, and security of tenure. |
| Sentinel-2 | Sentinel-2 | A European Space Agency (ESA) Earth observation mission providing high-resolution optical imagery. |
| Surface Reflectance | Surface Reflectance | The proportion of solar radiation reflected from the Earth's surface. |
| GEE | Google Earth Engine | A cloud-based platform for planetary-scale geospatial analysis. |
| Band | Spectral Band | A specific range of wavelengths in the electromagnetic spectrum. |
| NDVI | Normalized Difference Vegetation Index | A measure of vegetation greenness calculated from red and near-infrared light. |
| DeepSeek | DeepSeek AI | An AI model for image analysis and feature extraction. |
| 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. |
| False Color Composite | False Color Composite | A color image created by assigning different bands to red, green, and blue channels. |
| Thresholding | Thresholding | A technique to segment an image by setting a cutoff value. |
| Cloud Masking | Cloud Masking | The process of removing clouds from satellite imagery. |
| Spectral Signature | Spectral Signature | The reflectance or emittance of an object as a function of wavelength. |
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.
COPERNICUS/S2_SR_HARMONIZEDYou need two browser tabs open side by side throughout this course.
Course20_Informal Settlement Mapping with Sentinel-2 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 (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();
Add this block after the previous code. It continues the analysis with additional processing 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');
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 image to Google Drive.
Export.image.toDrive({
image: s2_composite,
description: 'Sentinel2_Composite_NorthMorocco',
folder: 'GEE_Exports',
scale: 10,
region: roi,
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 | COPERNICUS/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" |