Project

General

Profile

How to set GRIB metadata when creating GRIB from NetCDF

Added by Brian Højen-Sørensen almost 3 years ago

I'm converting a NetCDF file to GRIB2, which works quite fine.

cdo -b P8 -f grb2 -copy in.nc out.grb2

However, when inspecting the resulting GRIB2 file using cdo sinfo I can see that Institut is given as ECMWF, which corresponds to the centre code 98 one can see using grib_dump (see below)

cdo sinfo out.grb2
   File format : GRIB2
    -1 : Institut Source   T Steptype Levels Num    Points Num Dtype : Parameter ID
     1 : ECMWF    unknown  v instant       1   1     21879   1  P8   : 2.1.10        
     2 : ECMWF    unknown  v instant       1   1     21879   1  P8   : 3.1.10        
   Grid coordinates :
     1 : lonlat                   : points=21879 (143x153)
                              lon : 9.375 to 13.31948 by 0.027778 degrees_east
                              lat : 53.875 to 56.40838 by 0.016667 degrees_north
   Vertical coordinates :
     1 : surface                  : levels=1
   Time coordinate :  1 step
     RefTime =  2021-05-03 23:00:00  Units = seconds  Calendar = proleptic_gregorian
  YYYY-MM-DD hh:mm:ss  YYYY-MM-DD hh:mm:ss  YYYY-MM-DD hh:mm:ss  YYYY-MM-DD hh:mm:ss
  2021-05-04 00:00:00
grib_dump out.grb2 
***** FILE: out.grb2 
#==============   MESSAGE 1 ( length=12590 )               ==============
GRIB {
  # Oceanographic products (grib2/tables/4/0.0.table)  
  discipline = 10;
  editionNumber = 2;
  # European Centre for Medium-Range Weather Forecasts (common/c-11.table)  
  centre = 98;
  subCentre = 0;
  ...
  ...
  ...
}

My own organization (Danish Joint GEOMETOC Support center) is not in the official c-11.table and can therefore not be given as the Institute/centre, however since we are providing these files for the public to be downloaded we are not quite happy that the files are being reported as originating from ECMWF, since we are producing them using our own models.

I have tried adding NetCDF attributes called centre, center, Institut, Institute and so on to see if CDO would perhaps use that number instead, but without any success.
Our goal is to begin with, just to be able to change the centre number / Institute to something else so it is being reported as 'undefined' or 'unknown' rather than ECMWF.

Is it possible to provide a NetCDF attribute that will be used instead of just setting it to ECMWF, or might it possible to change after the convertion to GRIB with CDO (I haven't found anything in the docs)?

I have attached a set of test files.

Cheers,

Brian Højen-Sørensen
Geophysicist, MSc, PhD

Joint GEOMETOC Support Center
Defence Center for Operational Oceanography - FCOO
Defence Acquisition and Logistics Organization - DALO
Lautrupbjerg 1-5
DK-2750 Ballerup


Replies (5)

RE: How to set GRIB metadata when creating GRIB from NetCDF - Added by Karin Meier-Fleischer almost 3 years ago

Hi Brian,

I'm not a GRIB expert. GRIB does not have real metadata like netCDF, it uses pre-defined parameter tables. Why do you want do use GRIB? I actually thought that WRF used netCDF/HDF.

-Karin

RE: How to set GRIB metadata when creating GRIB from NetCDF - Added by Brian Højen-Sørensen almost 3 years ago

Hi Karin,

Thanks for the reply. Yes, I know that GRIB files do not have so much metadata, but it does have some.
The actual centre code, which is the one that can be used for getting the originating source is as far as I know actually real metadata in the GRIB files.
We plan to have our own centre added to the official eccodes table (we are responsble for Safety at Sea and low sea level wanings in the Danish area), which could solve this in the long run.
But right now CDO just assumes it's ECMWF, probably since we are using the official ECMWF codes and short names.

Regarding why we are using GRIB in the first place is because the software we are targeting with these files only supports GRIB files. For navigational planning (sailing ships), several different kinds of software exists, but all the common ones does not have NetCDF support at the moment.
We only work with NetCDF when at all possible and our own models (GETM and WW3) also uses NetCDF for input as well as output (which we already provide to the public). We do not run our own met models but have them provided by ECMWF and the Danish MetOffice.
So altough I agree that GRIB is a very frustrating format, it's simply the only option if we want to provide up to date forecasts to the sailing ships to be integrated into their route planning.

Cheers,
Brian

RE: How to set GRIB metadata when creating GRIB from NetCDF - Added by Karin Meier-Fleischer almost 3 years ago

Sorry, that was my mistake. I've send my comment to the wrong issue. :/

RE: How to set GRIB metadata when creating GRIB from NetCDF - Added by Uwe Schulzweida almost 3 years ago

Hi Brian,

CDO uses the GRIB1 and GRIB2 templates from ecCodes to encode GRIB messages. Some GRIB keys like centre and subCentre can't be change with CDO. You can use the ecCodes tool grib_set to set the GRIB keys:

grib_set -s centre=<XX>,subCentre=<YY> infile outfile
In the next CDO version the path to your own GRIB templates can be set with the environment variable CDI_GRIB1_TEMPLATE or CDI_GRIB2_TEMPLATE. A prerelase for testing is available in the download area.

Cheers,
Uwe

RE: How to set GRIB metadata when creating GRIB from NetCDF - Added by Brian Højen-Sørensen almost 3 years ago

Hi Uwe,

Thanks for the explanation, it was more or less what I expected. I found out how to do it with grib_set just as you mention, so we are producing the files operationally now.

But I really appreciate the effort you are investing in CDO.

Cheers,
Brian

    (1-5/5)