2017-02-14 48 views
0

我正在使用Google EarthEngine(Python API,但這並不重要)。我有一個ImageCollection,我需要按照區域縮小集合中的每個圖像。Google EarthEngine:爲reduceRegion獲取時間序列

有沒有辦法通過對EarthEngine的單個請求獲取.reduceRegion的時間序列。到目前爲止,我發現.reduceRegion('mean',feature)僅適用於圖像。我需要一個等同於collection.reduceRegion('mean',feature) - 不存在 - 的目標是獲得每個時間步的值列表。

潛在的問題是,我在創建我的時間序列時遇到EE的請求限制(每秒3次)。另外,對每一個值發出請求都很慢。

有沒有辦法爲集合構造一個合適的縮減器。由於收集減速器需要返回圖像(請告訴我,如果這是不正確的),我可以想象例如在輸入集合中爲每個圖像創建一個帶,其中只有一個像素具有所需的值。

謝謝你的幫助

+0

因此,您需要一個列表,其中包含縮略圖在集合的每個圖像中的結果。是對的嗎?像[0.2,0.5,0.8,0.7]之類的東西? –

+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() 
+0

謝謝你的努力。很快就會評估。 –