-
Notifications
You must be signed in to change notification settings - Fork 0
/
NCEP_DownloadNCF.py
63 lines (47 loc) · 1.94 KB
/
NCEP_DownloadNCF.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import sys
import datetime as dt
import time
from ftplib import FTP
import subprocess
import glob
import os
def logToFile (text):
with open("NWIO.log", 'a') as logfile:
logfile.write("%s\n"%text)
return "%s"%text;
def printDT():
dtt = dt.datetime.now()
dtt = "%04i-%02i-%02i_%02i-%02i-%02i" % (dtt.year,dtt.month,dtt.day,dtt.hour,dtt.minute,dtt.second)
return dtt;
class DownloadGrib:
def __init__(self, file_dates): # hours_hindcast = 18; hours_forecast = 180
logToFile("\n\n=== DONWLOAD NETCDF ===") # log to file
# === DOWNLOAD ===
logToFile("%s: Starting download" % printDT()) # log to file
readDates = open(file_dates, 'r').readlines()
print readDates
for dates in readDates:
r = 1
while r != -1:
try:
print "Y"
'''
ftp = FTP('polar.ncep.noaa.gov')
print "Connected | Downloading files"
ftp.login() # user anon, passw anon
'''
ftpfolder = 'pub/history/nopp-phase2/%s/partitions/' % dates.split()[0]
filename = "multi_reanal.partition.nwio_10m.%s.nc" % dates.split()[0]
#filename = "multi_reanal.partition.aoc_15m.%s.nc" % dates.split()[0]
print logToFile("%s%s" %(ftpfolder, filename))
'''
ftp.cwd(ftpfolder) #change dir
ftp.retrbinary('RETR %s' % filename, open('NWIO\%s' % filename, 'wb').write)
print logToFile("File downloaded : NWIO\%s" % filename)
'''
r = -1
except:
print logToFile("Connection error, retrying...(%i)" % r)
time.sleep(5)
r += 1
DownloadGrib("dates.inp")