动机
项目需要用到长时间序列的NDVI数据,一般人常用到的是MODIS的月合成产品,而忽略了GIMMS,是因为其空间分辨率低;但是其依然具有其他产品无法比拟的优势,那就是时间序列长。并且SPOT的时间序列也要比MODIS早。参考链接与代码链接在文末尾标注可以查看。
代码
在我看到过一个帖子,也很好,但是他月合成的方式,有点问题,直接把每个月都算成28天去合成。在月尺度和28天尺度上最大值合成。虽然结果差不多吧,但是我心里上还是不能接受;一直使用代码解决问题的思想,让我坚信能用月合成,而不是28天,所以我简单搜了下,找到的解决方案,希望给后面遇到同样苦难的同学提供解决思路。
废话不多说,直接贴代码。
// //显示边界
// 这里构建空的Image,然后通过palette设置边界颜色
var empty = ee.Image().toByte();
var outline = empty.paint({
featureCollection:MBR_HB, // 筛选的colletion
color:0, //颜色透明
width:1 //边界宽度
});
// Map.addLayer(Hulunbuir, {palette: "ff0000"},'Hulunbuir');
Map.addLayer(MBR_HB, {palette: "ff0000"},'MBR_HB');
print(imageCollection);
var years = ee.List.sequence(1981, 2013);
var months = ee.List.sequence(1, 12);
var map_m = function(i) {
i = ee.Number(i);
var filtered_col = years.map(function(j) {
var filtered = imageCollection
.filter(ee.Filter.calendarRange(i, i, 'month'))
.filter(ee.Filter.calendarRange(j, j, 'year'))
.select('ndvi')
.max();
return filtered;
});
return filtered_col;
};
var img_col = ee.ImageCollection(months.map(map_m).flatten());
print(img_col);
// var checkImage = ee.Image(img_col.filter(ee.Filter.eq('system:index', '10')).first());
// print(checkImage);
// Map.addLayer(checkImage, {min:-1,max:1}, 'test');
// var indexs = ee.List.sequence(0, 395);
for(var i=0;i<=3;i++){
var checkImage = ee.Image(img_col.filter(ee.Filter.eq('system:index', String(i))).first()).clip(MBR_HB);
print(checkImage);
Map.addLayer(checkImage, {min:-1,max:1},"ndvi_index_"+i);
Export.image.toDrive({
image: checkImage,
description: "index_"+i,
crs: "EPSG:4326",
// scale: 1000,
region: MBR_HB,
maxPixels: 1e13,
folder: 'Hulunbuir'
});
}
参考的帖子
https://gis.stackexchange.com/questions/279622/writing-code-for-monthly-ndvi-medians-in-google-earth-engine
我的GEE分享链接
https://code.earthengine.google.com/?scriptPath=users%2F1363989042%2FCannabis_Sentinel2%3ANDVI%2FGIMMS_Download