DataAccess.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:wa 作者: wateraccounting 项目源码 文件源码
def Download_ETens_from_WA_FTP(output_folder, Lat_tiles, Lon_tiles):           
    """
    This function retrieves ETensV1.0 data for a given date from the
    ftp.wateraccounting.unesco-ihe.org server.

    Restrictions:
    The data and this python file may not be distributed to others without
    permission of the WA+ team.

    Keyword arguments:
    output_folder -- Directory of the outputs
    Lat_tiles -- [Lat_min, Lat_max] Tile number of the max and min latitude tile number
    Lon_tiles -- [Lon_min, Lon_max] Tile number of the max and min longitude tile number                
    """      
    for v_tile in range(Lat_tiles[0], Lat_tiles[1]+1):
        for h_tile in range(Lon_tiles[0], Lon_tiles[1]+1):                                                  

            Tilename = "h%sv%s.zip" %(h_tile, v_tile)
            if not os.path.exists(os.path.join(output_folder,Tilename)): 
                try:  
                    # Collect account and FTP information           
                    username, password = WebAccounts.Accounts(Type = 'FTP_WA')
                    FTP_name = "ftp://ftp.wateraccounting.unesco-ihe.org//WaterAccounting_Guest/ETensV1.0/%s" % Tilename
                    local_filename = os.path.join(output_folder, Tilename)   

                    # Download data from FTP    
                    curl = pycurl.Curl()
                    curl.setopt(pycurl.URL, FTP_name)   
                    curl.setopt(pycurl.USERPWD, '%s:%s' %(username, password))                              
                    fp = open(local_filename, "wb")                              
                    curl.setopt(pycurl.WRITEDATA, fp)
                    curl.perform()
                    curl.close()
                    fp.close()  

                except:
                    print "tile %s is not found and will be replaced by NaN values" % Tilename

    return()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号