Javascript Google EarthEngine:获取reduceRegion的时间序列
我正在使用Google EarthEngine(Python API,但这并不重要)。我有一个ImageCollection,我需要为集合中的每个图像按区域缩小它 是否有一种方法可以通过向EartEngine发出一个请求来获取.reduceRegion的时间序列。到目前为止,我发现.reduceRegion('mean',feature)只对图像有效。我需要一个与collection.reduceRegion('mean',feature)等价的函数——它不存在——目标是为每个时间步获得一个值列表 潜在的问题是,我在创建时间序列时遇到了EE的请求限制(每秒3次)。此外,对每个值发出请求的速度非常慢 是否有一种方法可以为集合构造适当的缩减器。由于采集减缩器需要返回图像(请告诉我是否不正确),我可以想象,例如,在输入采集中,创建一个每个图像一个波段的图像,该图像只有一个像素具有所需的值 感谢您的帮助这里有一个方法 在这个脚本中,您将得到一个没有空值的字典Javascript Google EarthEngine:获取reduceRegion的时间序列,javascript,python,google-earth-engine,Javascript,Python,Google Earth Engine,我正在使用Google EarthEngine(Python API,但这并不重要)。我有一个ImageCollection,我需要为集合中的每个图像按区域缩小它 是否有一种方法可以通过向EartEngine发出一个请求来获取.reduceRegion的时间序列。到目前为止,我发现.reduceRegion('mean',feature)只对图像有效。我需要一个与collection.reduceRegion('mean',feature)等价的函数——它不存在——目标是为每个时间步获得一个值列
# -*- 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()
因此,您需要一个列表,其中包含集合的每个图像中的reducer结果。是这样吗?比如[0.2,0.5,0.8,0.7]?这是正确的。最好以某种方式将山谷与图像联系起来。但我想我自己也能保持秩序。谢谢你的努力。我会很快评估。我有一个与此相关的问题,为什么你的食谱在我的情况下不起作用?谢谢