Practical Course 8

Snow Cover Dynamics with MODIS and DeepSeek

Learn to analyze snow cover changes in North Morocco using satellite data and AI-powered code generation.
North Morocco ~2 hours Master - Climate Change and GeoAI
Dataset: MODIS/061/MOD10A1 MODIS Daily Snow Cover

📖 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
NDSINormalized Difference Snow IndexAn index used to detect and map snow cover using the reflectance of visible and shortwave infrared light.
MODISModerate Resolution Imaging SpectroradiometerA key instrument aboard the Terra (EOS AM) and Aqua (EOS PM) satellites, viewing the entire Earth's surface every 1 to 2 days.
Snow CoverSnow CoverThe area of land covered by snow.
AlbedoAlbedoThe measure of the reflectivity of a surface.
Time SeriesTime SeriesA sequence of data points, typically consisting of successive measurements made over a time interval.
GEEGoogle Earth EngineA cloud-based platform for planetary-scale geospatial analysis.
BandSpectral BandA specific range of wavelengths in the electromagnetic spectrum.
Image CollectionImage CollectionA stack of images in Google Earth Engine, usually representing a time series.
PixelPixelThe smallest addressable element in an image.
Cloud MaskingCloud MaskingThe process of removing or reducing the effect of clouds in satellite imagery.
ThresholdThresholdA value that separates two categories.
Remote SensingRemote SensingAcquiring information about an object or area from a distance, typically from aircraft or satellites.
Rif MountainsRif MountainsA mountain range in northern Morocco.
Middle AtlasMiddle AtlasA mountain range in Morocco, part of the Atlas Mountains.

Contents

  1. Introduction to Snow Cover Analysis
  2. Understanding MODIS MOD10A1 Data
  3. Setting up Google Earth Engine
  4. Data Filtering and Preprocessing
  5. Visualizing Snow Cover
  6. Calculating Snow Cover Area
  7. Time Series Analysis
  8. Using DeepSeek for Code Generation
  9. Advanced Analysis Techniques
  10. Conclusion and Further Exploration
1
Introduction
10 min

Snow cover is a crucial indicator of climate change and plays a significant role in water resources. This course introduces you to analyzing snow cover dynamics using MODIS data in Google Earth Engine (GEE). We will explore how to process, visualize, and analyze snow cover extent in North Morocco, and leverage AI tools like DeepSeek to generate GEE code.

GEE Asset ID
MODIS/061/MOD10A1
Dataset Name
MODIS Daily Snow Cover
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 Snow Cover Dynamics with MODIS 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 Course8_Snow Cover Dynamics with MODIS 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
Generate Google Earth Engine JavaScript code to: 1) Load the MODIS MOD10A1 dataset ('MODIS/061/MOD10A1') for the years 2020-2023 in North Morocco (Rif Mountains and Middle Atlas). 2) Filter the dataset to include only images from December, January, and February. 3) Calculate the mean NDSI snow cover for each year. 4) Display the annual mean NDSI snow cover as a map. Use the 'NDSI' band. 5) Add a legend to the map.
✨
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
Importing and Filtering MODIS Data
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.

Importing and Filtering MODIS Data
// Define the region of interest (North Morocco).
var geometry = ee.Geometry.Rectangle([-6, 32, -2, 35]);

// Load the MODIS MOD10A1 snow cover dataset.
var snowCover = ee.ImageCollection('MODIS/061/MOD10A1')
  .filterDate('2020-01-01', '2023-12-31')
  .filterBounds(geometry);

// Filter for December, January, and February.
var winterSnow = snowCover.filter(ee.Filter.calendarRange(12, 2, 'month'));

print('MODIS Snow Cover Collection:', winterSnow);
🔑
Beginner note: This code block first defines a region of interest in North Morocco. Then, it loads the MODIS MOD10A1 dataset and filters it to the years 2020-2023 and the specified geometry. Finally, it filters the collection to only include images from December, January, and February using `ee.Filter.calendarRange`. The resulting `winterSnow` collection is printed to the console.

5
Calculating and Visualizing Mean Snow Cover
10 min

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

Calculating and Visualizing Mean Snow Cover
// Calculate the mean NDSI snow cover for each year.
var annualSnow = ee.List.sequence(2020, 2023).map(function(year) {
  var startDate = ee.Date.fromYMD(year, 12, 1);
  var endDate = ee.Date.fromYMD(ee.Number(year).add(1), 2, 28);
  var annualImage = winterSnow.filterDate(startDate, endDate)
    .mean()
    .clip(geometry);
  return annualImage.set('year', year);
});

annualSnow = ee.ImageCollection.fromImages(annualSnow);

// Define visualization parameters.
var snowVisParams = {
  min: 0.0,
  max: 100.0,
  palette: ['00008B', '0000FF', 'ADD8E6', 'FFFFFF']
};

// Display the annual mean NDSI snow cover as a map.
annualSnow.sort('year').iterate(function(image) {
  var year = image.get('year');
  Map.addLayer(image, snowVisParams, 'Mean Snow Cover ' + year);
});
🔑
Beginner note: This code calculates the mean NDSI snow cover for each year (2020-2023) by filtering the `winterSnow` collection for each year and calculating the mean using `.mean()`. The `annualSnow` is then converted to an image collection. A color palette is defined for visualization. Finally, the annual mean snow cover is displayed on the map for each year using `Map.addLayer()`.

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 mean snow cover image to Google Drive.
Export.image.toDrive({
  image: annualSnow.first(),
  description: 'Mean_Snow_Cover_2020',
  folder: 'GEE_Exports',
  scale: 500,
  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.

Exploring Different Years

  1. Modify the code to analyze snow cover from 2015 to 2019.
  2. Compare the snow cover extent to the 2020-2023 period.

Analyzing Specific Regions

  1. Define a smaller region of interest within the Rif Mountains.
  2. Analyze the snow cover changes in that specific area.

Cloud Masking Implementation

  1. Research methods for cloud masking in MODIS data.
  2. Implement a cloud masking technique in your code to improve accuracy.

NDSI Thresholding

  1. Experiment with different NDSI thresholds to identify snow cover.
  2. Evaluate the impact of different thresholds on the accuracy of snow cover mapping.

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 IDMODIS/061/MOD10A1
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 8 - Snow Cover Dynamics with MODIS and DeepSeek | GeoAI for Climate Change | Dr. Ayoub Lahlouh | UM6P/CUS | 2025/2026