Changeset 176


Ignore:
Timestamp:
03/22/12 15:17:20 (12 years ago)
Author:
pinsard
Message:

parametrization of era-i new utility

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/get_erai.py

    r109 r176  
    22# -*- coding: iso-8859-1 -*- 
    33 
     4__docformat__ = "restructuredtext en" 
     5__version__ = '$Id$' 
     6 
    47""" 
    58 
     
    710=========== 
    811 
    9 get ERA-Interim reference files 
     12get ERA-Interim reference files between two dates 
    1013 
    1114SYNOPSIS 
     
    1417:: 
    1518 
    16  $ python get_erai.py 
    17  
     19 $ get_erai.py --begin yyyymmdd --end yyyymmdd 
     20 
     21EXAMPLES 
     22======== 
     23 
     24:: 
     25 
     26 $ get_erai.py --verbose --begin 20010101 --end 20010330 
    1827 
    1928SEE ALSO 
     
    2231:ref:`ecmwf` 
    2332 
     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 
    2446TIPS 
    2547==== 
    2648 
    2749To convet a GRIB file to a NetCDF file :: 
    28   
     50 
    2951  $ cdo -f nc copy data.grib data.nc 
    3052 
     
    3254==== 
    3355 
    34 make it work for all needed variables  
     56make it work for all needed variables 
    3557 
    3658produce netcdf files : now grib dispite name of the file target 
    3759 
    3860comment 
     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é. 
    3965 
    4066EVOLUTIONS 
     
    4571$URL$ 
    4672 
     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 
    4783- fplod 20111130T153500Z cratos (Linux) 
    4884 
     
    5288""" 
    5389 
     90import os 
     91from optparse import OptionParser 
     92import time 
     93import datetime 
     94from dateutil.parser import * 
     95 
    5496from ecmwf import ECMWFDataServer 
    5597 
    56 server = ECMWFDataServer( 
    57        'http://data-portal.ecmwf.int/data/d/dataserver/', 
    58               'd558d095ce964389eeda5e908e9462f3', 
    59              'francoise.pinsard@locean-ipsl.upmc.fr' 
    60          ) 
    61  
    62 server.retrieve({ 
    63     'dataset' : "interim_full_daily", 
    64     'date'    : "19790101/to/19790110", 
    65     'time'    : "00:00:00/06:00:00/12:00:00/18:00:00", 
    66     'grid'    : "1/1", 
    67     'step'    : "0", 
    68     'levtype' : "sfc", 
    69     'type'    : "an", 
    70     'param'   : "167.128", 
    71     'area'    : "60/-120/30/-60", 
    72     'target'  : "t2m.nc" 
    73         }) 
     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 TracChangeset for help on using the changeset viewer.