Project

General

Profile

Precision error?

Added by Lina Teckentrup over 4 years ago

Hello everyone,

I'm playing around with climate forcing. I first calculated an average background climate, then subtracted this from my original forcing and in the end add it back up. In years, where the original file and the modified file are suppose to be identical, I get a small error. This is what I did

cdo -ydaymean -mergetime prec*nc prec_CRUNCEP_1951-1980.nc
cdo sub prec_CRUNCEP_1968_original.nc prec_CRUNCEP_1951-1980.nc prec_CRUNCEP_1968_anomaly.nc
cdo add prec_CRUNCEP_1968_anomaly.nc prec_CRUNCEP_1951-1980.nc prec_CRUNCEP_1968_new.nc

now -

cdo sub prec_CRUNCEP_1968_original.nc prec_CRUNCEP_1968_new.nc delta_test.nc

should be zero everywhere but it isn't. For both files, the variable (prec) is a float so it can't have anything to do with the precision (?). When I tried the same for the temperature and incoming shortwave radiation forcing, also CRUNCEP, I didn't have this problem. I attached the first day of prec_CRUNCEP_1968_original.nc, prec_CRUNCEP_1968_new.nc and delta_test.nc

Cheers,
Lina


Replies (2)

RE: Precision error? - Added by Uwe Schulzweida over 4 years ago

Hello Linda,

It is definitely the precision! Your data is in 32bit float. All calculations in CDO are in 64bit float. The result is stored as 32bit float.
You have to store all intermediate results to 64bit float to get exactly the same result. Here is an example using the option -b F64:

cdo -b F64 -ydaymean -mergetime prec*nc prec_CRUNCEP_1951-1980.nc
cdo -b F64 sub prec_CRUNCEP_1968_original.nc prec_CRUNCEP_1951-1980.nc prec_CRUNCEP_1968_anomaly.nc
cdo -b F64 add prec_CRUNCEP_1968_anomaly.nc prec_CRUNCEP_1951-1980.nc prec_CRUNCEP_1968_new.nc

cdo -b F64 sub prec_CRUNCEP_1968_original.nc prec_CRUNCEP_1968_new.nc delta_test.nc
Cheers,
Uwe

RE: Precision error? - Added by Lina Teckentrup over 4 years ago

Great, thanks! That worked :)

    (1-2/2)