在Google Earth Engine(GEE)上获取逐日NDVI的代码
时间: 2024-02-06 10:10:04 浏览: 70
以下是使用Google Earth Engine获取逐日NDVI的代码示例:
```javascript
// 设置ROI
var roi = ee.Geometry.Rectangle([xmin, ymin, xmax, ymax]);
// 设置起始和结束日期
var startDate = ee.Date('2019-01-01');
var endDate = ee.Date('2019-12-31');
// 加载MODIS数据
var modis = ee.ImageCollection('MODIS/006/MOD13A1')
.filterBounds(roi)
.filterDate(startDate, endDate)
.select('NDVI');
// 定义函数计算每个图像的年份和日数
var addDate = function(image) {
var doy = image.date().getRelative('day', 'year');
return image.addBands(doy).addBands(image.date().get('year'));
};
// 对图像集应用函数
var modisWithDate = modis.map(addDate);
// 定义函数计算每个年份和日数的平均NDVI值
var reduceDaily = function(imageCollection, year, doy) {
var filtered = imageCollection.filter(ee.Filter.calendarRange(year, year, 'year'))
.filter(ee.Filter.calendarRange(doy, doy, 'day_of_year'));
return filtered.mean().set('year', year).set('doy', doy);
};
// 创建一个二维数组,其中第一维表示年份,第二维表示一年中的日数
var years = ee.List.sequence(startDate.get('year'), endDate.get('year'));
var days = ee.List.sequence(1, 365);
// 对所有年份和日数应用reduceDaily函数
var dailyNDVI = ee.ImageCollection.fromImages(years.map(function(y){
return days.map(function(d){
return reduceDaily(modisWithDate, y, d);
});
}).flatten());
// 打印输出结果
print(dailyNDVI);
```
在上述代码中,首先定义了一个感兴趣区域(ROI),然后加载了2000年至今的MODIS NDVI数据,并对其进行了筛选。接着定义了两个函数,一个函数用于向每个图像添加年份和日数作为带宽,另一个函数用于计算每个年份和日数的平均NDVI值。最后,将所有年份和日数应用到reduceDaily函数中,生成逐日的NDVI值。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![tif](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)