GEE下载年均GPP产品绘制GPP时间序列

求每年的平均

var geo = ee.FeatureCollection('projects/ee-wn1206/assets/dongbei').geometry()//加载研究区shp,建议把feature变为geometry类型,变于后面裁减
var dataset = ee.ImageCollection("MODIS/006/MOD17A2H");  //加载MODIS  MOD17A2H产品,注意查看数据年份
for(var i=2001;i<=2020;i++){
  var data_collection = dataset.filterDate(i+'-01-01',i+'-12-31').select('Gpp');
//删选出各年中的8天合成数据选择Gpp波段
  // print(data_collection)    有20个数据集
  var YR_collection = data_collection.sum().clip(geo);
//将每年的数据集求和得到年Gpp量,并裁减
  Export.image.toDrive({
    image: YR_collection,//输出数据集
    description: i, //任务描述
    fileNamePrefix: i,  //下载文件名
    scale: 500,  //分辨率
    crs:"EPSG:4326",  //坐标系
    region: geo.geometry().bounds(),//边界复杂显示无法现在修改region
    maxPixels: 1e13,
    folder: 'Modis'   //云盘文件名
  });
}     

求年均GPP

var geo = ee.FeatureCollection('projects/ee-wn1206/assets/dongbei').geometry();
//var union = geometry.union();//合并feature
//var geo =union.geometry();//feature变为多边形
var dataset = ee.ImageCollection("MODIS/006/MOD17A2H")
             .select('Gpp')
             .filter(ee.Filter.date('2001-01-01', '2020-12-31'))
             .filterBounds(geo);//这里不允许使用clip()
//波段选择、时间删选、范围删选
var GPP = dataset.sum().multiply(0.1).divide(20).clip(geo);
//直接将20年的数据求和/20年即可获得20年均GPP
//Gpp的缩放系数是0.0001,单位是kgC/year,换算成gC/year,所以总乘以0.1
Export.image.toDrive({
    image: GPP,
    description: "GPP_mean20",
    scale: 500,
    crs:"EPSG:4326",
    region: geo,
    maxPixels: 1e13,
    folder: 'Modis_GPP_Mean'
  });

GPP时间序列

var geo = ee.FeatureCollection('projects/ee-wn1206/assets/dongbei').geometry();
Map.addLayer(geo)//显示研究区
var collection = ee.ImageCollection("MODIS/006/MOD17A2H")
                     .filterDate('2001-01-01', '2020-12-31')
                     .select("Gpp")
                     .map(function(image){
                       return image.multiply(0.1).set(image.toDictionary(image.propertyNames()))
                     });//map是对每一个数据采用同样操作,即将每个数据集乘以0.1,并返回属性名
//image.set()指 Returns the element with the specified properties overridden.返回覆盖了指定属性的元素。
//Image.toDictionary(properties) 指Extract properties from a feature as a dictionary. 从特性中提取属性作为字典。
//Image.propertyNames() 指 Returns the names of properties on this element.返回此元素上的属性名称List。
var years = ee.List.sequence(2001, 2020);//years是列表
//ee.List.map 指Map an algorithm over a list. The algorithm is expected to take an Object and return an Object. 将算法映射到列表上。该算法将接受一个对象并返回一个对象。
var collectYear = ee.ImageCollection(years
  .map(function(y) {
    var start = ee.Date.fromYMD(y, 1, 1);
    var end = start.advance(12 ,'month');advance 指在初始时间上再加12个月,也可以写成start.advance(1 ,'year')
    return collection.filterDate(start, end).sum().reduce(ee.Reducer.mean()).float().set('system:time_start',y).set('year',y);
}));//map+function等于for循环,对每一年的数据遍历,求和并求影像的均值,并将数据类型改为浮点型,并设置两个属性名
//ee.Reducer.mean返回一个Reducer,用于计算其输入的(加权)算术平均值。
print(collectYear)// ee.ImageCollection(years .map)得到的遍历20个数据均值返回给collectYear
 //可以发现collectYeat是ImageCollection类型有20个元素,每个元素返回3个properties分别为index和创建的system:time_start、year,以及一个计算出来的波段为mean
var Yearly_chart = ui.Chart.image.series({
//图表部件ui.Chart(dataTable, chartType, options, view, downloadable)
    imageCollection: collectYear.select('mean'),
    region: geo,
    reducer: ee.Reducer.mean(),
    scale: 500,
    xProperty: 'year',
    }).setOptions({
//图表样式选择Chart.setOptions(options)
      interpolateNulls: true,
      lineWidth: 2,
      title: 'GPP Spring yearly Seires',
      vAxis: {title: 'GPP(gC/㎡)'},
      hAxis: {title: 'year'},
      trendlines: { 0: {title: 'GPP_trend',type:'linear', showR2: true,  color:'red', visibleInLegend: true}}
    //绘制出趋势直线
    })                        
print(Yearly_chart);

在这里插入图片描述

在这里插入图片描述

参考:
GPP/NPP产品介绍
GPP产品下载
GPP时间序列
趋势线

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值