GEE14:提取每年的GPP最大值

最近学习了关于获取每年GPP最大值的DOY(day of year)的方法:

1. 数据介绍

MOD17A2H v006:
The MOD17A2H Version 6 Gross Primary Productivity (GPP) product is a cumulative 8-day composite of values with 500 meter (m) pixel size based on the radiation use efficiency concept that can be potentially used as inputs to data models to calculate terrestrial energy, carbon, water cycle processes, and biogeochemistry of vegetation. The data product includes information about GPP and Net Photosynthesis (PSN). The PSN band values are the GPP less the Maintenance Respiration (MR). The data product also contains a PSN Quality Control (QC) layer. The quality layer contains quality information for both the GPP and the PSN.

在这里插入图片描述

2. JavaScript代码

已将代码进行了注释,方便读者学习和理解

// 数据导入:MOD17A2H.006,时间分辨率为8天,空间分辨率为500米
var gpp = ee.ImageCollection("MODIS/006/MOD17A2H");
print("gpp", gpp)

// 在2010-2022年间,提取每年的GPPmax,并输出GPPmax对应的DOY(day of year)
// 从开始到结束(包括)以等距增量生成一个数字序列
var start_year = 2010;
var end_year = 2022;
var yearList = ee.List.sequence(start_year,end_year);
print("yearList", yearList)

// 用map函数对yearList进行循环
// map函数一般计算最快,表示:并行执行任务,能用 map,就用 map
var yearImgList = yearList.map(function(year)
{
  year = ee.Number(year);
  // 将ImageCollection里面的Image按年进行处理
  var tempCol = gpp.filter(ee.Filter.calendarRange(year,year,'year'))
             .map(function(image)
             {  
               // 获取每个图像的开始时间
               var time_start = image.get("system:time_start");  
               var date = ee.Date(time_start);  
               // 计算DOY 
				   // 这一部分使用date对象的format方法将日期转换为字符串, 并使用参数"D"指定格式化字符串。
				   // "D"表示将日期转换为一个两位数的字符串表示,表示一年中的第几天。
				   // 例如,1月1日对应的是"001",12月31日对应的是"365"或"366"(闰年)。
               var doy = ee.Number.parse(date.format("D")).toInt(); 
               // 生成包含DOY的图像
               var doyImg = ee.Image.constant(doy).toInt16().rename("doy"); 
               // 原图像加上doy波段
               image = image.addBands(doyImg);  
               // 返回只包含Gpp和DOY 2个波段的图像
               return image;
                })
                .select(["Gpp", "doy"]);
  // 提取每一年Gpp的最大值及相应的doy,输出为List
  // reduce函数对图像集合进行降维操作:
  var img = tempCol.reduce(  
  // 这是一个降维器(reducer),用于计算每个像素在时间序列中的最大值
  // 参数2表示沿着时间轴(第二个轴)进行降维操作
  // 例如,对于每个像素位置,将从图像集合中选择具有最大Gpp值的图像。
  ee.Reducer.max(2)   
    .setOutputs(["gppmax", "doy"])); // 设置降维操作的输出名称
  img = img.set('year', year); // 将year属性添加到img图像中。year是当前年份,用于标识图像是哪一年的结果。
  img = img.set('system:index', ee.String(year.toInt())); // 用于将图像索引设为年份的字符串表示
  return img;
});
print("yearImgList", yearImgList)

// 查看第一个图像(从0开始计数)
Map.addLayer(ee.Image(yearImgList.get(0)))


// 获取List的图像的数量,并通过getInfo()获取相应的属性信息
var count = yearImgList.size().getInfo();
print("count", count)

// 批量导出所有图像
for(var i=0; i<count; i++)
{
  // 获取图像的id属性作为文件名的一部分
  var image = ee.Image(yearImgList.get(i)); 
  var id = image.id();
  var name = "GPPmax_"+id.getInfo();
  // 结果输出
  Export.image.toDrive({
    image: image, 
    description: 'imageToCOGeoTiff' + i,
    fileNamePrefix: name,
    scale: 500, // 空间分辨率为500m
    maxPixels: 1e13,
    fileFormat: 'GeoTIFF',
    formatOptions: {
      cloudOptimized: true
    }
  }); 
}

结果展示:
在这里插入图片描述
在这里插入图片描述

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Jackson的生态模型

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值