zoukankan      html  css  js  c++  java
  • [GEE Tips-1]在Colab配置GEE Python API

    1.为什么是Python API?为什么是Colab?

    Python有许多强大的包,如果可以利用Python调用GEE API,就会显得方便、优雅。但是,国内使用GEE Python API,因为网络原因,容易断线、无响应,如果是少量文件还好,文件多了以后,就会很麻烦;而Colab是Google的云Coding环境,自家服务器之间的通信会稳定许多。此外,由于大家机器的不同,导致本地配置GEE Python API相对困难,相对来讲提高了入门门槛,没有一定的Python基础,很难融会贯通;而Colab是统一的云端环境,无论Python 2还是3,只要一步一步来,很难出错。
    总结起来,就是网络条件不太好,和/或难以使用本地GEE Python API的情况下,Colab不失为一个好的解决方案。
    关于Colab,网络上的教程很多,这里不再赘述。

    2.GEE-Python API配置

    !pip install google-api-python-client
    !pip install pyCrypto
    !pip install earthengine-api
    !earthengine authenticate
    

    pyCrypto包在本地很容易安装失败,但在Colab上不会出现问题,直接用pip即可。
    需要注意的是,Colab下的命令行命令也是在代码窗口里输入,但是需要在前面加上”! “

    !!!!!2020年2月2日更新!!!!!
    现在已经不需要再安装这三个包了,直接

    import ee
    ee.Authenticate()
    

    就完事了

    3.Google Drive文件调用

    如果我们想调用自己的文件,而不把它上传到GEE平台,可以通过Colab调用自己的Google Drive,方法是:

    from google.colab import drive 
    drive.mount('/gdrive')
    

    这里也会出现一个类似于GEE的授权界面,方法类似,大家做的时候就知道啦。

    通过

    /gdrive/My Drive/+文件路径
    

    即可调用Google Drive里面的文件。

    4.测试代码

    import ee
    ee.Initialize()
    image1 = ee.Image('srtm90_v4')
    path = image1.getDownloadUrl({
       'scale': 30,
       'crs': 'EPSG:4326',
       'region': '[[-120, 35], [-119, 35], [-119, 34], [-120, 34]]'
    })
    # 获取下载地址
    print(path)
    
  • 相关阅读:
    URAL 1998 The old Padawan 二分
    URAL 1997 Those are not the droids you're looking for 二分图最大匹配
    URAL 1995 Illegal spices 贪心构造
    URAL 1993 This cheeseburger you don't need 模拟题
    URAL 1992 CVS
    URAL 1991 The battle near the swamp 水题
    Codeforces Beta Round #92 (Div. 1 Only) A. Prime Permutation 暴力
    Codeforces Beta Round #7 D. Palindrome Degree hash
    Codeforces Beta Round #7 C. Line Exgcd
    Codeforces Beta Round #7 B. Memory Manager 模拟题
  • 原文地址:https://www.cnblogs.com/wszhang/p/11372485.html
Copyright © 2011-2022 走看看