gpt4 book ai didi

javascript - Python GEE 从 Landsat 图像中提取特征集合时间序列

转载 作者:行者123 更新时间:2023-11-30 19:20:28 28 4
gpt4 key购买 nike

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

这是我用来提取时间序列的 javascript 功能代码:https://code.earthengine.google.com/5992f0f029b10a1c57c8ed34e73a368f

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

如有任何帮助,我们将不胜感激。

提前致谢。

我的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().<b>A</b>nd(cloud01.not())

这是区分 Python 的小语法更改 and来自 And 的运算符(operator)来自 Google Earth Engine 的功能。

希望对您有所帮助!

关于javascript - Python GEE 从 Landsat 图像中提取特征集合时间序列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57535039/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com