imageCollection.reduce() 函数在使用 Google 地球引擎 Python API 导出时生成单



我正在尝试找到从imageCollection导出单个图像的方法,目前正在查看imageCollection.reduce((函数。特别是,我想从图像集合中创建单个图像,其中每个像素表示该位置的像素在集合中的图像中的平均值。根据这个网页(https://developers.google.com/earth-engine/reducers_image_collection(,imageCollection.reduce(( 函数应该这样做。查看中位数函数的示例,它说"输出是逐像素计算的,因此输出中的每个像素都由该位置集合中所有图像的中值组成。

但是,每当我尝试使用这些功能时,导出到我的Google云端硬盘的输出都是单像素图像。

我已经能够导出和下载仅包含单个图像的 ee 图层的整个图像。以下示例显示了高程图层的结果:

import ee
import rasterio as rio
import numpy as np
ee.Initialize()
elevation = ee.Image('JAXA/ALOS/AW3D30_V1_1').select('AVE')
geometry = ee.Geometry.Polygon([[33.8777, -13.4055],
[33.8777, -13.3157],
[33.9701, -13.3157],
[33.9701, -13.4055]])
geometry = geometry['coordinates'][0]
filename = "Example_File"
task_config = {
'region': geometry,
'min': 0.0,
'max': 4000.0,
'palette': ['0000ff', '00ffff', 'ffff00', 'ff0000', 'ffffff']
}
task = ee.batch.Export.image(elevation, filename, task_config)
task.start()

一旦图像被导出并下载到我的计算机上,我得到以下输出:

rs = rio.open("C:\Users\miker\Downloads\Example_File.TIF")
rs.read(1)
#Output#
array([[1275, 1273, 1271, ..., 1152, 1163, 1178],
[1275, 1273, 1271, ..., 1152, 1164, 1184],
[1275, 1273, 1271, ..., 1158, 1169, 1187],
...,
[1327, 1326, 1324, ..., 1393, 1396, 1397],
[1328, 1326, 1325, ..., 1399, 1400, 1403],
[1328, 1326, 1325, ..., 1402, 1404, 1407]], dtype=int16)

但是,当我尝试对图像集合层遵循类似的过程时,其中集合已使用 ee 简化为图像。Reducer.mean(( 函数,我只得到一个像素数组:

population = (ee.ImageCollection('WorldPop/POP')
.select('population')
.filter(ee.Filter.date('2015-01-01', '2017-12-31')))
population = population.reduce(ee.Reducer.mean())
File_Name = "Example_File2"
task_config = {
'region': geometry,
'min': 0.0,
'max': 50.0,
'palette': ['24126c', '1fff4f', 'd4ff50']
}
task = ee.batch.Export.image(population, File_Name, task_config)
task.start()
rs = rio.open("C:\Users\miker\Downloads\Example_File2.TIF")
rs.read(1)
#Output#
array([[1.262935]], dtype=float32)

我已经对min((,max((和median((重复了这个过程,并得到了类似的结果:

# mean:   array([[1.262935]], dtype=float32)
# median: array([[1.262935]], dtype=float32)
# min:    array([[1.2147448]], dtype=float32)
# max:    array([[1.3111253]], dtype=float32)

有谁知道为什么会发生这种情况?我的猜测是 reduce(( 函数将整个集合聚合到一个值中,但我不确定为什么或我可以做些什么来阻止这种情况。

任何帮助将不胜感激。

当您在没有显式设置参数的情况下运行task.start()时,任务将使用默认值。如@blindjesse所述,您没有正确设置图像导出任务的参数,并且默认情况下会给您奇怪的结果。以下是以 30m 分辨率将人口图像导出到 GDrive 的示例:

population = (ee.ImageCollection('WorldPop/POP')
.select('population')
.filter(ee.Filter.date('2015-01-01', '2017-12-31')))
population = population.reduce(ee.Reducer.mean())
geometry = ee.Geometry.Polygon([[33.8777, -13.4055],
[33.8777, -13.3157],
[33.9701, -13.3157],
[33.9701, -13.4055]])
File_Name = "Example_File2"
task_config = {
'region': geometry.coordinates().getInfo(), 
'scale': 30,
'description': File_Name
} 
task = ee.batch.Export.image.toDrive(population, **task_config)
task.start()

最新更新