我正在使用Google EarthEngine(Python API,但这并不重要)。我有一个ImageCollection,我需要按区域为集合中的每个图像减少。
有没有办法通过对EarthEngine的单一请求获取.reduceRegion的时间序列。到目前为止,我发现.reduceRegion(' mean',feature)仅适用于图像。我需要一个与collection.reduceRegion(' mean',feature)相当的 - 它不存在 - 目标是获取每个时间步的值列表。
根本问题是,我在创建时间序列时遇到了EE的请求限制(每秒3次)。此外,对每个值发出请求的速度非常慢。
有没有办法为集合构建合适的reducer。由于集合缩减器需要返回图像(请告诉我,如果这是不正确的),我可以想象,例如在输入集合中为每个图像创建一个带的图像,该图像只有一个具有所需值的像素。
感谢您的帮助
答案 0 :(得分:1)
这是一种方法。
在此脚本中,您将获得一个没有空值的字典
# -*- coding: utf-8 -*-
"""
Created on Tue Mar 14 11:21:09 2017
@author: Gennadii
"""
import ee
ee.Initialize()
geometry = ee.Geometry.Polygon([[[-71.54365539550781, -43.07340216393553],
[-71.5484619140625, -43.11050787253287],
[-71.488037109375, -43.125043167401266],
[-71.48460388183594, -43.0754084526532]]])
def calcMean(img):
# gets the mean NDVI for the area in this img
mean = img.reduceRegion(ee.Reducer.mean(), geometry, 30).get('NDVI')
# sets the date and the mean NDVI as a property of the image
return img.set('date', img.date().format()).set('mean', mean)
# Applies calcMean() in the collection
col = ee.ImageCollection("LANDSAT/LC8_L1T_8DAY_NDVI").filterDate("2014-01-01","2014-03-31").map(calcMean)
# Reduces the images properties to a list of lists
values = col.reduceColumns(ee.Reducer.toList(2), ['date', 'mean']).values().get(0)
# Type casts the result into a List
lista = ee.List(values)
# Converts the list of lists to a Dictionaty
means = ee.Dictionary(lista.flatten())
print "Dictionary of means:", means.getInfo()
和你得到的其他脚本也是空值。它们在此脚本中填充-10,但您可以将其更改为您需要的任何内容。它可以是0或字符串。
# -*- coding: utf-8 -*-
"""
Created on Tue Mar 14 11:17:29 2017
@author: Rodrigo E. Principe
"""
import ee
ee.Initialize()
geometry = ee.Geometry.Polygon([[[-71.54365539550781, -43.07340216393553],
[-71.5484619140625, -43.11050787253287],
[-71.488037109375, -43.125043167401266],
[-71.48460388183594, -43.0754084526532]]])
col = ee.ImageCollection("LANDSAT/LC8_L1T_8DAY_NDVI").filterDate("2014-01-01","2014-03-31")
# Initial empty Dictionary
meansIni = ee.Dictionary()
def calcMean(img, first):
#gets the year of the image
year = img.date().format()
#gets the NDVI
nd = ee.Image(img).reduceRegion(ee.Reducer.mean(),geometry,30).get("NDVI")
#Checks for null values and fills them with whatever suits you (-10 is just an option)
ndvi = ee.Algorithms.If(ee.Algorithms.IsEqual(nd, None), -10, nd)
#fills the Dictionary
return ee.Dictionary(first).set(year, ndvi)
# Apply calcMean() to the collection
means = ee.Dictionary(col.iterate(calcMean, meansIni))
print "Dictionary of means:", means.getInfo()