Project

General

Profile

calculate area weighted mean from a selected region

Added by Feng Wang over 4 years ago

Hi all,
I am new to CDO. Recently I tried to extract some data from output of climate models. I want to get weighted mean of regions of interest. First of all, I selected the data from a region using the command:
#cdo sellonlatbox, 220,305,30,90 mync.nc outnc.nc
it worked.
Then I used command:
#cdo fldmean outnc.nc out2nc.nc
It said that:
#Warning: Grid cell bounds not available, using constant grid cell area weights for variable w_stag!
#Warning: Grid cell bounds not available, using constant grid cell area weights for variable nlon!
#Warning: Grid cell bounds not available, using constant grid cell area weights for variable TREFHT!

I think the weighted means are not calculated in this case.
However, there is no such problem if I calculate the area-weighted mean from the complete nc file, i.e. mync.nc

Could anyone help to give simple solutions to this issue?Thank you in advance. The data is attached.

Feng

mync.nc (60.7 MB) mync.nc

Replies (4)

RE: calculate area weighted mean from a selected region - Added by Uwe Schulzweida over 4 years ago

Hi Feng,

This is a bug in sellonlatbox, when storing the data. We will fix this problem in the next release.
A workaround is to select the required variable (e.g. TREFHT) first:

cdo sellonlatbox,220,305,30,90 -selname,TREFHT mync.nc outnc.nc
cdo fldmean outnc.nc out2nc.nc
or apply fldmean directly on the result of sellonlatbox:
cdo fldmean -sellonlatbox,220,305,30,90 mync.nc outnc.nc
Cheers,
Uwe

RE: calculate area weighted mean from a selected region - Added by Feng Wang over 4 years ago

Hi Uwe,
Thanks a lot for providing solutions. I just tried both options using exactly the same netcdf file I shared. But in my pc (Mac), there are warnings too:
for your first solution, #cdo fldmean outnc.nc out2nc.nc# was terminated automatically.
Probably this is due to the warnings following the first command "cdo sellonlatbox,220,305,30,90 -selname,TREFHT mync.nc outnc.nc".

cdo(1) selname: Process started
Warning (cdfCheckVars): Unsupported data type (char/string), skipped variable date_written!
Warning (cdfCheckVars): Unsupported data type (char/string), skipped variable time_written!
cdf_get_var1_double: ncid = 65536 varid = 7

for the second solution, I got similar warnings. Although the data can be written, the variable of interest (i.e. TREFHT) disappeared in the created nc file.
Could you please check this?
Many thanks.

Feng

RE: calculate area weighted mean from a selected region - Added by Uwe Schulzweida over 4 years ago

Hi Feng,

Unfortunately I can't reproduce this problem. I therefore assume that this is a known problem with NetCDF4 (see: https://code.mpimet.mpg.de/projects/cdo/wiki#Segfault-with-netcdf4-files).
So, please try it with the -L option:

cdo -L sellonlatbox,220,305,30,90 -selname,TREFHT mync.nc outnc.nc
Otherwise I need the output of "cdo -V".

Cheers,
Uwe

RE: calculate area weighted mean from a selected region - Added by Feng Wang over 4 years ago

Hi Uwe,
That's perfectly working! Although there are some warnings (see below), the TREFHT can be finally written and I can continue to use -fldmean anyway. The area-weighted mean can be finally calculated.

cdo(1) selname: Process started
Warning (cdfCheckVars): Unsupported data type (char/string), skipped variable date_written!
Warning (cdfCheckVars): Unsupported data type (char/string), skipped variable time_written!
cdo(1) selname: Processed 16 variables over 1872 timesteps.
cdo sellonlatbox: Processed 25878528 values from 1 variable over 1872 timesteps [2.15s 69MB].

Thank you very much,
Feng

    (1-4/4)