Project

General

Profile

Possible bug in src/Varsstat.cc when using operator -varsstd or -varsvar

Added by Jonas Kock am Brink 6 months ago

Hello,

I found a possible bug in the implementation of the varsvar and varsstd operator. I attached a
minimum working example that consists of the following files:

  • icon-d2-eps_germany_icosahedral_single-level_2023102600_000_2d_t_2m.grib2
  • target_grid_icon_d2_002.txt
  • weights_icon_d2_002.nc
  • run.sh

The first file is available at https://opendata.dwd.de/weather/nwp/icon-d2-eps/grib/00/t_2m/. The
last two can be found in https://opendata.dwd.de/weather/lib/cdo/ICON_D2_002_EASY.tar.bz2.

run.sh is the script with contains three parts:
  1. Calculating the varsvar of an unstructured grid
  2. Calculating the varsvar of a remapped grid
  3. Calculating the varsvar of a bboxed and remapped grid

While the first and second section works, the last section returns 0. The result of the varsvar of a
bboxed and remapped grid are nans only. But not if the bbox is omitted as you can see in example 2.

Possible Bug

When investigating the source code, I looked at cdo/src/Varsstat.cc when invoking
fieldc_stdvar_func() at around line 264. If you compare the function arguments with the call for
the mean (7 lines further up), you notice that rsamp1.nsamp is used instead of rvars1.nsamp.
And indeed, when fixing this, the function operator returns the correct values.

The patch would be:

diff --git a/src/Varsstat.cc b/src/Varsstat.cc
index 90331bc..05c6d82 100644
--- a/src/Varsstat.cc
+++ b/src/Varsstat.cc
@@ -261,7 +261,7 @@ public:
                     if (!rsamp1.empty())
                       field2_stdvar_func(rvars1, vars2[levelID], rsamp1, divisor);
                     else
-                      fieldc_stdvar_func(rvars1, vars2[levelID], rsamp1.nsamp, divisor);
+                      fieldc_stdvar_func(rvars1, vars2[levelID], rvars1.nsamp, divisor);
                   }
                 else if (lrange) { field2_sub(rvars1, vars2[levelID]); }


Replies (1)

RE: Possible bug in src/Varsstat.cc when using operator -varsstd or -varsvar - Added by Uwe Schulzweida 6 months ago

Hello Jonas,

Thanks for this report, the example and the patch! A fix of this bug will be available in the next CDO release 2.3.1.

Cheers,
Uwe

    (1-1/1)