使用 Google Earth Engine 计算每个地区、月份和年份的 NDVI?

2023-12-19

我想计算每个区域(管理级别 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);}

首先,您应该不惜一切代价避免在 Earth Engine 上使用 for 循环,它只会使系统陷入困境,并且对每个人都不利(请参阅本节的循环部分)page https://developers.google.com/earth-engine/client_server)。您可以使用嵌套映射 https://stackoverflow.com/questions/47102922/double-loop-with-map-function-in-google-earth-engine循环遍历特征集合,然后遍历所有时间段以提取您需要的信息:

// import data
var region = ee.FeatureCollection("ft:1zRUOJL1LYCPJj-mjP6ZRx8sxYKNH8EwDw3EPP66K"),
modisNDVI = ee.ImageCollection("MODIS/MCD43A4_006_NDVI");

var startDate = ee.Date('2010-01-01'); // set analysis start time
var endDate = ee.Date('2010-12-31'); // set analysis end time

// calculate the number of months to process
var nMonths = ee.Number(endDate.difference(startDate,'month')).round();

var result = region.map(function(feature){
  // map over each month
  var timeDict = ee.List.sequence(0,nMonths).map(function (n){
    // calculate the offset from startDate
    var ini = startDate.advance(n,'month');
    // advance just one month
    var end = ini.advance(1,'month');
    // filter and reduce
    var data = modisNDVI.filterDate(ini,end).mean().reduceRegion({
      reducer: ee.Reducer.mean(),
      geometry: feature.geometry(),
      scale: 1000
    });
    // return zonal mean with a time key
    return data.combine(ee.Dictionary({'time':ini}));
  });
  // return feature with a timeseries property and results
  return feature.set('timeseries',timeDict);
});

// print to see if it is doing what we expect...
print(result.select(["HRpcode",'timeseries']));

// Export the data to a table for further analysis
Export.table.toDrive({
  collection:result,
  description:"tester",
  fileFormat:"CSV",
  selectors:["HRpcode","timeseries"]
})

代码链接:https://code.earthengine.google.com/abf5eeb5c203310c11bf45c6714ae731 https://code.earthengine.google.com/abf5eeb5c203310c11bf45c6714ae731

在这个实现中,结果格式可能有点奇怪,结果是一个以字典作为属性的特征集合,而不是数组或表......但是,希望这可以为您提供您需要的东西,或者为您提供一种获得您想要的东西的方法。需要。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 Google Earth Engine 计算每个地区、月份和年份的 NDVI? 的相关文章

