Google Earth Engine(GEE)合成长时序的月NDVI与LST

今天来简单分享下如何在GEE合成长时序的月NDVI与LST,并进行分析

目标:

利用MODIS为数据源,在GEE计算某一地区对月NDVI与LST,并制作统计图

以武汉市为研究区

GEE实现代码:

首先确定研究区和使用的数据集

var roi = ee.FeatureCollection("users/lilei655123/WUhan");
Map.centerObject(roi,7)
var styling = {color:"red",fillColor:"00000000"};
Map.addLayer(roi.style(styling),{},"geometry")
//添加MODIS植被指数16天全球250米 
var Coll_NDVI = ee.ImageCollection("MODIS/006/MOD13Q1")
//MODIS/006/MOD13A1
var Coll_LST = ee.ImageCollection("MODIS/006/MOD11A2")
//MODIS/006/MOD11A1

确定起止时间和月份

var startYear = 2010;
var endYear = 2020;
var startDate = ee.Date.fromYMD(startYear, 1, 1);
var endDate = ee.Date.fromYMD(endYear, 12, 31);

合成NDVI和LST

Coll_NDVI = Coll_NDVI.filterDate(startDate, endDate).select("NDVI");
Coll_NDVI = ee.ImageCollection(ee.Algorithms.If(Coll_NDVI.size().eq(0),
      ee.ImageCollection(ee.Image(0).selfMask().rename('NDVI')),
      Coll_NDVI
    ));
Coll_LST = Coll_LST.filterDate(startDate, endDate).select("LST_Day_1km");
Coll_LST = ee.ImageCollection(ee.Algorithms.If(Coll_LST.size().eq(0),
      ee.ImageCollection(ee.Image(0).selfMask().rename('LST_Day_1km')),
      Coll_LST
    ));
// MOD12Q1数据的NDVI比例为0.0001 [ 最小值=-2000,最大值=10000]
var Coll_NDVI = Coll_NDVI.map(function(img) {
  return img
    .divide(10000).float().set("system:time_start", img.get("system:time_start")); // keep time info
    });


var Coll_LST = Coll_LST.map(function(img) {
  return img
    .multiply(0.02).subtract(273.15).float().set("system:time_start", img.get("system:time_start")); // keep time info
});


print(Coll_NDVI);
print(Coll_LST);

合成月NDVI

var monthlyNDVI =  ee.ImageCollection.fromImages(
  years.map(function (y) { 
    return months.map(function(m) {
      var monthly = Coll_NDVI
        .filter(ee.Filter.calendarRange(y, y, "year"))
        .filter(ee.Filter.calendarRange(m, m, "month"))
        .mean(); 
      return monthly
        .set("year", y) 
        .set("month", m)
        .set('date', ee.Date.fromYMD(y,m,1))
        .set("system:time_start", ee.Date.fromYMD(y, m, 1));}); })
  .flatten());
print('monthlyNDVI',monthlyNDVI)
//最大合成NDVI
var MonthlyMAX =  ee.ImageCollection.fromImages(months
  .map(function (m) {
    var maxNDVI = monthlyNDVI.filter(ee.Filter.eq("month", m))
      .reduce(ee.Reducer.percentile({percentiles: [90]}));
  return maxNDVI
    .set("month", m);})
  .flatten());
//print (MonthlyMAX, 'MonthlyMAX');
Map.addLayer (MonthlyMAX.first().clip(roi),  {min:0, max:1,  'palette': ['red','yellow', 'green']}, 'MonthlyMAX');


var MonthlyMIN =  ee.ImageCollection.fromImages(months
  .map(function (m) {
    var minNDVI = monthlyNDVI.filter(ee.Filter.eq("month", m))
      .reduce(ee.Reducer.percentile({percentiles: [10]}));
  return minNDVI
    .set("month", m);})
  .flatten()); 
//print (MonthlyMIN, 'MonthlyMIN');
Map.addLayer (MonthlyMIN.first().clip(roi),  {min:0, max:1,  'palette': ['red','yellow', 'green']}, 'MonthlyMIN');

同样的方法合成月LST

var monthlyLST =  ee.ImageCollection.fromImages(
  years.map(function (y) { 
    return months.map(function(m) {
      var monthly = Coll_LST
        .filter(ee.Filter.calendarRange(y, y, "year"))
        .filter(ee.Filter.calendarRange(m, m, "month"))
        .mean(); 
      return monthly
        .set("year", y) 
        .set("month", m)
        .set('date', ee.Date.fromYMD(y,m,1))
        .set("system:time_start", ee.Date.fromYMD(y, m, 1));}); })
  .flatten());
print('monthlyLST',monthlyLST)




//最大合成LST 
var Monthly_LST_MAX =  ee.ImageCollection.fromImages(months
  .map(function (m) {
    var maxNDVI = monthlyLST.filter(ee.Filter.eq("month", m))
      .reduce(ee.Reducer.percentile({percentiles: [90]}));
  return maxNDVI
    .set("month", m);})
  .flatten());
  
//print (Monthly_LST_MAX, 'Monthly_LST_MAX');
Map.addLayer (Monthly_LST_MAX.first().clip(roi),  {min:15, max:35,  'palette': ['red','yellow', 'green']}, 'Monthly_LST_MAX');


var Monthly_LST_MIN =  ee.ImageCollection.fromImages(months
  .map(function (m) {
    var minNDVI = monthlyNDVI.filter(ee.Filter.eq("month", m))
      .reduce(ee.Reducer.percentile({percentiles: [10]}));
  return minNDVI
    .set("month", m);})
  .flatten());
  
//print (Monthly_LST_MIN, 'Monthly_LST_MIN');
Map.addLayer (Monthly_LST_MIN.first().clip(roi),  {min:0, max:1,  'palette': ['red','yellow', 'green']}, 'Monthly_LST_MIN');

创建统计图

var ndviTimeSeries = ui.Chart.image.seriesByRegion(
    monthlyNDVI, roi, ee.Reducer.mean(), 'NDVI', 500, 'system:time_start', 'label')
        .setChartType('ScatterChart')
        .setOptions({trendlines: {0: {color: 'green'}},lineWidth: 1,pointSize: 3,
          title: 'MODIS NDVI Time Series',
          vAxis: {title: 'NDVI'},
                   series: {
            0: {color: 'green'}, 
           
}});
print(ndviTimeSeries);
print(ui.Chart.image.series(monthlyNDVI , roi , ee.Reducer.mean(), 500));

运行结果如下:

167d165218093f7a21436c74874644a3.png

LST

2531c1bc70c37d9922c1762714574202.png

1fe2b072e40e39b7a4c13f90ff1f84be.png

NDVI的带状平均值

425ff08d19fb02e0496570c2fd28ce6e.png

ed5eba422400566e3ffb3313fd88165a.png

LST的带状平均值

完整代码请在公众号后台回复“0803合成月NDVI和LST”

感谢关注,欢迎转发!

声明:仅供学习使用!

希望关注的朋友们转发,如果对你有帮助的话记得给小编点个赞或者在看

## ****更多内容请关注微信公众号“生态遥感监测笔记”**

  • 10
    点赞
  • 87
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 9
    评论
以下是使用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值。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

生态遥感监测笔记

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

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

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

打赏作者

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

抵扣说明:

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

余额充值