Google EarthEngine:获取 reduceRegion 的时间序列

Google EarthEngine: Getting time series for reduceRegion

我正在使用 Google EarthEngine(Python API,但这并不重要)。我有一个 ImageCollection,我需要为集合中的每个图像按区域减少。

有没有办法通过向 EarthEngine 发出单个请求来获取 .reduceRegion 的时间序列。到目前为止,我发现 .reduceRegion('mean', feature) 仅适用于图像。我需要一个相当于 collection.reduceRegion('mean', feature) 的东西——它不存在——目的是获取每个时间步长的值列表。

根本问题是,我在创建时间序列时 运行 进入了 EE 的请求限制(每秒 3 个)。此外,对每个单个值发出请求非常慢。

有没有办法为集合构建合适的缩减器。由于集合缩减器需要 return 图像(请告诉我这是否不正确),我可以想象例如在只有一个像素具有所需值的输入集合中创建每个图像一个波段的图像。

感谢您的帮助

这是一个方法。

在这个脚本中你得到一个没有空值的字典

# -*- 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()