Subtract two variables with different dimensions
Added by Catarina Guerreiro almost 10 years ago
Hi,
I am trying to do the following calculus with cdo: anomaly=var(time,lon,lat)-var_spatialmean(time).
I estimated the var_spatialmean, which is the spatial mean for each time step:
1) # cdo fldmean inputfile outputfile
The variable dimensions are time, lon,lat, with lon and lat = 1.
And this becomes a problem when I do:
2) # cdo expr,'var_anomaly=var-var_spatialmean' inputfile outputfile
I would like to eliminate lon and lat dimensions of the second variable but I couldn't find any cdo command for the purpose.
I appreciate your help.
Catarina
Replies (3)
RE: Subtract two variables with different dimensions - Added by Uwe Schulzweida almost 10 years ago
Hi Catarina,
You can remove lon/lat=1 with the CDO option --reduce_dim:
cdo --reduce_dim fldmean inputfile outputfileBut I think this will not help you much for the calculation of the anomaly. Here are two examples to calculate the anomaly.
1. With expr for specific variables:
cdo expr,"var_anomaly=var-fldmean(var)" inputfile outputfile2. With combination of CDO operators for all variables:
cdo sub inputfile -enlarge,inputfile -fldmean inputfile outputfileWe will remove the necessity of the "-enlarge,inputfile" operator in the above example in CDO version 1.8.1.
Cheers,
Uwe
RE: Subtract two variables with different dimensions - Added by Catarina Guerreiro almost 10 years ago
Hi Uwe,
Thank you very much for your suggestions!
I had to update my cdo version to use the operators you suggested.
I have still one question regarding the variable properties in the outputfile. I lose part of my variable information after applying the cdo operators.
Is there a way to recover or to keep this information in the output file?
In the inputfile:
short msl(time, latitude, longitude) ;
msl:standard_name = "air_pressure_at_sea_level" ;
msl:long_name = "Mean sea level pressure" ;
msl:units = "Pa" ;
msl:add_offset = 99552.1862391848 ;
msl:scale_factor = 0.252521630323654 ;
msl:_FillValue = -32767s ;
msl:missing_value = -32767s ;
After applying # cdo expr,"var_anomaly=var-fldmean(var)" inputfile outputfile:
float msl_anomaly(time, latitude, longitude) ;
msl_anomaly:_FillValue = -32767.f ;
msl_anomaly:missing_value = -32767.f ;
After applying # cdo sub inputfile -enlarge,inputfile -fldmean inputfile outputfile:
double msl(time, latitude, longitude) ;
msl:standard_name = "air_pressure_at_sea_level" ;
msl:long_name = "Mean sea level pressure" ;
msl:units = "Pa" ;
msl:_FillValue = -32767. ;
msl:missing_value = -32767. ;
Thank you for your help.
Catarina
RE: Subtract two variables with different dimensions - Added by Uwe Schulzweida almost 10 years ago
Hi Catarina,
Unfortunately all attributes will be lost when using the expression operator expr. There is no way to keep these attributes, sorry.
Cheers,
Uwe