Google Earth Engine Tutorial: Beginners Guide 29 Extract Monthly LST to CSV
Credit: Youtube Channel “Terra Spatial, Tutorial on extracting monthly Land Surface Temperature values from MODIS data and exporting to CSV.”
You can see all the tutorials from here: Techgeo Academy.
Google Earth Engine Tutorial: Beginners Guide 29 Extract Monthly LST to CSV using Google Earth Engine
Introduction to Monthly Land Surface Temperature (LST) Extraction
Extracting monthly Land Surface Temperature (LST) data from Google Earth Engine (GEE) and exporting it to a CSV file is a powerful way to analyze climate patterns over time. This guide will walk you through the process step-by-step using JavaScript API in GEE.
Step 1: Set Up Your Google Earth Engine Account
Before you begin, ensure you have a Google account and access to the Google Earth Engine platform. Install and authenticate the Earth Engine API in your environment using the command:
earthengine authenticate
Step 2: Load the LST Dataset
Google Earth Engine offers several LST datasets. For this example, we’ll use the MODIS Terra Land Surface Temperature product (MCD11A1).
var lstCollection = ee.ImageCollection('MODIS/006/MCD11A1');
This dataset provides daily LST measurements. Filter the collection to include only the temperature bands (e.g., “LST_Day_1km” and “LST_Night_1km”).
Step 3: Define the Time Range and Region of Interest
Select a specific date range and define the area you want to analyze. For example:
var startDate = '2020-01-01';
var endDate = '2020-12-31';
var roi = ee.FeatureCollection('FAO/GAUL/2015/level0').filter(ee.Filter.eq('ADM0_NAME', 'Brazil'));
This example filters data for Brazil. Modify the ROI as needed.
Step 4: Filter Data by Date and Compute Monthly Means
Use filterDate
to narrow the dataset and compute monthly averages:
var filtered = lstCollection.filterDate(startDate, endDate);
var monthlyLST = filtered.select('LST_Day_1km').filter(ee.Filter.calendarRange(1,12,'month')).map(function(image) {
return image.copyProperties(image, ['system:time_start']);
});
Calculate the mean LST for each month:
var monthlyMean = monthlyLST.map(function(image) {
return image.reduce(ee.Reducer.mean()).copyProperties(image, ['system:time_start']);
}).select('LST_Day_1km_mean');
Step 5: Export Monthly LST to CSV
Export the results to a CSV file using the
Export.table.toDrive
function:Export.table.toDrive({
collection: monthlyMean.select(['system:time_start', 'LST_Day_1km_mean']),
description: 'Monthly_LST_Brazil',
folder: 'GEE_Exports',
fileNamePrefix: 'monthly_lst',
fileFormat: 'CSV'
});
Run this code in the GEE Code Editor. The CSV file will be saved in your Google Drive under the specified folder.
FAQ
Why is my CSV file empty?
Ensure the dataset contains valid data for the specified time range and region. Check if the ROI is correctly defined and the LST bands are selected properly.
Can I use a different LST dataset?
Yes, replace
'MODIS/006/MCD11A1'
with another dataset (e.g.,'NASA/GLDAS/V21'
) and adjust the band names accordingly.How to handle missing data in the CSV?
Use the
mask
function to exclude pixels with no data. Modify the code to add.mask()
before exporting.Why does the export take so long?
Large regions or long time ranges may require more processing time. You can reduce the resolution or simplify the ROI to speed up the export.
What time format does GEE use for the CSV?
The
system:time_start
property in GEE is in milliseconds. Convert it to a readable date format using theformat
function in the code:image.set('date', image.get('system:time_start').format('YYYY-MM-DD'));
Then include the date column in the exported CSV.
Can I export data for multiple regions at once?
Yes, use a FeatureCollection for your ROIs and iterate over them with
map()
oraggregate
functions to generate separate CSV files or merge them into a single dataset.