-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy patheriscripts2.py
237 lines (217 loc) · 6.81 KB
/
eriscripts2.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# This Python file uses the following encoding: utf-8
from multiprocessing import Pool
from threading import Thread
from ecmwfapi import ECMWFDataServer
from time import time
import datetime
import calendar
import os
#https://blog.csdn.net/seetheworld518/article/details/49639651
def downloadonefile(riqi):
ts = time()
print(riqi)
return
filename="/mnt/HD/HD_a2/Public/ERA-Interim/SURF/u10/u10."+riqi+".grb"
if(os.path.isfile(filename)): #如果存在文件名则返回
print("ok",filename)
else:
server = ECMWFDataServer()
server.retrieve({
"class": "ei",
"dataset": "interim",
"date": riqi,
"expver": "1",
"grid": "0.75/0.75",
"levtype": "sfc",
"param": "165.128", #u10
"step": "0",
"stream": "oper",
"time": "00:00:00/06:00:00/12:00:00/18:00:00",
"type": "an",
"target": filename,
})
filename="/mnt/HD/HD_a2/Public/ERA-Interim/SURF/v10/v10."+riqi+".grb"
if(os.path.isfile(filename)): #如果存在文件名则返回
print("ok",filename)
else:
server = ECMWFDataServer()
server.retrieve({
"class": "ei",
"dataset": "interim",
"date": riqi,
"expver": "1",
"grid": "0.75/0.75",
"levtype": "sfc",
"param": "166.128", #v10
"step": "0",
"stream": "oper",
"time": "00:00:00/06:00:00/12:00:00/18:00:00",
"type": "an",
"target": filename,
})
filename="/mnt/HD/HD_a2/Public/ERA-Interim/SURF/2t/2t."+riqi+".grb"
if(os.path.isfile(filename)): #如果存在文件名则返回
print("ok",filename)
else:
server = ECMWFDataServer()
server.retrieve({
"class": "ei",
"dataset": "interim",
"date": riqi,
"expver": "1",
"grid": "0.75/0.75",
"levelist": "1000/975/950/925/900/875/850/825/800/775/750/700/650/600/550/500/450/400/350/300/250/225/200/175/150/125/100/70",
"levtype": "sfc",
"param": "167.128", #2m气温
"step": "0",
"stream": "oper",
"time": "00:00:00/06:00:00/12:00:00/18:00:00",
"type": "an",
"target": filename,
})
filename="/mnt/HD/HD_a2/Public/ERA-Interim/SURF/sst/sst."+riqi+".grb"
if(os.path.isfile(filename)): #如果存在文件名则返回
print("ok",filename)
else:
server = ECMWFDataServer()
server.retrieve({
"class": "ei",
"dataset": "interim",
"date": riqi,
"expver": "1",
"grid": "0.75/0.75",
"levtype": "sfc",
"param": "34.128", #sst
"step": "0",
"stream": "oper",
"time": "00:00:00/06:00:00/12:00:00/18:00:00",
"type": "an",
"target": filename,
})
filename="/mnt/HD/HD_a2/Public/ERA-Interim/SURF/sp/sp."+riqi+".grb"
if(os.path.isfile(filename)): #如果存在文件名则返回
print("ok",filename)
else:
server = ECMWFDataServer()
server.retrieve({
"class": "ei",
"dataset": "interim",
"date": riqi,
"expver": "1",
"grid": "0.75/0.75",
"levelist": "1000/975/950/925/900/875/850/825/800/775/750/700/650/600/550/500/450/400/350/300/250/225/200/175/150/125/100/70",
"levtype": "sfc",
"param": "134.128", #Surface pressure
"step": "0",
"stream": "oper",
"time": "00:00:00/06:00:00/12:00:00/18:00:00",
"type": "an",
"target": filename,
})
filename="/mnt/HD/HD_a2/Public/ERA-Interim/SURF/mslp/mslp."+riqi+".grb"
if(os.path.isfile(filename)): #如果存在文件名则返回
print("ok",filename)
else:
server = ECMWFDataServer()
server.retrieve({
"class": "ei",
"dataset": "interim",
"date": riqi,
"expver": "1",
"grid": "0.75/0.75",
"levtype": "sfc",
"param": "151.128", #mslp
"step": "0",
"stream": "oper",
"time": "00:00:00/06:00:00/12:00:00/18:00:00",
"type": "an",
"target": filename,
})
filename="/mnt/HD/HD_a2/Public/ERA-Interim/SURF/tcw/tcw."+riqi+".grb"
if(os.path.isfile(filename)): #如果存在文件名则返回
print("ok",filename)
else:
server = ECMWFDataServer()
server.retrieve({
"class": "ei",
"dataset": "interim",
"date": riqi,
"expver": "1",
"grid": "0.75/0.75",
"levtype": "sfc",
"param": "136.128", #tcw
"step": "0",
"stream": "oper",
"time": "00:00:00/06:00:00/12:00:00/18:00:00",
"type": "an",
"target": filename,
})
filename="/mnt/HD/HD_a2/Public/ERA-Interim/SURF/tcwv/tcwv."+riqi+".grb"
if(os.path.isfile(filename)): #如果存在文件名则返回
print("ok",filename)
else:
server = ECMWFDataServer()
server.retrieve({
"class": "ei",
"dataset": "interim",
"date": riqi,
"expver": "1",
"grid": "0.75/0.75",
"levtype": "sfc",
"param": "137.128", #tcwv
"step": "0",
"stream": "oper",
"time": "00:00:00/06:00:00/12:00:00/18:00:00",
"type": "an",
"target": filename,
})
filename="/mnt/HD/HD_a2/Public/ERA-Interim/SURF/cape/cape."+riqi+".grb"
if(os.path.isfile(filename)): #如果存在文件名则返回
print("ok",filename)
else:
server = ECMWFDataServer()
server.retrieve({
"class": "ei",
"dataset": "interim",
"date": riqi,
"expver": "1",
"grid": "0.75/0.75",
"levtype": "sfc",
"param": "59.128", #cape
"step": "3/6/9/12",
"stream": "oper",
"time": "00:00:00/12:00:00",
"type": "fc",
"target": filename,
})
#主程序
def main():
#起始时间
ts = time()
nowyear=datetime.datetime.now().year
nowmonth=datetime.datetime.now().month
nowfirstdaymonth=datetime.date(nowyear,nowmonth,1) #本月1号
## print(nowfirstdaymonth)
pretime=nowfirstdaymonth-datetime.timedelta(days=70)#大约调到三个月前
preyear=pretime.year
premonth=pretime.month
## print (pretime)
premonthrange=calendar.monthrange(preyear,premonth)[1] #返回该月一共多少天
#起始日期
begin = datetime.date(preyear,premonth,1)
end = datetime.date(preyear,premonth,premonthrange)
d=begin
delta = datetime.timedelta(days=1)
#建立下载日期序列
links = []
while d <= end:
riqi=d.strftime("%Y%m%d")
links.append(str(riqi))
d += delta
pool = Pool(5) # 创建拥有5个进程数量的进程池
rl=pool.map(downloadonefile,links)
pool.close()#关闭进程池,不再接受新的进程
pool.join()#主进程阻塞等待子进程的退出
print('Took {}'.format(time() - ts))
if __name__ == '__main__':
main()