Notebook 2: Google Earth Engine
Cloud-based Earth Observation Data Processing
Session 4 Hands-On Notebook
This notebook accompanies Session 4: Introduction to Google Earth Engine. You will use the Earth Engine Python API to find, cloud-mask, composite and export Sentinel-2 and Sentinel-1 data over the Philippines, and prepare a feature stack for machine learning.
Learning Objectives
By completing this notebook, you will:
- Authenticate and initialise Earth Engine with your own Cloud project
- Use Geometry, Image, ImageCollection, Feature and FeatureCollection objects
- Filter Sentinel-2 and Sentinel-1 collections by place, time and metadata
- Mask clouds with Cloud Score+ and build median composites
- Calculate NDVI and summarise it over an area with reducers
- Export images and sample tables to Google Drive for ML workflows
- Build a multi-sensor feature stack and preview a Random Forest classification
Getting Started
Open in Google Colab (Recommended)
Earth Engine needs a Google Cloud project registered for Earth Engine (free for non-commercial use: education, research, government). Register at https://code.earthengine.google.com/register, note your Project ID, and set it in the first code cell:
ee.Authenticate()
ee.Initialize(project="your-cloud-project")Registration is usually immediate. See also the Setup Guide.
Download Option:
Requirements for local use: pip install earthengine-api geemap (geemap is optional, for interactive maps)
Notebook Contents
- Setup and authentication — Cloud project,
ee.Authenticate(),ee.Initialize(project=...), troubleshooting table - Core concepts — geometries, images and collections, features, filters and reducers
- Sentinel-2 — Puerto Princesa (Palawan) dry-season 2024 collection, Cloud Score+ masking, median composite, true/false colour thumbnails, optional geemap map, NDVI statistics
- Sentinel-1 SAR — IW mode, VV+VH, single orbit direction; temporal mean; VV−VH ratio in dB
- Exports — image to Google Drive in UTM (EPSG:32650), task monitoring, sample points as CSV
- From GEE to ML — optical + NDVI + SAR feature stack;
sampleRegions; Random Forest preview (Day 2 goes deeper) - Best practices — efficiency, quotas, GEE vs local processing, common errors
- Exercises — another place and season; VV vs VH; export your own composite (solutions hidden in each exercise)
Time: about 2 hours.
In Earth Engine the classic QA60 cloud bitmask is empty from 25 January 2022 to 28 February 2024, so QA60-based masks remove every pixel in that period. The notebook uses Google’s Cloud Score+ product (GOOGLE/CLOUD_SCORE_PLUS/V1/S2_HARMONIZED), which also handles cloud shadows. The Sentinel-2 Scene Classification Layer (SCL) is a good alternative (see Session 1).
Prerequisites
- Earth Engine Cloud project registered (see above)
- Completed Notebook 1: Python for Geospatial Data
- Basic Python knowledge and familiarity with Jupyter/Colab
Key Code Pattern
import ee
ee.Initialize(project="your-cloud-project")
aoi = ee.Geometry.Rectangle([118.4, 9.5, 119.0, 10.1]) # Puerto Princesa, Palawan
cs_plus = ee.ImageCollection("GOOGLE/CLOUD_SCORE_PLUS/V1/S2_HARMONIZED")
composite = (ee.ImageCollection("COPERNICUS/S2_SR_HARMONIZED")
.filterBounds(aoi)
.filterDate("2024-01-01", "2024-04-30")
.filter(ee.Filter.lt("CLOUDY_PIXEL_PERCENTAGE", 60))
.linkCollection(cs_plus, ["cs_cdf"])
.map(lambda img: img.updateMask(img.select("cs_cdf").gte(0.6)))
.median()
.clip(aoi))
ndvi = composite.normalizedDifference(["B8", "B4"]).rename("NDVI")Common Errors & Solutions
| Error | Fix |
|---|---|
ee.Initialize: no project found / project not registered |
Pass project= and register the project for Earth Engine |
User memory limit exceeded |
Reduce the area or use a coarser scale; export instead of .getInfo() |
Collection.first: No matching elements |
No images match: check dates, AOI and cloud filter |
Too many concurrent aggregations |
Fewer simultaneous requests; use .limit() while testing |
See the FAQ for more troubleshooting help.
Next Steps
After completing this notebook:
- ✅ Practice with other Philippine regions and seasons
- ✅ Experiment with other datasets (Landsat, ESA WorldCover, Dynamic World)
- ✅ Prepare for Day 2: Machine Learning for Land Cover Classification (Palawan)