Python GEE 用于从 Landsat 影像中提取要素集合时间序列



我有一个要素集合,我需要从 Landsat 影像中提取 NDWI 的时间序列。

以下是我用来提取时间序列的javascript函数代码: https://code.earthengine.google.com/5992f0f029b10a1c57c8ed34e73a368f

现在我正在尝试在 python 中复制相同的脚本,如下所示,但它在包含 image.mask((.and(cloud01.not((( 的行中显示语法错误。我想知道如何在 python 中指定相同的条件。

任何有关它的帮助将不胜感激。

提前谢谢。

我的蟒蛇代码如下:

import datetime
import ee
ee.Initialize()

table = ee.FeatureCollection("users/nbiswas/Buffered_reservoirs_seasia")
L8 = ee.ImageCollection("LANDSAT/LC08/C01/T2"),
table2 = ee.FeatureCollection("users/nbiswas/Madushan"),
table3 = ee.FeatureCollection("users/nbiswas/india_reservoirs_buffer_3km");
class ReservoirExtent():
def __init__(self):
self.table = table2
self.geometry = table2.geometry();
self.Date_Start = ee.Date('2008-01-01');
self.Date_End = ee.Date('2018-07-31');
self.cloud_thresh = 20;
def clipimage(self, img):
return img.clip(self.geometry);
def cloudfunction(self, image):
#use add the cloud likelihood band to the image
CloudScore = ee.Algorithms.Landsat.simpleCloudScore(image);
#isolate the cloud likelihood band
quality = CloudScore.select('cloud');
#get pixels above the threshold
cloud01 = quality.gt(self.cloud_thresh);
#create a mask from high likelihood pixels
cloudmask = image.mask().and(cloud01.not());
#mask those pixels from the image
return image.updateMask(cloudmask);
def l8Ndwi(self, img):
ndwi = img.normalizedDifference(['B3', 'B5']).rename('NDWI');
return img.addBands(ndwi);
def areadate(self, img):
area = img.gt(0).multiply(ee.Image.pixelArea()).divide(1000000).reduceRegion(ee.Reducer.sum(), self.geometry, 30).get('NDWI');
return img.set('area', area).set('date', img.get('system:time_start'));
def extentseries(self, reservoir):
l8images = L8.filterDate(self.Date_Start,self.Date_End).filterBounds(self.geometry);
print(l8images);
l8images = l8images.map(self.clipimages);
l8images = l8images.map(self.cloudfunction);
l8images = l8images.select(["B3","B5"]);

# calculate ndwi for each image in imagecollection
l8ndwi = l8images.map(self.l8Ndwi);
mosaics = l8ndwi.map(self.areadate)
mosaics = ee.ImageCollection(mosaics);
mosaic = mosaics.sort('system:time_start', false);
list = mosaic.reduceColumns(ee.Reducer.toList(2), ['date', 'area']).get('list');
print(list);
#return reservoir.set(ee.Dictionary(ee.List(list).flatten()));

if __name__ == '__main__':
forecast = ReservoirExtent()
ppp = forecast.extentseries(table2);
print(ppp.getInfo());

尝试And而不是and

image.mask().And(cloud01.not())

这是为了区分 Pythonand运算符和 Google 地球引擎的And函数而进行的语法更改。

希望对您有所帮助!

最新更新