[英]Summarize Pixel Value in Every Image of an Image Collection in Google Earth Engine
I am a newbie in GEE.我是 GEE 的新手。 I want to calculate a sum / mean of a pixel value (rainfall data from CHIRPS satellite) in one region of every image data in an ImageCollection.我想计算 ImageCollection 中每个图像数据的一个区域中像素值(来自 CHIRPS 卫星的降雨数据)的总和/平均值。 Basically i want to calculate the mean daily rainfall in my study area.基本上我想计算我研究区域的平均日降雨量。
Here is my code so far:到目前为止,这是我的代码:
//define study area
var aoi = ee.FeatureCollection(juana)
//load & filtering ImageCollection
var precipitation = ee.ImageCollection('UCSB-CHG/CHIRPS/DAILY')
.filterDate('2021-01-01', '2021-12-31')
.select('precipitation');
//clipped ImageCollection to Study Area
var clipped = precipitation.map(function(precipitation){
return precipitation.clip(aoi);
});
//plot in map
Map.addLayer(clipped)
Here is the result in map:这是 map 中的结果:
Every pixel has a daily rainfall data like this:每个像素都有这样的每日降雨数据:
But what i need is i want to sum/averaging those pixel in the study area and make a daily graphic.但我需要的是我想对研究区域中的那些像素求和/平均并制作每日图形。 What should i do?我应该怎么办?
You use ee.Image().reduceRegion()
to calculate aggregate statistics for an area of an image.您使用ee.Image().reduceRegion()
来计算图像区域的聚合统计信息。 In your case, you want a time-series of the stats, so you want to do this for every image in you collection.在你的例子中,你想要一个时间序列的统计数据,所以你想对你收藏中的每张图片都这样做。 To do that, you use ee.ImageCollection.map()
.为此,您可以使用ee.ImageCollection.map()
。 You have relevant sections in the docs here and here .您在此处和此处的文档中有相关部分。 Something like this:是这样的:
var dailyStats = precipitation.map(function (image) {
var reduced = image.reduceRegion({
reducer: ee.Reducer.sum()
.combine(ee.Reducer.mean(), null, true),
geometry: aoi.geometry(),
scale: 5000,
maxPixels: 1e13
})
return ee.Feature(null, reduced)
.set('system:time_start', image.get('system:time_start'))
})
var meanChart = ui.Chart.feature.byFeature({
features: dailyStats,
xProperty: 'system:time_start',
yProperties: 'precipitation_mean'
})
var sumChart = ui.Chart.feature.byFeature({
features: dailyStats,
xProperty: 'system:time_start',
yProperties: 'precipitation_sum'
})
print('mean', meanChart)
print('sum', sumChart)
https://code.earthengine.google.com/e6e4af4147004c6cbd9fe0f20dd7c9fe https://code.earthengine.google.com/e6e4af4147004c6cbd9fe0f20dd7c9fe
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.