[Thread Prev][Thread Next][Index]

Re: [ferret_users] @sum bug ?



Ansley Manke a écrit :
Hi Patrick,
I really think this is a precision issue. The numbers involved are down near the limit of single-precision accuracy. The source code for the sum operation has never been changed, since Ferret was first written. Note that the difference between 2526427.250 and 2526434.500 are in the 6th decimal place, and both would be rounded off to 2526430. at a precision of 6 decimal places. Single-precision variables are really only this accurate, to 6 or 7 decimal places. I have to conclude that the differences in the results from one Ferret executable to another are due to slight changes in the way Ferret is compiled and linked.

The reason that the sums of var and xsequence(var) differ somewhat is again because of computational accuracy. When computing the sum of the multi-dimensioned variable, the sum over x is first computed, leaving a variable in y, then that is summed over y. When the one-dimensional variable's sum is computed, that is done in just one step, so there's just a bit of a difference in the way the numbers are added up. We're looking into the possibility of changing the summation routines to make the results of the two computations consistent and perhaps more accurate.
Ansley,
Indeed your analysis of the problem seems correct : it is a precision issue.
This poor precision on a sum operation gives of course error on a mean too.
More than 1E-4 between a mean calculated from ncap2 and ferret.
I would really like that all internal calculations be casted to double precision float
then be written as float.

Here the test you can do from
http://dods.ipsl.jussieu.fr/brocksce/ferret_bugs/tas_day_IPSL-CM5A-LR_piControl_r1i1p1_extract.nc

Then calculate a sum (total) and a mean (avg) with ncap2
$ ncap2 -Oh -s 'tas_mean=tas.avg($lat,$lon); tas_sum=tas.total($lat,$lon)' tas_day_IPSL-CM5A-LR_piControl_r1i1p1_extract.nc tyty.nc

Then compare results in a ferret session (Linux 6.64 X86_64):

$ ferret
yes? use tyty.nc
yes? list tas_sum-tas[i=@sum,j=@sum], tas_mean-tas[i=@sum,j=@sum]/tas[i=@ngd,j=@ngd]
            DATA SET: ./tyty.nc
IPSL-CM5A-LR model output prepared for CMIP5 pre-industrial control
            TIME: 01-JAN-1800 00:00 to 11-APR-1800 00:00 NOLEAP
            LONGITUDE: 1.9W(-1.9) to 1.9W
            LATITUDE: 90S to 90N
Column  1: EX#1 is TAS_SUM-TAS[I=@SUM,J=@SUM]
Column  2: EX#2 is TAS_MEAN-TAS[I=@SUM,J=@SUM]/TAS[I=@NGD,J=@NGD]
                      EX#1     EX#2
01-JAN-1800 12 /   1:   7.25  0.000793
02-JAN-1800 12 /   2:   9.75  0.001068
03-JAN-1800 12 /   3:  -6.25 -0.000671
04-JAN-1800 12 /   4:  11.75  0.001282
05-JAN-1800 12 /   5: -11.50 -0.001251
06-JAN-1800 12 /   6:   3.50  0.000397
07-JAN-1800 12 /   7:   9.00  0.000977
08-JAN-1800 12 /   8:  -7.50 -0.000824
09-JAN-1800 12 /   9:  -7.50 -0.000793
10-JAN-1800 12 /  10:  -8.50 -0.000916
11-JAN-1800 12 /  11:  -4.50 -0.000488
12-JAN-1800 12 /  12:   9.50  0.001007
13-JAN-1800 12 /  13: -13.75 -0.001495
14-JAN-1800 12 /  14:  12.00  0.001312

Patrick

--
LSCE/IPSL, Laboratoire CEA-CNRS-UVSQ
Data Analysis and Visualization Engineer
IPSL Global Climate Modelling Group
--



[Thread Prev][Thread Next][Index]

Contact Us
Dept of Commerce / NOAA / OAR / PMEL / TMAP

Privacy Policy | Disclaimer | Accessibility Statement