1 | #!/usr/bin/env python |
---|
2 | # -*- coding: utf-8 -*- |
---|
3 | |
---|
4 | __docformat__ = "restructuredtext en" |
---|
5 | __version__ = '$Id$' |
---|
6 | |
---|
7 | """ |
---|
8 | |
---|
9 | DESCRIPTION |
---|
10 | =========== |
---|
11 | |
---|
12 | get ERA-Interim reference files between two dates |
---|
13 | |
---|
14 | SYNOPSIS |
---|
15 | ======== |
---|
16 | |
---|
17 | .. code-block:: bash |
---|
18 | |
---|
19 | get_erai.py --begin yyyymmdd --end yyyymmdd |
---|
20 | |
---|
21 | EXAMPLES |
---|
22 | ======== |
---|
23 | |
---|
24 | .. code-block:: bash |
---|
25 | |
---|
26 | get_erai.py --verbose --begin 20010101 --end 20010330 |
---|
27 | |
---|
28 | SEE ALSO |
---|
29 | ======== |
---|
30 | |
---|
31 | :ref:`ecmwf` |
---|
32 | |
---|
33 | for interactif retrieval |
---|
34 | http://data-portal.ecmwf.int/data/d/interim_daily/ |
---|
35 | |
---|
36 | http://data-portal.ecmwf.int/data/d/interim_full_daily |
---|
37 | |
---|
38 | For python script syntax |
---|
39 | http://data-portal.ecmwf.int/data/d/token/interim_daily/ |
---|
40 | |
---|
41 | "Please note that these batch scripts are available for download in grib format only. " ... |
---|
42 | |
---|
43 | MARS language |
---|
44 | http://www.ecmwf.int/publications/manuals/mars/guide/index.html |
---|
45 | |
---|
46 | TIPS |
---|
47 | ==== |
---|
48 | |
---|
49 | To convert a GRIB file to a NetCDF file : |
---|
50 | |
---|
51 | .. code-block:: bash |
---|
52 | |
---|
53 | cdo -f nc copy data.grib data.nc |
---|
54 | |
---|
55 | TODO |
---|
56 | ==== |
---|
57 | |
---|
58 | make it work for all needed variables |
---|
59 | |
---|
60 | produce netcdf files : now grib despite name of the file target |
---|
61 | |
---|
62 | comment |
---|
63 | |
---|
64 | nb : le champ str (wind stress pourra/devra être récupéré pour faire des comparaisons (cf. 20c3m_erai_str_TROP_1989_2009.nc) |
---|
65 | |
---|
66 | nb :Mean sea level pressure en a-t-on vraiment besoin ? jusqu'à présent on ne sait pas si pkb l'a utilisé. |
---|
67 | |
---|
68 | EVOLUTIONS |
---|
69 | ========== |
---|
70 | |
---|
71 | $Id$ |
---|
72 | |
---|
73 | $URL$ |
---|
74 | |
---|
75 | - fplod 20120314 |
---|
76 | |
---|
77 | * add parameters |
---|
78 | |
---|
79 | - fplod 20120306 |
---|
80 | |
---|
81 | * add all param for analyse (it might be better to do a loop to produce |
---|
82 | one file/field |
---|
83 | * add retrieve for forecast (only one parameter here) |
---|
84 | |
---|
85 | - fplod 20111130T153500Z cratos (Linux) |
---|
86 | |
---|
87 | * got from http://data-portal.ecmwf.int/data/d/token/interim_full_daily/ |
---|
88 | * add docstring |
---|
89 | |
---|
90 | """ |
---|
91 | |
---|
92 | import os |
---|
93 | from optparse import OptionParser |
---|
94 | import time |
---|
95 | import datetime |
---|
96 | from dateutil.parser import * |
---|
97 | |
---|
98 | from ecmwf import ECMWFDataServer |
---|
99 | |
---|
100 | def get_option_parser (): |
---|
101 | """parse CLI arguments |
---|
102 | |
---|
103 | :returns: parser |
---|
104 | :rtype: :class:`optparse.OptionParser` |
---|
105 | """ |
---|
106 | |
---|
107 | parser = OptionParser('%prog [--verbose] --begin yyyymmdd --end yyymmdd ') |
---|
108 | |
---|
109 | parser = OptionParser(conflict_handler="resolve") |
---|
110 | |
---|
111 | parser.add_option ('-V', '--verbose', help='produce verbose output', |
---|
112 | action='store_true', |
---|
113 | default=False, |
---|
114 | dest='is_verbose') |
---|
115 | |
---|
116 | parser.add_option('--version', |
---|
117 | action='store_true', |
---|
118 | dest='version', |
---|
119 | help='show version number and exit') |
---|
120 | |
---|
121 | parser.add_option('--begin', |
---|
122 | help='date (yyyymmdd) of the first date', |
---|
123 | dest='yyyymmddb', |
---|
124 | action='store') |
---|
125 | |
---|
126 | parser.add_option('--end', |
---|
127 | help='date (yyyymmdd) of the last date', |
---|
128 | dest='yyyymmdde', |
---|
129 | action='store') |
---|
130 | |
---|
131 | return parser |
---|
132 | |
---|
133 | def get_erai(): |
---|
134 | """main |
---|
135 | """ |
---|
136 | try: |
---|
137 | parser = get_option_parser () |
---|
138 | (fromcli, args) = parser.parse_args() |
---|
139 | except IOError, msg: |
---|
140 | parser.error(str(msg)) |
---|
141 | |
---|
142 | yyyymmddb = parse(fromcli.yyyymmddb, ignoretz=True) |
---|
143 | yyyymmdde = parse(fromcli.yyyymmdde, ignoretz=True) |
---|
144 | |
---|
145 | # ++ check date validity and interval validity |
---|
146 | if fromcli.is_verbose == True: |
---|
147 | print ('yyyymmddb %s' % (yyyymmddb)) |
---|
148 | print ('yyyymmdde %s' % (yyyymmdde)) |
---|
149 | |
---|
150 | # build the value of date parameter yyyymmdd/to/yyyymmdd |
---|
151 | date_param = fromcli.yyyymmddb + '/to/' + fromcli.yyyymmdde |
---|
152 | |
---|
153 | if fromcli.is_verbose == True: |
---|
154 | print ('date for erai %s' % (date_param)) |
---|
155 | |
---|
156 | server = ECMWFDataServer( |
---|
157 | 'http://data-portal.ecmwf.int/data/d/dataserver/', |
---|
158 | 'd558d095ce964389eeda5e908e9462f3', |
---|
159 | 'Francoise.Pinsard@locean-ipsl.upmc.fr' |
---|
160 | ) |
---|
161 | |
---|
162 | # Pour les analyses de |
---|
163 | # 10 metre U wind component |
---|
164 | # 10 metre V wind component |
---|
165 | # 2 metre temperature |
---|
166 | # 2 metre dewpoint temperature |
---|
167 | # Sea surface temperature |
---|
168 | # Mean sea level pressure |
---|
169 | param_param = [] |
---|
170 | param_param.append("34.128") #Sea surface temperature sstk |
---|
171 | #param_param.append("151.128") Mean sea level pressure |
---|
172 | #param_param.append("165.128") 10 metre U wind component u10 |
---|
173 | #param_param.append("166.128") 10 metre V wind component v10 |
---|
174 | #param_param.append("167.128") 2 metre temperature t2 |
---|
175 | #param_param.append("168.128") 2 metre dewpoint temperature d2 |
---|
176 | |
---|
177 | for one_param in param_param: |
---|
178 | |
---|
179 | if fromcli.is_verbose == True: |
---|
180 | print('recup de %s ' % one_param) |
---|
181 | |
---|
182 | server.retrieve({ |
---|
183 | 'dataset' : "interim_full_daily", |
---|
184 | 'date' : date_param, |
---|
185 | 'time' : "00:00:00/06:00:00/12:00:00/18:00:00", |
---|
186 | 'grid' : "1/1", |
---|
187 | 'step' : "0", |
---|
188 | 'levtype' : "sfc", |
---|
189 | 'type' : "an", |
---|
190 | 'param' : one_param, |
---|
191 | 'area' : "60/-120/30/-60", |
---|
192 | 'target' : "toto.grib" |
---|
193 | }) |
---|
194 | |
---|
195 | # Pour la "Surface thermal radiation downwards": |
---|
196 | param_param = [] |
---|
197 | param_param.append("175.128") # Surface thermal radiation downwards |
---|
198 | for one_param in param_param: |
---|
199 | |
---|
200 | if fromcli.is_verbose == True: |
---|
201 | print('recup de %s' % one_param) |
---|
202 | |
---|
203 | server.retrieve({ |
---|
204 | 'dataset' : "interim_full_daily", |
---|
205 | 'date' : date_param, |
---|
206 | 'time' : "00:00:00/12:00:00", |
---|
207 | 'grid' : "1/1", |
---|
208 | 'step' : "12", |
---|
209 | 'levtype' : "sfc", |
---|
210 | 'type' : "fc", |
---|
211 | 'param' : param_param, |
---|
212 | 'area' : "60/-120/30/-60", |
---|
213 | 'target' : "fc.grib" |
---|
214 | }) |
---|
215 | |
---|
216 | # Run main, if called from the command line |
---|
217 | if __name__ == '__main__': |
---|
218 | get_erai() |
---|
219 | |
---|