Project

General

Profile

Reg: Change variable name in a grib file.

Added by jyoti lodha almost 6 years ago

Hi
I want to change my variable name from (var11) to TT,but when I am using :
cdo chname,var11,TT fina.grb chname.grb
cdo chname: Processed 43200 values from 1 variable over 120 time steps ( 0.84s ).

It is processing the data , but not changing it.
And my CDO version in 1.9.3

Thanking you

Waiting for a positive response.

fina.grb (104 KB) fina.grb grib file

Replies (11)

RE: Reg: Change variable name in a grib file. - Added by Ralf Mueller almost 6 years ago

GRIB1 does NOT support variable names. what you see with infov operators is a generated string. GRIB1 only uses 3-digit code numbers. for useing names that can be changed, you have to use netcdf files:

cdo -f nc copy <in.grb> <out.nc>

hth
ralf

RE: Reg: Change variable name in a grib file. - Added by jyoti lodha almost 6 years ago

Hi
Thanks for the reply. But at initial stage I have converted my .nc file to grib1, and this file(fina.grb) has to be used further in WRF processing. So this solution is not fully supported , is there is any other solution to save the variable name before converting netcdf to grib file.So, it does not changes. As I am using (cdo -f grb setltype,100 -chparam,-1,11 /ankit/temp4.nc /ankit/temp4Docker.grb) for converting netcdf to grib file.

Waiting for a positive response.

RE: Reg: Change variable name in a grib file. - Added by Ralf Mueller almost 6 years ago

Since the names definitely get lost in GRIB, you should create a kind of inventory of the netcdf file. you can use the partab operator for creating it based on the netcdf file. here is an introduction to setpartab, the operator that apllies these inventories to files.

So the workflow could be

  1. create the inventort from netcdf input
  2. create the grib file and an inventory based on that
  3. compare the two inventories and merge them to get the names and the grib code numbers into on a single file. you shoud set the out_name key to be the desired netcdf name
  4. that final inventory can be used to create the netcdf file from grib using
     cdo -f nc setpartab,<finalInventory> in.grib out.nc

hth
ralf

RE: Reg: Change variable name in a grib file. - Added by jyoti lodha almost 6 years ago

Hi
Thanks for the reply. But I am not able to merge the 2 different inventories. As both are in different formats i.e grib and .nc.

I run the following commands.
1) cdo setpartabn,mypartab sel.nc invnetcdf.nc
2)cdo setpartabn,mypartab fina.grb invnetcdf.grb
3) cdo merge invnetcdf.nc invnetcdf.grb inv.nc

Error (streamCopyRecord) : Streams have different file types (GRIB -> netCDF2)!.

Where I am doing wrong process?. I have attached my inventory of grib and .nc

mypartabnc (123 Bytes) mypartabnc inventory netcdf
mypartabgrib (126 Bytes) mypartabgrib inventory grib
fina.grb (104 KB) fina.grb grib file
sel.nc (175 KB) sel.nc netcdf file

RE: Reg: Change variable name in a grib file. - Added by jyoti lodha almost 6 years ago

Hi
I have understood and ran the command, but it is converting the variable of grib to .nc file.I want the reverse of it i.e I want to change variable of newly converted .grib file and copy the variable from .nc file.

RE: Reg: Change variable name in a grib file. - Added by Ralf Mueller almost 6 years ago

again: there is no such thing as a variable name in grib1 file format. u can check the grib1 definition yourself at ecmwf.int. grib2 has names, but you cannot change it directly. and i don't kown, what is really needed for WRF.

RE: Reg: Change variable name in a grib file. - Added by Ralf Mueller almost 6 years ago

you can use different grib tables to give certain code numbera a different meaning, check the settable operator in that case.

hth
ralf

RE: Reg: Change variable name in a grib file. - Added by jyoti lodha almost 6 years ago

Hi,

Thanks a lot. I will check it again from my end.:)

RE: Reg: Change variable name in a grib file. - Added by Jay Su almost 4 years ago

You have to do it in two steps:

cdo -f grb copy input.nc temporary.grb
cdo setpartabn,paramtab.txt temporary.grb output.grb

where paramtab.txt is the parameter table created by you to transform metadata. Looks like, eg,
&parameter
name = var1
out_name= SWnet
standard_name = Net Shortwave Radiation
units = "W/m^2"
param = 111
/
&parameter
name = var2
out_name = LWnet
standard_name = Net Longwave Radiation
units = "W/m^2"
param = 112

It's strange to me that the following does not work:
cdo -s -f grb -setpartabn,parmtab.txt input.nc output.grb

No error message and the output has the right size, but not the variable and PDS-ID mapping.

RE: Reg: Change variable name in a grib file. - Added by Ralf Mueller almost 4 years ago

hi Jay!

grib does not use names to identify variables. they are not free strings like in netcdf. instead they are defind by WMO, i.e. the GRIB standard. Please note that there are two editions of this standard. GRIB1 does not know any names, but code numbers. GRIB2 does know shortnames, but only as secondary meta information.

hth
ralf

RE: Reg: Change variable name in a grib file. - Added by Jay Su almost 4 years ago

I understand the difference between grib1 and grib2. My question here is, why I have to use two commands:

cdo -f grb copy input.nc temporary.grb
cdo setpartabn,paramtab.txt temporary.grb output.grb

but cant combine them into one:

cdo -s -f grb -setpartabn,parmtab.txt input.nc output.grb

    (1-11/11)