【问题标题】:imageCollection.reduce() functions producing single pixel image when exported using Google Earth Engine Python API使用 Google Earth Engine Python API 导出时产生单像素图像的 imageCollection.reduce() 函数
【发布时间】: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() 函数将整个集合聚合为一个值,但我不确定为什么或我能做些什么来阻止它。

任何帮助将不胜感激。

【问题讨论】:

标签: python arrays google-earth-engine


【解决方案1】:

当您运行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()

【讨论】:

  • 嗨,Kel Markert,我刚刚试用了代码,效果很好。非常感谢您解决这个问题!还要感谢 @blindjesse 的有用建议。
  • 很高兴我能提供帮助。编码愉快!
猜你喜欢
  • 2019-03-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-10-09
  • 1970-01-01
  • 2021-04-11
  • 2021-07-21
相关资源
最近更新 更多