【发布时间】:2019-09-04 04:06:52
【问题描述】:
我正在尝试寻找从 imageCollection 导出单个图像的方法,目前正在研究 imageCollection.reduce() 函数。特别是,我想从图像集合中创建单个图像,其中每个像素代表集合中图像中该位置的像素的平均值。根据这个网页 (https://developers.google.com/earth-engine/reducers_image_collection),imageCollection.reduce() 函数应该做到这一点。查看中值函数的示例,它表示“输出是按像素计算的,因此输出中的每个像素都由该位置集合中所有图像的中值组成。”
但是,每当我尝试使用这些函数时,导出到我的 Google Drive 的输出都是单像素图像。
我已经能够为仅包含单个图像的 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()
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() 函数将整个集合聚合为一个值,但我不确定为什么或我能做些什么来阻止它。
任何帮助将不胜感激。
【问题讨论】:
-
不确定这是问题的一部分,但这些参数看起来不像 ee.batch.Export.image 的正确参数:github.com/google/earthengine-api/blob/master/python/ee/…
标签: python arrays google-earth-engine