Downloading a Sentinel-2 NDVI Time Series
What this dataset is
This page is a hands-on tutorial: in Google Earth Engine (GEE, Google's cloud platform for geospatial data processing) you import the Sentinel-2 dataset, draw your own download area, and then run a piece of JavaScript code that automatically removes clouds, computes NDVI (the Normalized Difference Vegetation Index, a commonly used indicator of vegetation growth) month by month, and batch-exports a full year of NDVI time series to Google Drive.
Coverage and time range
- Coverage: an area drawn by the user in GEE (the ROI in the code)
- Time: the code uses 2020 as the example, exporting the NDVI time series month by month for the whole year
Resolution and specifications
- Export scale: 10 (metres)
- Export coordinate system: EPSG:4326
- Export method: Export.image.toDrive, to Google Drive; the code also sets a cloud filter of CLOUDY_PIXEL_PERCENTAGE less than 12 and removes clouds using the QA60 band
What you can use it for
- Batch-download a full year of monthly NDVI time series for an area of your choice
- Compute NDVI from Sentinel-2 imagery after cloud removal
- Run all export tasks at once with a browser console script, instead of clicking each one
- Import the Sentinel-2 dataset


- Draw the download area

- Modify the drawn area and the dataset name

- Run the code below
javascript
//define ROI
var roi = ee.FeatureCollection(ROI)
//哨兵2去云处理
function s2_rmcloud(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);
}
//在原影像中加入一个新的波段,命名为NDVI
var s2_ndvi = function(image) {
return image.addBands(image.normalizedDifference(["B8", "B4"]).rename("NDVI"));
};
//选择某一年的NDVI时间序列数据集
var Year = '2020';
var DateTime = [Year+'-01-01', Year+'-01-31',Year+'-02-01', Year+'-02-28',Year+'-03-01',Year+'-03-31',
Year+'-04-01', Year+'-04-30',Year+'-05-01', Year+'-05-31',Year+'-06-01', Year+'-06-30',
Year+'-07-01', Year+'-07-31',Year+'-08-01', Year+'-08-31',Year+'-09-01', Year+'-09-30',
Year+'-10-01', Year+'-10-31',Year+'-11-01', Year+'-11-30',Year+'-12-01', Year+'-12-31',];
//print(DateTime);
//定义批量导出函数
function exportImage(imgCol,region,fileName) {
Export.image.toDrive({
image: imgCol,
description: "NDVI",
fileNamePrefix: "ndvi"+fileName,
scale: 10,
region:region,
crs: "EPSG:4326",
maxPixels: 1e13
});
}
//过滤筛选哨兵2影像中NDVI,并导出。
for(var i=0;i<DateTime.length;i+=2){
var s2_nocloud = s2_col.map(s2_rmcloud)
.filterBounds(roi)
.filterDate(DateTime[i], DateTime[i+1])
.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 12));
var ndvi = s2_nocloud.map(s2_ndvi).select("NDVI").reduce(ee.Reducer.mean());
var ndvi_clipped = ndvi.clipToCollection(roi);
exportImage(ndvi_clipped,roi,DateTime[i]);
}
var visParam = {min: 0, max: 1, palette: ['ffffff', '000000']};
Map.centerObject(roi,7);
Map.addLayer(roi,{color:'FFFF00'},"roi");
Map.addLayer(ndvi, visParam, "ndvi",false);
Map.addLayer(ndvi_clipped, visParam, "ndvi_clipped");- When all the export tasks in the run list are displayed, open the browser's console command-line window, copy and paste Teacher Yang's batch run code, press enter, and wait patiently.
javascript
runTasks = function() {
const evt = new MouseEvent('click', {bubbles: true, cancelable: true, ctrlKey: true})
$$('.run-button' ,$$('ee-task-pane')[0].shadowRoot).forEach(function(e) {
e.dispatchEvent(evt)
})
}
runTasks()As shown in the figure:
Import into Google Drive. 
Related datasets
- Harmonized Sentinel-2 MSI: MultiSpectral Instrument, Level-2A (SR)
- GIMMS NDVI From AVHRR Sensors (3rd Generation)
- MODIS Combined 16-Day NDVI [deprecated]
- MOD15A2H.061: Terra Leaf Area Index/FPAR 8-Day Global 500m
Author
