source: trunk/src/get_erai.py @ 178

Last change on this file since 178 was 176, checked in by pinsard, 12 years ago

parametrization of era-i new utility

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