-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathGetRfeData.py
87 lines (79 loc) · 3.22 KB
/
GetRfeData.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
##Download FEWS-RFE data=name
##Budyko=group
##ParameterFile|dst_folder|Select precipitation folder|True|False
##ParameterString|start_date|Start date [yyyymmdd]. Must be after 20010101.|20130101|False
##ParameterString|end_date|End date [yyyymmdd]. For dates older than a year, the whole year will be downloaded.|20130101|False
##*ParameterExtent|subset_extent|Subset to download. Leave default value to download African dataset.|0,1,0,1
import os
import sys
from datetime import date, datetime
from processing.core.GeoAlgorithmExecutionException import (
GeoAlgorithmExecutionException,
)
if not os.path.dirname(scriptDescriptionFile) in sys.path:
sys.path.append(os.path.dirname(scriptDescriptionFile))
import DownloadRfeClimateData
if os.path.isdir(dst_folder):
# Creating log file
with open(os.path.join(dst_folder, "Download_log.txt"), "w") as log_file:
# Write current date to log file
now = date.today()
log_file.write("Run: " + now.strftime("%Y%m%d") + "\n")
log_file.write("Data source: FEWS-RFE\n")
# Get dates
try:
start_date = datetime.strptime(start_date, "%Y%m%d").date()
except ValueError:
raise GeoAlgorithmExecutionException(
'Error in data format: "' + start_date + '". Must be in YYYYMMDD.'
)
try:
end_date = datetime.strptime(end_date, "%Y%m%d").date()
except ValueError:
raise GeoAlgorithmExecutionException(
"Error in data format: " + end_date + '". Must be in YYYYMMDD.'
)
number_of_iterations = float((end_date.year - start_date.year + 1) * 3)
# Download, extract and translate to GeoTIFF
iteration = 0
for year in range(start_date.year, end_date.year + 1):
progress.setConsoleInfo(
"Downloading and extracting RFE precipitation data for "
+ str(year)
+ "..."
)
if year == now.year:
if start_date < date(now.year, 1, 1):
iteration = DownloadRfeClimateData.RfeImportDays(
date(year, 1, 1),
end_date,
dst_folder,
log_file,
progress,
iteration,
number_of_iterations,
subset_extent,
)
else:
iteration = DownloadRfeClimateData.RfeImportDays(
start_date,
end_date,
dst_folder,
log_file,
progress,
iteration,
number_of_iterations,
subset_extent,
)
else:
iteration = DownloadRfeClimateData.RfeImportYear(
year,
dst_folder,
log_file,
progress,
iteration,
number_of_iterations,
subset_extent,
)
else:
raise GeoAlgorithmExecutionException('No such directory: "' + dst_folder + '" ')