问题
I have downloaded grib1
model data from GFS, I am using a Mac OS X and was able to build the wgrib2
file from NOAA but was unable to extract the data. I have not found a grib1
utility for MAC.
Then I run to this program http://www.giss.nasa.gov/tools/panoply/ that was able to read the file and can see the data but I have some issues with it.
- the values comes in other units (like K for temp and other different from mm in rainfall)
- I am able to export
CSV
but only the values not the coordinates
What I want to do is :
- extract data from grib file via the command line via latitude longitude
- extract data an move to a
MySQL
database to be able to do some data aggregation (sum, max, min) etc - be able to plot / map data (I would probably use CartoDB service)
I already can extract grib
or can download from certain region, I would like that data to be able to see on a spreadsheet for example latitude, longitude, temperature, rainfall, wind etc... then from there I can take it to a database, or sum /avg etc or manipulate data.
Sample grib
data file: https://dl.dropboxusercontent.com/u/104462/neavilag_rain_wind_pressure.grb
Based on my scenario what is the best approach to handle my needs? Can you suggest me what to do?
回答1:
I recommend to use cfgrib which is a python based grib reader based on python project xarray
and the eccodes
software by the ECMWF.
It is very easy to use:
import cfgrib
cfgrib.open_datasets('your_grib_data.grib2')
And xarray comes with a lot of helpful built-in functions. Have fun!
回答2:
If I do this kind of manipulation I usually use CDO, as it handles all kinds of native grids correctly. If you want to calculate the sum or mean of a field over a certain area for example, it is not correct to simply calculate the arithmetic mean with a regular lat-lon or reduced Gaussian grid as it does not account account for the changing grid-cell sizes as you move towards the poles.
I would therefore select an area with
cdo -f nc sellonlatbox,lon1,lon2,lat1,lat2 in.grb out.nc
Here I am converting to netcdf at the same time with the "-f nc" option. Many software packages read netcdf easily to create plots (ncl, gdl/idl, grads, R, python, panoply etc etc).
To calculate field statistics for the files it is as straightforward as
cdo fldmean in.nc out.nc
cdo fldmax in.nc out.nc
cdo fldsum in.nc out.nc
To give some of the examples you request. You may also make stats in the time dimension (timmean etc). Check out the CDO help pages for details. I installed CDO on my MAC using macports.
来源:https://stackoverflow.com/questions/27782574/extract-data-from-grib-weather-model