Exemplo n.º 1
0
def getDailyDataFromFTP(localPath, datesList=[]):
    dailyDir = "pub/org/chg/products/CHIRPS-2.0/global_daily/tifs/p25/"
    chirpsBaseName = "chirps-v2.0."
    chirpsExt = ".tif.gz"
    # if have dates, only get those files
    if not datesList:
        # get all files not already in localPath
        getFilesFromFTP(ftp_address_NDVI, "anonymous", "anonymous@", dailyDir, localPath)
    else:
        sd = datesList[0]
        ed = datesList[1]
        ftp = None
        try:
            ftp = FTP(ftp_address_NDVI)
        except:
            print ("Error connecting to server ", ftp_address_NDVI)
        ftp.login("anonymous", "anonymous@")

        while sd <= ed:
            yrs = "{0}".format(sd.year)
            yrDir = path.join(dailyDir, yrs)
            fname = sd.strftime("chirps-v2.0.%Y.%m.%d.tif.gz")
            print "Looking for: ", fname, " in ", yrDir
            localFile = path.join(localPath, fname)
            fileObj = open(localFile, "wb")
            # try to find file in directory
            fn = yrDir + "/" + fname
            # Download the file a chunk at a time using RETR
            ftp.retrbinary("RETR " + fn, fileObj.write)
            # Close the file
            fileObj.close()
            print "retreived ", localFile

            sd = sd + timedelta(days=1)
        ftp.close()
    return 0
Exemplo n.º 2
0
def getMonthlyDataFromFTP(localPath):
    monthlyDir = "pub/org/chg/products/CHIRPS-2.0/global_monthly/tifs/"
    getFilesFromFTP(ftp_address_NDVI, "anonymous", "anonymous@", monthlyDir, localPath)
    return 0
Exemplo n.º 3
0
def getPentadDataFromFTP(localPath):
    pentadDir = "pub/org/chg/products/CHIRPS-2.0/global_pentad/tifs/"
    getFilesFromFTP(ftp_address_NDVI, "anonymous", "anonymous@", pentadDir, localPath)
    return 0