Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extract data from grib weather model

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.

  1. the values comes in other units (like K for temp and other different from mm in rainfall)
  2. I am able to export CSV but only the values not the coordinates

What I want to do is :

  1. extract data from grib file via the command line via latitude longitude
  2. extract data an move to a MySQL database to be able to do some data aggregation (sum, max, min) etc
  3. 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?

like image 831
neavilag Avatar asked Jan 05 '15 15:01

neavilag


2 Answers

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!

like image 102
dl.meteo Avatar answered Oct 05 '22 20:10

dl.meteo


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.

like image 38
Adrian Tompkins Avatar answered Oct 05 '22 21:10

Adrian Tompkins