今天带来的有关蒸散发数据的下载代码,蒸散发数据在气象气候,农业干旱监测等领域应用广泛,那么在GEE上如何方便快捷获取蒸散发数据呢?今天跟着小编分享代码,快来学习吧!!
A.定义研究区域
//定义研究区域
var geometry = ee.FeatureCollection('users/hesuixinya511/ganzhou');
//聚焦研究区域
Map.centerObject(geometry,6);
这里小编以赣州市作为研究区域。
B.影像调用与数据筛选
//加载MODIS蒸发量数据,按照2001-2020年赣州市的研究区域范围完成数据筛选和裁剪
var collection = ee.ImageCollection('MODIS/006/MOD16A2').filter(ee.Filter.date('2001-01-01', '2023-12-31')).filterBounds(geometry).select('ET');//选择PET(潜在蒸发量)波段数据
小编选择的是MODIS的数据产品,为MOD16A2,该数据产品提供ET、PET等近20年的数据,以下显示的是该数据的波段信息,我们挑了ET即总的蒸散发作为例子:
C.年度蒸发量数据合成
//合成年总蒸发量数据
var years = ee.List.sequence(2001, 2023);
var collectYear = ee.ImageCollection(years.map(function(y) {var start = ee.Date.fromYMD(y, 1, 1);var end = start.advance(12, 'month');return collection.filterDate(start, end).reduce(ee.Reducer.sum()).float().set('system:time_start',y).set('year',y);
}));
print(collectYear);
D.影像批量裁剪
//利用赣州市的行政边界裁剪蒸散发数据
var clip_Collection=collectYear.map(function(img){return img.clip(geometry);
});
print(clip_Collection);
E.影像的可视化
var palettes = require('users/gena/packages:palettes');
var evapotranspirationVis = {min: 0,max: 300,palette: palettes.colorbrewer.RdYlBu[11]
};
Map.addLayer(clip_Collection.median(), evapotranspirationVis, 'Evapotranspiration');
F.年度时间序列展示
//时间序列展示
var Yearly_Chart = ui.Chart = ui.Chart.image.series({imageCollection:clip_Collection.select("ET_sum"),region:geometry,reducer:ee.Reducer.mean(),scale:500,xProperty:"year",
}).setOptions({interpolateNulls:true,lineWidth:2,pontSize:3,title:"PET Yearly Series",vAxis:{title:"PET"},hAxis:{title:"Date"},trendlines:{0:{title:"PET_trend",type:"linear",showR2:true,color:"red",visibleInLegend:true}}
});
print(Yearly_Chart);
G.影像批量下载
//定义下载影像函数
function exportImage(image, region, fileName) { Export.image.toDrive({ image: image, description: "Drive-"+fileName,//影像名称 fileNamePrefix: fileName, folder: "GanzhouET", //文件夹名称 scale: 500, region: region, maxPixels: 1e13, crs: "EPSG:4326" });
}
//生成时间序列按照循环迭代下载数据集的每一张影像
var indexList = clip_Collection.reduceColumns(ee.Reducer.toList(), ["system:index"]).get("list");
print("indexList", indexList);
indexList.evaluate(function(indexs) { for (var i=0; i<indexs.length; i++) { var image = clip_Collection.filter(ee.Filter.eq("system:index", indexs[i])).first(); exportImage(image, geometry, "20"+indexs[i+1]); }
});
H.导出为CSV格式
//导出为CSV格式
var table = ee.FeatureCollection(clip_Collection.map(function(image){var date = image.get("year");return ee.Feature(null,{"date":date,"value":image.reduceRegion(ee.Reducer.mean(),geometry,500).get("ET_sum")});
}));
Export.table.toDrive({collection:table,description:"Yearly_series",folder:"ET",fileNamePrefix:"ET_Year",fileFormat:"CSV"
});
I.本篇案例完整代码
//定义研究区域
var geometry = ee.FeatureCollection('users/hesuixinya511/ganzhou');
//聚焦研究区域
Map.centerObject(geometry,6);
//加载MODIS蒸发量数据,按照2001-2020年赣州市的研究区域范围完成数据筛选和裁剪
var collection = ee.ImageCollection('MODIS/006/MOD16A2').filter(ee.Filter.date('2001-01-01', '2023-12-31')).filterBounds(geometry).select('ET');//选择PET(潜在蒸发量)波段数据
//合成年总蒸发量数据
var years = ee.List.sequence(2001, 2023);
var collectYear = ee.ImageCollection(years.map(function(y) {var start = ee.Date.fromYMD(y, 1, 1);var end = start.advance(12, 'month');return collection.filterDate(start, end).reduce(ee.Reducer.sum()).float().set('system:time_start',y).set('year',y);
}));
print(collectYear);
//利用赣州市的行政边界裁剪蒸散发数据
var clip_Collection=collectYear.map(function(img){return img.clip(geometry);
});
print(clip_Collection);
var palettes = require('users/gena/packages:palettes');
var evapotranspirationVis = {min: 0,max: 300,palette: palettes.colorbrewer.RdYlBu[11]
};
Map.addLayer(clip_Collection.median(), evapotranspirationVis, 'Evapotranspiration');
//时间序列展示
var Yearly_Chart = ui.Chart = ui.Chart.image.series({imageCollection:clip_Collection.select("ET_sum"),region:geometry,reducer:ee.Reducer.mean(),scale:500,xProperty:"year",
}).setOptions({interpolateNulls:true,lineWidth:2,pontSize:3,title:"PET Yearly Series",vAxis:{title:"PET"},hAxis:{title:"Date"},trendlines:{0:{title:"PET_trend",type:"linear",showR2:true,color:"red",visibleInLegend:true}}
});
print(Yearly_Chart);
//定义下载影像函数
function exportImage(image, region, fileName) { Export.image.toDrive({ image: image, description: "Drive-"+fileName,//影像名称 fileNamePrefix: fileName, folder: "GanzhouET", //文件夹名称 scale: 500, region: region, maxPixels: 1e13, crs: "EPSG:4326" });
}
//生成时间序列按照循环迭代下载数据集的每一张影像
var indexList = clip_Collection.reduceColumns(ee.Reducer.toList(), ["system:index"]).get("list");
print("indexList", indexList);
indexList.evaluate(function(indexs) { for (var i=0; i<indexs.length; i++) { var image = clip_Collection.filter(ee.Filter.eq("system:index", indexs[i])).first(); exportImage(image, geometry, "20"+indexs[i+1]); }
});
//导出为CSV格式
var table = ee.FeatureCollection(clip_Collection.map(function(image){var date = image.get("year");return ee.Feature(null,{"date":date,"value":image.reduceRegion(ee.Reducer.mean(),geometry,500).get("ET_sum")});
}));
Export.table.toDrive({collection:table,description:"Yearly_series",folder:"ET",fileNamePrefix:"ET_Year",fileFormat:"CSV"
});
关于GEE下载蒸散发数据的代码到这里就结束了,如果对你有帮助,不要忘记了给小编点赞哦!
代码链接:https://code.earthengine.google.com/c1c7de2ae0a8a4992f4fe1051b71ec98
谢谢大家!!下期再见!!