Grib1 To Grib2 Converterlite

newmini
3 min readNov 2, 2021

Download here

Active11 months ago

Conversion of GRIB and NetCDF to my database. Or you can use PyNio, a Python package that allows to read and write netCDF3 and netCDF4 classic format, and to read GRIB1 and GRIB2 files. Java GRIB-Decoder: Extract data from GRIB2 files. How to index a NetCDF file very quickly. NCL can read and plot GRIB1 and GRIB2 data directly. (GRIB2 support was added in version 4.3.0.) Therefore, this type of conversion need only be used if netCDF output for sharing is required. GRIB2 improves upon the standard with the same compression software commonly used for images to gain a roughly 50% reduction in file size over GRIB1. Recently, version 2 of GRIB2 was released. Recently, version 2 of GRIB2 was released.

I know there is software like wgrib2 that will convert files in grib and grib2 format to NetCDF files, but I need to go the other way: from NetCDF to grib2, because the local weather offices here can only consume gridded data in grib2 format.

It appears that one solution could be in Python, using the NetCDF4-Python library (or other) to read the NetCDF files and using pygrib to write grib2.

Is there a better way?

msi_gerva

98222 gold badges99 silver badges2323 bronze badges

Rich SignellRich Signell

8,81922 gold badges3131 silver badges5959 bronze badges

Convert Grib2 To Grib1

4 Answers

After some more research, I ended up using the British Met Office ‘Iris’ package (http://scitools.org.uk/iris/docs/latest/index.html) which can read NetCDF as well as OPeNDAP, GRIB and several other formats, and allows to save as NetCDF or GRIB.

Basically the code looks like:

But if your netcdf file doesn’t contain sufficient metadata, you may need to add it, which you can also do with Iris. Here’s a full working example:

Rich SignellRich Signell

8,81922 gold badges3131 silver badges5959 bronze badges

One can also use climate data operators (cdo’s) for the task -https://code.zmaw.de/projects/cdo/wiki

but need to install the software with all additional libraries.

msi_gervamsi_gerva

98222 gold badges99 silver badges2323 bronze badges

I know CDO is mentioned above, but I thought it would be useful to give the full command

Adrian TompkinsAdrian Tompkins

1,83311 gold badge55 silver badges3838 bronze badges

ECMWF has a command line based tool to do just this: https://software.ecmwf.int/wiki/display/GRIB/grib_to_netcdf

N1B4N1B4

Not the answer you’re looking for? Browse other questions tagged pythonnetcdfgrib or ask your own question.

Active1 year, 4 months ago

$begingroup$

ECMWF model data comes in a hybrid GRIB format, that is, model level output is stored in GRIB2 messages, whereas surface data still uses GRIB1 format. Ungrib is unable to understand this hybrid GRIB format. Previous posts referred to ECMWF’s grib-api which should be able to convert GRIB2 to GRIB1, but this doesn’t seem to work since the 2013 update when 137 model levels were introduced. So my question is, how to get it working again?

milancurcic

4,60511 gold badge2222 silver badges4141 bronze badges

Peter9192Peter9192

$endgroup$

1 Answer

$begingroup$

Grib2 Nc

I finally solved this problem with the following steps:

  • Download the ECMWF data separately for model level variables (Q,T,U,V and geopotential) and surface variables. In this way, you will get ‘pure’ GRIB1 and ‘pure’ GRIB2 files rather than the hybrid type.
  • Run ungrib twice: for the model levels files, use this Vtable. For the surface file, use the ‘old’ Vtable.ECMWF_sigma. Between the two ungrib runs, change the ungrib prefix in the namelist.wps (e.g. I used prefix = ‘FILE_ML’ and prefix = ‘FILE_SFC’).
  • Run util/calc_ecmwf_p.exe. This only works if the program can read both files. To achieve this, make sure that in the metgrid part of the namelist.wps, both input names are given (fg_name = ‘FILE_ML’,’FILE_SFC’,’PRES’,). Not sure whether ‘PRES’ makes a difference here, but since it will be used for metgrid I already put it there and it worked for me. ‘PRES’ are the files created by calc_ecmwf_p.exe. Note that you’ll also need an ‘ecmwf_coeffs’ file for this step.
  • Run metgrid, real and wrf as usual.

Peter9192Peter9192

How To Use Wgrib2

$endgroup$

Grib2 To Netcdf

Not the answer you’re looking for? Browse other questions tagged meteorologymodelsatmosphere-modellingwrf or ask your own question.

Download here

--

--