-
Notifications
You must be signed in to change notification settings - Fork 0
/
descarga.py
53 lines (46 loc) · 1.66 KB
/
descarga.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
""" This script downloads grib files of GEFS Model (NOAA).
Those files have a spatial resolution of 0.5 Degrees and
includes the mean and spread of the ensemble for the most
commonly used parameters.
Diego Quintero
2019"""
import urllib.request
import pdb
import rlcompleter
from datetime import datetime
import os
import numpy as np
pdb.Pdb.complete=rlcompleter.Completer(locals()).complete
date = datetime(2019,10,21)
days_for_download = 7
download_step_hours = 3
path = '/home/diego/Documentos/Pronosticos_Luker/'
# Create a folder for the downloaded data
try:
os.mkdir(path + date.strftime('%Y%m%d'))
print('Path ' + path + date.strftime('%Y%m%d'), ' Created')
except FileExistsError:
print('Path ' + date.strftime('%Y%m%d'), ' Already existed')
download_range = np.arange(0, days_for_download*24 + 7, download_step_hours)
# Ensemble avg and spr download
j = 0
for i in download_range:
total_files_to_download =len(download_range)
if i < 10:
i_str = '00' + str(i)
elif i < 100:
i_str = '0' + str(i)
else:
i_str = str(i)
for ens_est in ['avg', 'spr']:
url = 'ftp://ftp.ncep.noaa.gov/pub/data/nccf/com/gens/prod/gefs.' +\
date.strftime('%Y%m%d') + '/00/pgrb2ap5/ge' + ens_est + '.t00z.pgrb2a.0p50.f' + i_str
try:
urllib.request.urlretrieve(url, path
+ date.strftime('%Y%m%d') + '/' + url.split('/')[-1])
print(url + ' Done! ' + str(round(100*(((j + 1)/2)/total_files_to_download), 1)) + '% Downloaded')
except:
print('Error downloading!!')
pdb.set_trace()
break
j += 1