[英]Python GEE to extract featurecollection timeseries from Landsat imageries
I have a featurecollection for which I need to extract timeseries of NDWI from Landsat imageries.我有一个特征集合,我需要从 Landsat 图像中提取 NDWI 的时间序列。
Here is the javascript functional code I used to extract timeseries: https://code.earthengine.google.com/5992f0f029b10a1c57c8ed34e73a368f这是我用来提取时间序列的 javascript 功能代码: https : //code.earthengine.google.com/5992f0f029b10a1c57c8ed34e73a368f
Now I am trying to replicate the same script in python as follows but it is showing syntax error in the line containing image.mask().and(cloud01.not()).现在我试图在 python 中复制相同的脚本,如下所示,但它在包含 image.mask().and(cloud01.not()) 的行中显示语法错误。 I am wondering how to specify the same condition in python.我想知道如何在 python 中指定相同的条件。
Any help regarding it will be highly appreciated.任何有关它的帮助将不胜感激。
Thanks in advance.提前致谢。
My python code is as follows:我的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());
Try And
instead of and
:尝试And
而不是and
:
image.mask(). A nd(cloud01.not())
This is little syntax changes to distinguish the Python and
operator from the And
function from Google Earth Engine.这是将 Python and
运算符And
Google Earth Engine 中的And
函数区分开来的小语法更改。
Hope that helps!希望有帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.