简体   繁体   English

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

[英]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.

相关问题 我的 GEE 编辑器代码出现错误“image.normalizedDifference 不是函数”以计算 Landsat 集合的 NDVI 时间序列 - Getting error "image.normalizedDifference is not a function" for my GEE editor code to calculate timeseries of NDVI for a Landsat collection 从多个GeoJSON字符串创建FeatureCollection - Create FeatureCollection from multiple GeoJSON strings 从featureCollection turf.js中删除功能 - Remove feature from featureCollection turf.js 如何通过坐标从JSON FeatureCollection查找属性值? - How can I find property value from a json FeatureCollection by coordinates? 随机化FeatureCollection - randomize featureCollection 如何从 landsat 8 表面反射集合中删除具有特定 WRS_PATH 和 WRS_ROW 的图像? - How to remove images with specific WRS_PATH and WRS_ROW from a landsat 8 surface reflectance collection? URL中的Mapbox JS,GeoJSON featureCollection对象仅添加一个标记 - Mapbox JS, GeoJSON featureCollection object from URL only adds one marker 如何从时间序列数据构造一个“嵌套”对象? - How to construct an 'nested' object from timeseries data? 使用以下 function 将 GEE javascript 转换为 Python 脚本时出现错误 - Using the below function I am getting an error when I convert the GEE javascript to Python script 使用Quora中的Selenium - Python提取“(更多)”文本 - Extract “(more)” text with Selenium from Quora - Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM