[GIS] Conversion of GRIB and NetCDF to the database

convertgribnetcdf

.

enter image description here

I have downloaded "High Resolution Initial Conditions" climate forecast data for one day, it was in extension .tar.gz so I extracted it in my local directory and I get the files like in the attached image.

I think, that the files without extension are GRIB data (because first word in them is "GRIB"). So i want to get data from the big files (GRIB and NetCDF formats containing climate data like temerature & pressure in grid) to my database, but they are binary.
Can you recommend me some easy way for getting data from these files? I can't get any information about handling their datasets on their website.

Converting these files to .csv would be nice, but I can't find any working program to convert the GRIB files.

Best Answer

you can use wgrib2 to convert your data to csv.

wgrib2: -csv (comma separated values)

The -csv option writes the grid values to a specified file as a comma separated values (text) which can be imported into a spread sheet. This function is similar to -text with a different output.

"time0","time1","field","level",longitude,latitude,grid-value

Time0 is the reference time, that is usually the analysis or start of the forecast time. Time1 is the verification time. For analyses, Time0 and Time1 will be the same.

wgrib2 fcst.grb2 -csv junk 

$ cat junk 
"2007-03-26 00:00:00","2007-03-26 00:00:00","HGT","1000 mb",0,-90,164.1
"2007-03-26 00:00:00","2007-03-26 00:00:00","HGT","1000 mb",0.5,-90,164.1
"2007-03-26 00:00:00","2007-03-26 00:00:00","HGT","1000 mb",1,-90,164.1
"2007-03-26 00:00:00","2007-03-26 00:00:00","HGT","1000 mb",1.5,-90,164.1

beside this there is a python library which name is pygrib (python module for reading GRIB files). i think you can read your grib files and then convert them to csv file or anything with it.

Python module for reading and writing GRIB (editions 1 and 2) files. GRIB is the World Meterological Organization standard for distributing gridded data. The module is a python interface to the GRIB API C library from the European Centre for Medium-Range Weather Forecasts (ECMWF).

Some Example code:

import pygrib

grbs = pygrib.open('sampledata/flux.grb')  
grb = grbs.select(name='Maximum temperature')[0]

#

maxt = grb.values # same as grb['values']
maxt.shape, maxt.min(), maxt.max()
#(94, 192) 223.7 319.9

get the latitudes and longitudes of the grid:

lats, lons = grb.latlons()
lats.shape, lats.min(), lats.max(), lons.shape, lons.min(), lons.max()
(94, 192) -88.5419501373 88.5419501373  0.0 358.125

i hope it helps you...

Related Question