forked from insarlab/PyAPS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetecmwf.py
53 lines (47 loc) · 1.83 KB
/
getecmwf.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
############################################################
# Program is part of PyAPS #
# Copyright 2012, by the California Institute of Technology#
# Contact: earthdef@gps.caltech.edu #
# Modified by A. Benoit and R. Jolivet 2019 #
# Ecole Normale Superieure, Paris #
# Contact: insar@geologie.ens.fr #
############################################################
#!/usr/bin/python
from ecmwf import ECMWFDataServer
def getfiles(bdate,hr,filedir,model,humidity='Q')
server = ECMWFDataServer('https://api.ecmwf.int/v1',
'yourkey',
'youremailadress')
# Define dataset type
assert datatype in ('fc','an'), 'Unknown dataset type field for ECMWF'
if datatype in 'fc':
dstep = '6'
elif datatype in 'an':
dstep = '0'
# Define grid size according to weather model
assert model in ('era5','interim', 'hres'), 'Unknown model for ECMWF'
if model in 'era5':
gridsize = '0.3/0.3'
elif model in 'hres':
gridsize = '0.1/0.1'
elif model in 'interim':
gridsize = '0.75/0.75'
# Define humidity param
assert humidity in ('Q','R'), 'Unknown humidity field for ECMWF'
if humidity in 'Q':
humidparam = 133
elif humidity in 'R':
humidparam = 157
for day in bdate:
server.retrieve({
'dataset' : "%s"%(model),
'type' : "%s"%(datatype),
'date' : "%s"%(bdate),
'time' : "%s"%(hr),
'step' : "%s"%(dstep),
'levtype' : "pl",
'levelist' : "all",
'grid' : "%s"%(gridsize),
'param' : "129/130/%d"%(humidparam),
'target' : "%s/%s_%s_%s_%s.grb"%(fileloc,model,bdate,hr,datatype),
})