我想计算每个区域(管理级别 3,也称为 Wearda)、月份和年份的平均 NDVI。所以我的最终结果看起来像这样:
regions year month NDVI
---------------------------------
region_1 2010 1 0.5
region_1 2010 2 -0.6
region_1 2010 3 0.7
region_1 2010 4 -0.3
region_1 2010 5 0.4
region_1 2010 6 -0.5
region_1 2010 7 0.5
region_1 2010 8 -0.7
region_1 2010 9 0.8
region_1 2010 10 -0.55
region_1 2010 11 -0.3
region_1 2010 12 -0.2
region_2 2010 1 0.5
region_2 2010 2 -0.6
region_2 2010 3 0.7
region_2 2010 4 -0.3
region_2 2010 5 0.4
region_2 2010 6 -0.5
region_2 2010 7 0.5
region_2 2010 8 -0.7
region_2 2010 9 0.8
region_2 2010 10 -0.55
region_2 2010 11 -0.3
region_2 2010 12 -0.2
... ... ... ...
我的代码基本上是针对 var modisNDVI 中的预定区域执行此操作。不过,我希望我的代码能够在 2010 年到 2015 年每个地区的每个月执行此操作。
我怎样才能做到这一点而不编写更多的 for 循环(迭代年和月)?
我应该使用 reduceRegion 或 .map() 来跳过(所有)for 循环吗?
我尝试过使用reduceRegions但未能将其应用于图像集合。
// import data
var region = ee.FeatureCollection("ft:1zRUOJL1LYCPJj-mjP6ZRx8sxYKNH8EwDw3EPP66K"),
modisNDVI = ee.ImageCollection("MODIS/MCD43A4_006_NDVI");
// Get NDVI
var modisNDVI = ee.ImageCollection(modisNDVI.filterDate('2015-01-01', '2015-06-01'));
var woredaNames = region.aggregate_array("HRpcode")
// do something so I can get monthly data for each year (2010-2015) for earch woreda (690)
// I don't want to write another for loop for the year and month what is a more optimized way?
// Processing all the 690 takes long, for this example I've used 10 woreda's
for (var woreda=0; woreda < 10 ;woreda++){
// Focus on one region:
var focusRegion = region.filter(ee.Filter.eq('system:index', String(woreda)));
// Clip modis image on focused region:
var focus_NDVI_clip = modisNDVI.mean().clip(focusRegion);
// aggregate mean over geometry from focused region:
var mean_dict = focus_NDVI_clip.reduceRegion({
reducer: ee.Reducer.mean(),
geometry: focusRegion.geometry(),
scale: 500,
});
// Append index to mean_dictionary and print it (eventually this should turn into a list):
var woreda_code = ee.List(woredaNames).get(woreda);
mean_dict = mean_dict.set('Woreda_code', ee.String(woreda_code));
print(mean_dict);}