随机推荐

  • 如何确保文本框是字母数字但没有前导数字?

    我的 Web 应用程序包含一个文本框 我想限制其输入 我想阻止用户输入以下文本 以空白开头 以数字以外的内容开头 在前导字符之后包含字母数字字符 谢谢你的建议 不要以字母数字的空格开头 a zA Z 后跟 0 个或多个字母数字 a zA Z
  • Python中浮点数的分数[重复]

    这个问题在这里已经有答案了 当数字作为浮点数传递时 为什么分数的分子和分母更大 gt gt gt from fractions import Fraction gt gt gt gt gt gt a Fraction 2 34 gt gt
  • Javascript:识别是桌面Linux还是Android

    无法识别是linux桌面机还是android设备使用navigator userAgent or navigator platform因为某些 Android 设备有字符串linux同时 详情如下 Device OS navigator p
  • 启动 python 进行 Web 开发的好资源吗?

    我对学习 Python 进行 Web 开发非常感兴趣 有人能指出我正确的方向吗 我一直在 Google 上查看相关内容 但还没有真正找到任何显示正确文档以及如何开始使用的内容 有推荐的框架吗 教程 我从事 PHP 工作已有 5 年了 所以我
  • 获取复选按钮状态

    我如何获得 state of a Tkinter Checkbutton By state 我的意思是看看它是否有复选标记 当你创建它时 需要一个variable关键字参数 通过它IntVar from Tkinter 选中或取消选中该框将
  • 如何将 Kotlin 支持添加到您的 flutter 项目中?

    阅读后README文件的条形码扫描插件 https pub dev packages barcode scan我遇到了指令 这个插件是用 Kotlin 编写的 因此 需要添加Kotlin 支持您的项目 请参阅安装 Kotlin 插件 htt
  • 如何在Windows上正确使用CMAKE_MODULE_PATH

    修改此变量以便 CMake 可以找到项目指定为需求的适当模块的正确方法是什么 它似乎是自动生成的 我找不到可以以任何方式修改此路径的环境变量 我也很难找到能很好解释这一点的文档 只有 安装 CMake 包的说明 没有具体说明如何完成此操作的
  • ng-repeat 仅显示最后一个元素

    我正在使用 AngularJs 开发消息收件箱 我遇到了一个问题 我想仅显示其中的最后一个元素ng repeat 我做了一些研究 发现下面的代码应该可以工作 div class inbox ul div span recipient id
  • Flutter 将 Draggable Scrollbar 添加到 CustomScrollView?它一直给我“参数类型 CustomScrollView 无法分配给 BoxScrollView”

    一个简单的例子是 Scaffold floatingActionButton fab floatingActionButtonLocation fabLocation body Scrollbar child CustomScrollVie
  • 并发/待办事项示例不起作用

    我正在尝试 ToDo 示例 并在尝试并发处理时遇到了未处理的异常 dataservice js 包含这些行saveFailed error method if detail detail ExceptionType indexOf Opti
  • 该证书的颁发者无效 Apple Push Services

    我已创建证书以在我的应用程序中启用推送服务 但每次我尝试在钥匙串中添加证书时 添加证书后都会显示以下错误 该证书的颁发者无效 我想我已经弄清楚了这一点 我导入了新的 WWDR 证书将于 2023 年到期 https developer ap
  • Codeigniter 中国家/地区和城市的 Ajax 下拉菜单?

    我正在我们的 Codeigniter 框架中借助 ajax 使国家和城市下降 数据库的结构如下所示 Country country id country name State country id state id state name c
  • 如何在 Chrome 扩展中使用 google 创建登录信息

    我最近刚刚构建了一个插件 需要在其中集成 Google Login 我搜索并发现chrome identity使用谷歌帐户对用户进行身份验证 但这效果不佳 所以我通过使用下面的代码找到了一个解决方案 var manifest chrome
  • 使用 VBA 宏删除 PowerPoint 中的图片

    我正在使用以下 VBA 宏删除 PowerPoint 幻灯片中的所有图片 Public Function delete slide object slide no Reference existing instance of PowerPo
  • Zend Action 助手与插件

    我有一个出现在每个页面上的侧边栏 侧边栏的第一个元素是 a 登录表单 或 b 当前用户的详细信息 取决于用户是否登录 我已经阅读了一些实现此目的的方法 并计划在引导程序中初始化侧边栏占位符 当需要将用户详细信息或登录表单附加到侧边栏时 我应
  • Allegro CL 在调用(读取)函数时冻结

    每当我打电话给 read 在 Allegro Common Lisp 9 0 中 调试窗口 中断 抱歉 我想不出更清晰的术语 鼠标变成旋转的蓝色死亡轮 窗口拒绝评估任何新输入 尽管它可以仍然可以输入 IDE 的其他部分不受影响 屏幕看起来像
  • 关于加快选边速度的建议

    我正在用 C 构建一个图形编辑器 用户可以在其中放置节点 然后将它们与有向或无向边连接 完成后 A 寻路算法确定两个节点之间的最佳路径 我拥有的 具有 x y 连接节点列表以及 F G 和 H 分数的 Node 类 具有 Start Fin
  • 标准库方法的成员函数指针问题

    这个问题源于 将指向重载类方法的成员函数指针传递到模板函数中 https stackoverflow com questions 31309846 passing a member function pointer to an overlo
  • 丰富的卡片属性 Markdown 格式

    我在英雄卡中的文本属性的降价格式方面遇到问题 这是代码示例 HeroCard heroCard new HeroCard Text Place1 Berlin n n Place2 Hamburg Buttons cardButtons 它
  • 使用 Google Earth Engine 计算每个地区、月份和年份的 NDVI?

    我想计算每个区域 管理级别 3 也称为 Wearda 月份和年份的平均 NDVI 所以我的最终结果看起来像这样 regions year month NDVI region 1 2010 1 0 5 region 1 2010 2 0 6