Project

General

Profile

Multiply 4D var by constant over one dimension

Added by david moreno 14 days ago

Hello,

I have a 4D var (time, level, lat, lon) and a 1D var (level). I want to multiply the 4D var by the 1D var over the level dimension.

It should be something like 4Dvar (:,lev,:,:)*1Dvar(lev)

Is there any way to do this with CDO, or perhaps NCO?

Thanks.


Replies (5)

RE: Multiply 4D var by constant over one dimension - Added by Uwe Schulzweida 13 days ago

If both variables are in the same file and 1Dvar(lev) is the vertical coordinate of 4Dvar, use

cdo expr,'4Dvar=4Dvar*clev(4Dvar)'  infile  outfile
And if 1Dvar(lev) is not the vertical coordinate of 4Dvar:
cdo expr,'4Dvar=4Dvar*1Dvar'  infile  outfile

RE: Multiply 4D var by constant over one dimension - Added by david moreno 13 days ago

Hi Uwe, thanks for the reply, however, seems like things are not working out as expected...

The 4DVar with dimensions (time, level, lat, lon) has dims (24,4,400,300) and the 1DVar with dimensions (level) has dimension (4), meaning, it has 1 value per level, which in the case are 0.1, 0.3, 0.5 and 1.

So, I think that the 1DVar is NOT the vertical coordinate of 4DVar, but it is simply a 1DVar with values over the same vertical coordinate of 4DVar.

If I do cdo expr,'4Dvar=4Dvar*1Dvar' infile outfile, then the outcome is:

cdo expr (Abort): expr_var_var: Number of grid points differ (4DVar191808 <-> 1DVar4)

RE: Multiply 4D var by constant over one dimension - Added by david moreno 13 days ago

Here is the ncdump -h of my infile, I want to multiply the variable MRSFL by the var DZS:

dimensions:
XTIME = UNLIMITED ; // (24 currently)
west_east = 444 ;
south_north = 432 ;
soil_layers_stag = 4 ;
variables:
float XTIME ;
XTIME:standard_name = "time" ;
XTIME:units = "minutes since 1978-07-01 00:00:00" ;
XTIME:calendar = "standard" ;
XTIME:axis = "T" ;
float XLONG ;
XLONG:standard_name = "longitude" ;
XLONG:long_name = "longitude" ;
XLONG:units = "degree_east" ;
XLONG:_CoordinateAxisType = "Lon" ;
float XLAT ;
XLAT:standard_name = "latitude" ;
XLAT:long_name = "latitude" ;
XLAT:units = "degree_north" ;
XLAT:_CoordinateAxisType = "Lat" ;
float MRSFL ;
MRSFL:coordinates = "XLAT XLONG" ;
MRSFL:_FillValue = -9.e+33f ;
MRSFL:missing_value = -9.e+33f ;
float DZS ;
DZS:units = "m" ;
DZS:FieldType = 104 ;
DZS:MemoryOrder = "Z " ;
DZS:description = "THICKNESSES OF SOIL LAYERS" ;
DZS:stagger = "Z" ;
DZS:cell_methods = "XTIME: mean" ;

RE: Multiply 4D var by constant over one dimension - Added by david moreno 13 days ago

dimensions:
XTIME = UNLIMITED ; // (24 currently)
west_east = 444 ;
south_north = 432 ;
soil_layers_stag = 4 ;
variables:
float XTIME) ;
XTIME:standard_name = "time" ;
XTIME:units = "minutes since 1978-07-01 00:00:00" ;
XTIME:calendar = "standard" ;
XTIME:axis = "T" ;
float XLONG) ;
XLONG:standard_name = "longitude" ;
XLONG:long_name = "longitude" ;
XLONG:units = "degree_east" ;
XLONG:_CoordinateAxisType = "Lon" ;
float XLAT) ;
XLAT:standard_name = "latitude" ;
XLAT:long_name = "latitude" ;
XLAT:units = "degree_north" ;
XLAT:_CoordinateAxisType = "Lat" ;
float MRSFL) ;
MRSFL:coordinates = "XLAT XLONG" ;
MRSFL:_FillValue = -9.e+33f ;
MRSFL:missing_value = -9.e+33f ;
float DZS);
DZS:units = "m" ;
DZS:FieldType = 104 ;
DZS:MemoryOrder = "Z " ;
DZS:description = "THICKNESSES OF SOIL LAYERS" ;
DZS:stagger = "Z" ;
DZS:cell_methods = "XTIME: mean" ;

RE: Multiply 4D var by constant over one dimension - Added by Uwe Schulzweida 13 days ago

To identify soil_layers_stag as a vertical dimension, a coordinate variable with the same name must exist. The attribute axis=“Z” is also required:

ncap2 -s 'soil_layers_stag[soil_layers_stag]=0'  filename.nc
ncatted -a axis,soil_layers_stag,c,c,"Z"  filename.nc

    (1-5/5)