[180] | 1 | def 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"] |
---|
[558] | 9 | elif var == "78": name="Total column liquid water (kg/kg)" |
---|
[273] | 10 | elif var == "137": name="Total column water vapour (kg/m2)" |
---|
[599] | 11 | elif var == "189": name="Sunshine duration (s)" |
---|
| 12 | elif var == "228": name="Total precipitation (m)" |
---|
[558] | 13 | else: name="" |
---|
[180] | 14 | return name |
---|
| 15 | |
---|
| 16 | def split_char_add (var,add): |
---|
| 17 | import numpy as np |
---|
| 18 | varchar = "" |
---|
| 19 | for i in range( np.array(var).size ): |
---|
| 20 | varchar = varchar + str(var[i]) + add + "/" |
---|
| 21 | return varchar |
---|
| 22 | |
---|
| 23 | def split_char (var): |
---|
| 24 | varchar = split_char_add (var,"") |
---|
| 25 | return varchar |
---|
| 26 | |
---|
[558] | 27 | def get_ecmwf (var, fieldtype, wlat, wlon, lev, date, tim): |
---|
[180] | 28 | from ecmwf import ECMWFDataServer |
---|
| 29 | from os import system |
---|
| 30 | from netCDF4 import Dataset |
---|
| 31 | gbfile = 'output.grib' |
---|
[558] | 32 | #ncfile = str(date[2]) + str(date[1]) + str(date[0]) + str(date[5]) + str(date[4]) + str(date[3])+'.nc' |
---|
| 33 | ncfile = 'output.nc' |
---|
| 34 | ###### |
---|
| 35 | if fieldtype == "3d": |
---|
| 36 | dataset = ["an","pl","0"] |
---|
| 37 | elif fieldtype == "2d": |
---|
| 38 | dataset = ["fc","sfc","3"] |
---|
| 39 | lev = [9999.] |
---|
[180] | 40 | ###### |
---|
| 41 | timchar = split_char (tim) |
---|
| 42 | levchar = split_char (lev) |
---|
| 43 | varchar = split_char_add (var,".128") |
---|
| 44 | ########################################################################## |
---|
| 45 | ## First registrer at http://data-portal.ecmwf.int/data/d/license/interim/ |
---|
| 46 | ## Then get your token at http://data-portal.ecmwf.int/data/d/token/interim_daily/ |
---|
| 47 | server = ECMWFDataServer('http://data-portal.ecmwf.int/data/d/dataserver/','6948746482e9e3e29d64211e06329a2e','spiga@lmd.jussieu.fr') |
---|
| 48 | server.retrieve({ |
---|
| 49 | 'dataset' : "interim_daily", |
---|
| 50 | 'date' : date[2] + date[1] + date[0] + "/to/" + date[5] + date[4] + date[3], |
---|
| 51 | 'time' : timchar, |
---|
| 52 | 'step' : dataset[2], |
---|
| 53 | 'levtype' : dataset[1], |
---|
| 54 | 'type' : dataset[0], |
---|
| 55 | 'param' : varchar, |
---|
| 56 | 'levelist' : levchar, |
---|
| 57 | 'area' : str(wlat[0])+"/"+str(wlon[0])+"/"+str(wlat[1])+"/"+str(wlon[1]), |
---|
| 58 | 'target' : gbfile |
---|
| 59 | }) |
---|
| 60 | system("cdo -f nc copy "+gbfile+" "+ncfile+" ; rm -f "+gbfile) |
---|
| 61 | nc = Dataset(ncfile) |
---|
| 62 | #system("rm -f "+ncfile) |
---|
| 63 | return nc |
---|