source: trunk/UTIL/PYTHON/myecmwf.py @ 579

Last change on this file since 579 was 558, checked in by aslmd, 13 years ago

UTIL PYTHON: moved corrected ECMWF stuff for simple use in the main PYTHON directory. corrected planetoplot so that output files from ECMWF can be used. added a more general treatment of lat/lon prescription.

  • Property svn:executable set to *
File size: 2.5 KB
Line 
1def ecmwf_title_field (var):
2        ### http://www.ecmwf.int/services/archive/d/table/grib_table_2_versions
3        ### http://www.ecmwf.int/services/archive/d/parameters/mars=1/order=grib_parameter/table=128/
4        ### http://www.atmos.albany.edu/facstaff/rmctc/ecmwfGrib/ecmwfgrib128.tbl
5        if   var == "151": name="Mean Sea Level Pressure (Pa)"          # ["151", "fc", "3", "sfc"]
6        elif var == "146": name="Sensible Heat Flux (W m^-2)"           # ["146", "fc", "3", "sfc"]
7        elif var == "130": name="Atmospheric Temperature (K)"           # ["130", "an", "0", "pl" ]
8        elif var == "167": name="2m Atmospheric Temperature (K)"        # ["167", "fc", "3", "sfc"]
9        elif var == "78":  name="Total column liquid water (kg/kg)"
10        elif var == "137": name="Total column water vapour (kg/m2)"
11        else:              name=""
12        return name
13
14def split_char_add (var,add):
15        import  numpy as np
16        varchar = ""
17        for i in range( np.array(var).size ):
18                varchar = varchar + str(var[i]) + add + "/"
19        return varchar
20
21def split_char (var):
22        varchar = split_char_add (var,"")
23        return varchar
24
25def get_ecmwf (var, fieldtype, wlat, wlon, lev, date, tim):
26        from ecmwf      import ECMWFDataServer
27        from os         import system
28        from netCDF4    import Dataset
29        gbfile = 'output.grib'
30        #ncfile = str(date[2]) + str(date[1]) + str(date[0]) + str(date[5]) + str(date[4]) + str(date[3])+'.nc'
31        ncfile = 'output.nc'
32        ######
33        if fieldtype == "3d":   
34            dataset = ["an","pl","0"]
35        elif fieldtype == "2d": 
36            dataset = ["fc","sfc","3"]
37            lev = [9999.]
38        ######
39        timchar = split_char (tim)
40        levchar = split_char (lev)
41        varchar = split_char_add (var,".128")
42        ##########################################################################
43        ## First registrer at http://data-portal.ecmwf.int/data/d/license/interim/
44        ## Then get your token at http://data-portal.ecmwf.int/data/d/token/interim_daily/
45        server = ECMWFDataServer('http://data-portal.ecmwf.int/data/d/dataserver/','6948746482e9e3e29d64211e06329a2e','spiga@lmd.jussieu.fr')
46        server.retrieve({
47                'dataset'  : "interim_daily",
48                'date'     : date[2] + date[1] + date[0] + "/to/" + date[5] + date[4] + date[3],
49                'time'     : timchar,
50                'step'     : dataset[2],
51                'levtype'  : dataset[1],
52                'type'     : dataset[0],
53                'param'    : varchar,
54                'levelist' : levchar,   
55                'area'     : str(wlat[0])+"/"+str(wlon[0])+"/"+str(wlat[1])+"/"+str(wlon[1]),
56                'target'   : gbfile
57        })
58        system("cdo -f nc copy "+gbfile+" "+ncfile+" ; rm -f "+gbfile)
59        nc = Dataset(ncfile)
60        #system("rm -f "+ncfile)
61        return nc
Note: See TracBrowser for help on using the repository browser.