Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Google Earth引擎Python API导出时生成单像素图像的imageCollection.reduce()函数_Python_Arrays_Google Earth Engine - Fatal编程技术网

使用Google Earth引擎Python API导出时生成单像素图像的imageCollection.reduce()函数

使用Google Earth引擎Python API导出时生成单像素图像的imageCollection.reduce()函数,python,arrays,google-earth-engine,Python,Arrays,Google Earth Engine,我正在试图找到从imageCollection导出单个图像的方法,目前正在查看imageCollection.reduce()函数。特别是,我想从一个图像集合中创建一个图像,其中每个像素表示集合中图像在该位置的像素平均值。根据这个网页(),imageCollection.reduce()函数应该就是这样做的。看看中值函数的例子,它说“输出是按像素计算的,因此输出中的每个像素由该位置集合中所有图像的中值组成。” 然而,每当我尝试使用这些函数时,导出到我的Google驱动器的输出都是单像素图像 我已

我正在试图找到从imageCollection导出单个图像的方法,目前正在查看imageCollection.reduce()函数。特别是,我想从一个图像集合中创建一个图像,其中每个像素表示集合中图像在该位置的像素平均值。根据这个网页(),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)
但是,当我尝试对imageCollection层执行类似的过程时,其中集合已使用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()
我对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所提到的,您没有正确设置图像导出任务的参数,这会给您一些奇怪的默认结果。以下是以30米分辨率将人口图像导出到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()

运行
task.start()
而不显式设置参数时,任务将使用默认值。正如@blindjesse所提到的,您没有正确设置图像导出任务的参数,这会给您一些奇怪的默认结果。以下是以30米分辨率将人口图像导出到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()

不确定这是否是问题的一部分,但这些参数与ee.batch.Export.image的参数不符:不确定这是否是问题的一部分,但这些参数与ee.batch.Export.image的参数不符:嗨,Kel Markert,我刚刚试用了代码,效果很好。非常感谢你把这件事弄清楚!也感谢@blindjesse的建议。很高兴我能提供帮助。快乐编码!嗨,凯尔·马克特,我刚刚试过这个代码,效果很好。非常感谢你把这件事弄清楚!也感谢@blindjesse的建议。很高兴我能提供帮助。快乐编码!