本文记录了在GEE(GoogleEarthEngine)平台上,使用UCSB-CHG/CHIRPS/DAILY数据集,绘制一个指定点的一段时间内的降水量累计值折线图的代码,也记录了绘制一个区域一段时间内的降水量均值的折线图代码。其中累积降水量使用每日数据累积,降水量均值折线图使用的是每周的降水量数据。即本文记录了将影像集合按天 ‘day’ 合成和按周 ‘week’ 合成的方法。
操作对象:一个点
研究区:一个点的缓冲区
累计值:一个点一段时期内降水量的累积值
var chirpsDaily = ee.ImageCollection("UCSB-CHG/CHIRPS/DAILY");
// 定义时间区间
var startDate = ee.Date('2020-06-01')
var endDate = ee.Date('2020-09-30')
var days = endDate.difference(startDate, 'day')
var daysList = ee.List.sequence(1, days)
// Map()在天列表上的函数
var cumulativeImages = daysList.map(function(day) {
// 筛选从开始日期到计算当天的集合
var begin = startDate
var current = startDate.advance(day, 'day')
var filtered = chirpsDaily.filter(ee.Filter.date(begin, current))
// 使用sum()计算该时期的总降雨量
// 确保设置了图像的start_time
var cumulativeImage = filtered.reduce(ee.Reducer.sum())
.set('system:time_start', current.millis())
return cumulativeImage
})
// 把包含累积降雨的图像列表收集起来
var cumulativeCol = ee.ImageCollection.fromImages(cumulativeImages)
// 创建一个上海的点
var point = ee.Geometry.Point(121.1649, 31.0614)
// 累积降雨量图绘制
var chart = ui.Chart.image.series({
imageCollection: cumulativeCol,
region: point,
reducer: ee.Reducer.mean(),
scale: 5566,
}).setOptions({
interpolateNulls: true,
lineWidth: 1,
pointSize: 3,
title: 'Cumulative Monsoon Rainfall at Shanhai (2020)',
vAxis: {title: 'Cumulative Rainfall (mm)'},
hAxis: {title: 'Month', format: 'YYYY-MMM'}
});
print(chart);
Map.setCenter(121.1649, 31.0614, 12);
Map.addLayer(point, {}, 'point');
操作对象:整个影像
研究区:一个矩形区域
均值:整个影像的均值
var roi = ee.Geometry.Rectangle({
coords: [[120, 30], [122, 32]],
geodesic: false
});
Map.addLayer(roi);
Map.centerObject(roi,7)
var yrly_rain = ee.ImageCollection('UCSB-CHG/CHIRPS/DAILY')
.filter(ee.Filter.calendarRange(2019, 2019, 'year'))
.sum()
.clip(roi)
print(yrly_rain)
Map.addLayer(yrly_rain,{},'Yrly Rainfall')
var chirps = ee.ImageCollection('UCSB-CHG/CHIRPS/DAILY')
// .filter(ee.Filter.calendarRange(2019, 2019, 'year'))
print(chirps.limit(500))
var weeks = ee.List.sequence(1,52)
//print(weeks)
var startD = ee.Date.fromYMD(2019,01,01)
var wkrf = function(Week)
{
var weekStartD = startD.advance (Week,'week')
var weekEndD = weekStartD.advance(1, 'week')
var wk = chirps.filterDate(weekStartD,weekEndD).sum().clip(roi)
return wk.set({'Week': ee.Number(Week)})
}
var wk_rf = weeks.map(wkrf)
var wk_rfcoll = ee.ImageCollection.fromImages(wk_rf)
print(wk_rfcoll);
var wkrf_series = ui.Chart.image.series({
imageCollection:wk_rfcoll,
region: roi,
reducer:ee.Reducer.mean(),
scale:5000,
xProperty:'Week'
})
print(wkrf_series)
Map.addLayer(wk_rfcoll,{},'wkly Rainfall')