Fail in replacing variable values between grib2 files
Added by Annie Jasmine over 4 years ago
Hi everyone,
I want to replace values of surface temperature variable (t at Level 0) in the fnl file (grib2) by values in ts1.grb2. Those files are attached
Below is info in each file.
info - file1
cdo infov fnl_20131106_18_00.grib2
-1 : Date Time Level Gridsize Miss : Minimum Mean Maximum : Parameter name
1 : 2013-11-06 18:00:00 0 65160 0 : 95199. 1.0070e+05 1.0381e+05 : msl
2 : 2013-11-06 18:00:00 1000 65160 0 : 28922. 30676. 31604. : gh
...
202 : 2013-11-06 18:00:00 0 65160 0 : -121.51 383.51 5638.7 : orog
203 : 2013-11-06 18:00:00 0 65160 0 : 206.70 278.08 329.80 : t
204 : 2013-11-06 18:00:00 0.05 65160 43101 : 219.38 267.61 315.00 : t
...
cdo infon: Processed 75 variables over 1 timestep [12.08s 54MB].
info - file2
cdo infov ts1.gr2
-1 : Date Time Level Gridsize Miss : Minimum Mean Maximum : Parameter name
1 : 2013-11-06 18:00:00 0 65160 0 : 206.70 278.86 329.80 : t
cdo infon: Processed 1 variable over 1 timestep [0.16s 46MB].
replacing
cdo replace fnl_20131106_18_00.grib2 ts1.grb2 out.grb2
Warning: Level 0 not found!
cdo replace: Processed 76 variables over 2 timesteps [8.53s 130MB].
There is no change in the surface temperature values in the output file compared to the original fnl file.
The warning might cause the failed replacement dispite Level 0 printed out by "cdo info" commands above.
Could anyone please suggest me a solution for this?
Many thanks!
ts1.grb2 (255 KB) ts1.grb2 | file2 | ||
fnl_20131106_18_00.grib2 (13.6 MB) fnl_20131106_18_00.grib2 | file1 |
Replies (6)
RE: Fail in replacing variable values between grib2 files - Added by Uwe Schulzweida over 4 years ago
Hi Annie,
The error message is unfortunately somewhat unclear. The correct message is
cdo replace (Warning): Variable t on level 0 not found!
The Replace operator assumes that all variable names occur only once. Your GRIB file contains the variable t nine times. Three of them are on level zero. The first variable t has 26 pressure levels and level 0 is not found there.
I will adapt the documentation.
Cheers,
Uwe
RE: Fail in replacing variable values between grib2 files - Added by Annie Jasmine over 4 years ago
Thanks Uwe for pointing out the cause. Could you please let me know there is any way to tell cdo that I want to replace the value of the t variable in the 203th record printed out by "cdo info"? Or any other tool can do?
Kind regard,
Annie
RE: Fail in replacing variable values between grib2 files - Added by Uwe Schulzweida over 4 years ago
You can use the undocumented operator selrec to select records:
cdo selrec,1/202 fnl_20131106_18_00.grib2 part1.grib2 cdo selrec,204/288 fnl_20131106_18_00.grib2 part2.grib2 cat part1.grib2 ts1.grb2 part2.grib2 > result
RE: Fail in replacing variable values between grib2 files - Added by Annie Jasmine over 4 years ago
Awesome! The selrec operator works well. Thanks so much, Uwe!
By the way, I got another confusion using "cdo add" and "cdo sub", could you please help me to explain?
cdo add in.grb2 f1.grb2 out.grb2
cdo add: Processed 2 variables over 2 timesteps [0.22s 61MB].
cdo sub out.grb2 in.grb2 f2.grb2
cdo sub: Processed 2 variables over 2 timesteps [0.10s 36MB].
f1.grb2 and f2.grb2 should be the same but they are different, in fact!
cdo infov f1.grb2
-1 : Date Time Level Gridsize Miss : Minimum Mean Maximum : Parameter name
1 : 1850-01-01 00:00:00 0 65160 0 : -0.20051 0.77733 3.3890 : t
cdo infon: Processed 1 variable over 1 timestep [0.15s 46MB].
cdo infov f2.grb2
-1 : Date Time Level Gridsize Miss : Minimum Mean Maximum : Parameter name
1 : 2013-11-06 18:00:00 0 65160 0 : -0.22500 0.77739 3.3629 : t
cdo infon: Processed 1 variable over 1 timestep [0.07s 28MB].
Kind regards,
Annie
RE: Fail in replacing variable values between grib2 files - Added by Uwe Schulzweida over 4 years ago
You must be very careful when using GRIB to store intermediate results. The idea of GRIB is to store data efficiently. Normally lossy compressions are used for this. This means that information can be lost when saving.
In your example, the first field contains 11-bit compressed data and the second field contains 32-bit float data. CDO stores the result in 11-bit because this information is inherited from the first field.
Here is the result, when using 32-bit float:
cdo -b F32 add in.grb2 f1.grb2 out.grb2 cdo sub out.grb2 in.grb2 f2.grb2 cdo infov f1.grb2 -1 : Date Time Level Gridsize Miss : Minimum Mean Maximum : Parameter name 1 : 1850-01-01 00:00:00 0 65160 0 : -0.20051 0.77733 3.3890 : t cdo infon: Processed 65160 values from 1 variable over 1 timestep [0.18s 44MB]. cdo infov f2.grb2 -1 : Date Time Level Gridsize Miss : Minimum Mean Maximum : Parameter name 1 : 2013-11-06 18:00:00 0 65160 0 : -0.20052 0.77733 3.3890 : t cdo infon: Processed 65160 values from 1 variable over 1 timestep [0.05s 29MB].
RE: Fail in replacing variable values between grib2 files - Added by Annie Jasmine over 4 years ago
Yes, I got the point and many thanks for your help, Uwe !