[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"] |
---|
| 9 | return name |
---|
| 10 | |
---|
| 11 | def split_char_add (var,add): |
---|
| 12 | import numpy as np |
---|
| 13 | varchar = "" |
---|
| 14 | for i in range( np.array(var).size ): |
---|
| 15 | varchar = varchar + str(var[i]) + add + "/" |
---|
| 16 | return varchar |
---|
| 17 | |
---|
| 18 | def split_char (var): |
---|
| 19 | varchar = split_char_add (var,"") |
---|
| 20 | return varchar |
---|
| 21 | |
---|
| 22 | def get_ecmwf (var, dataset, wlat, wlon, lev, date, tim): |
---|
| 23 | from ecmwf import ECMWFDataServer |
---|
| 24 | from os import system |
---|
| 25 | from netCDF4 import Dataset |
---|
| 26 | gbfile = 'output.grib' |
---|
| 27 | ncfile = 'output.nc' |
---|
| 28 | ###### |
---|
| 29 | timchar = split_char (tim) |
---|
| 30 | levchar = split_char (lev) |
---|
| 31 | varchar = split_char_add (var,".128") |
---|
| 32 | ########################################################################## |
---|
| 33 | ## First registrer at http://data-portal.ecmwf.int/data/d/license/interim/ |
---|
| 34 | ## Then get your token at http://data-portal.ecmwf.int/data/d/token/interim_daily/ |
---|
| 35 | server = ECMWFDataServer('http://data-portal.ecmwf.int/data/d/dataserver/','6948746482e9e3e29d64211e06329a2e','spiga@lmd.jussieu.fr') |
---|
| 36 | server.retrieve({ |
---|
| 37 | 'dataset' : "interim_daily", |
---|
| 38 | 'date' : date[2] + date[1] + date[0] + "/to/" + date[5] + date[4] + date[3], |
---|
| 39 | 'time' : timchar, |
---|
| 40 | 'step' : dataset[2], |
---|
| 41 | 'levtype' : dataset[1], |
---|
| 42 | 'type' : dataset[0], |
---|
| 43 | 'param' : varchar, |
---|
| 44 | 'levelist' : levchar, |
---|
| 45 | 'area' : str(wlat[0])+"/"+str(wlon[0])+"/"+str(wlat[1])+"/"+str(wlon[1]), |
---|
| 46 | 'target' : gbfile |
---|
| 47 | }) |
---|
| 48 | system("cdo -f nc copy "+gbfile+" "+ncfile+" ; rm -f "+gbfile) |
---|
| 49 | nc = Dataset(ncfile) |
---|
| 50 | #system("rm -f "+ncfile) |
---|
| 51 | return nc |
---|