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 |
|---|---|---|
| SAR | Synthetic Aperture Radar | A type of radar that creates two-dimensional images or three-dimensional reconstructions of objects, such as landscapes. |
| GRD | Ground Range Detected | Sentinel-1 data that has been processed to represent the radar signal strength on the ground. |
| VV | Vertical-Vertical Polarization | The radar signal is transmitted and received vertically. |
| VH | Vertical-Horizontal Polarization | The radar signal is transmitted vertically and received horizontally. |
| Soil Moisture | Soil Moisture | The amount of water present in the soil. |
| Backscatter | Radar Backscatter | The amount of the radar signal that is reflected back to the sensor. |
| Sentinel-1 | Sentinel-1 | A European radar imaging satellite. |
| GEE | Google Earth Engine | A cloud-based platform for geospatial analysis. |
| Speckle | Speckle Noise | Granular noise inherent in SAR images. |
| DeepSeek | DeepSeek | A large language model used to generate code. |
| Filtering | Image Filtering | Process of removing noise or unwanted features from an image. |
| Incidence Angle | Incidence Angle | The angle at which the radar beam hits the Earth's surface. |
Soil moisture is a critical component of the Earth's climate system, influencing weather patterns, agriculture, and ecosystem health. This course will guide you through using Sentinel-1 SAR data in Google Earth Engine (GEE) to estimate soil moisture in North Morocco, leveraging the power of DeepSeek for code generation.
COPERNICUS/S1_GRDYou need two browser tabs open side by side throughout this course.
Course16_Soil Moisture from Space
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.0], [-2.0, 35.0], [-2.0, 32.0], [-5.5, 32.0]]]);
// Define the date range
var startDate = '2023-01-01';
var endDate = '2023-12-31';
// Load Sentinel-1 GRD data
var sentinel1 = ee.ImageCollection('COPERNICUS/S1_GRD')
.filter(ee.Filter.eq('instrumentMode', 'IW'))
.filter(ee.Filter.listContains('transmitterReceiverPolarisation', 'VV'))
.filter(ee.Filter.listContains('transmitterReceiverPolarisation', 'VH'))
.filter(ee.Filter.eq('orbitProperties_pass', 'DESCENDING'))
.filter(ee.Filter.date(startDate, endDate))
.filterBounds(roi);
//Print the number of images
print('Number of Sentinel-1 images:', sentinel1.size());
Add this block after the previous code. It continues the analysis with additional processing and visualization.
// Function to apply a simple speckle filter (e.g., median filter)
var speckleFilter = function(image) {
var vv = image.select('VV');
var vvFiltered = vv.focal_median();
return image.addBands(vvFiltered.rename('VV_filtered')).copyProperties(image, ['system:time_start']);
};
// Apply speckle filtering to the Sentinel-1 data
var sentinel1Filtered = sentinel1.map(speckleFilter);
// Function to calculate Normalized Difference Soil Moisture Index (NDMI)
var calculateNDMI = function(image) {
var vv = image.select('VV_filtered');
var vh = image.select('VH');
var ndmi = vv.subtract(vh).divide(vv.add(vh)).rename('NDMI');
return image.addBands(ndmi).copyProperties(image, ['system:time_start']);
};
// Calculate NDMI
var sentinel1NDMI = sentinel1Filtered.map(calculateNDMI);
//Composite the images into one image
var composite = sentinel1NDMI.median();
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 NDMI image to Google Drive
Export.image.toDrive({
image: composite.select('NDMI'),
description: 'Sentinel1_NDMI_Morocco',
folder: 'GEE_Exports',
scale: 10,
region: roi,
maxPixels: 1e10
});
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/S1_GRD |
| 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" |