Project

General

Profile

operators on variables different names in different files

Added by Noam Chomsky over 4 years ago

Say I have two files a(lat,lon,z,time) and b(lat,lon,z,time). Both files have a certain number of variables.

Lat,lon,time are the same for the two files

I want to be able to multiple, add, etc variables across specific levels across these two files.

The last step would be to calculate the average across the last x number of years for each variable in the netcdf. So the result would be average(lat,lon,z) for each variable.

I have managed to get my result, which I think it's correct, but it seems I had to go through many intermediate steps. Is there a more efficient way to do this?

in myexpr I use variab3 = sellevel(variable1,10)+sellevel(variable2,11);

#make some calculation in file a
cdo exprf,myexpr a.nc a1.nc

cdo expr,'anpop=ani_popu_all*10^6;' b.nc b1.nc

cdo merge a1.nc b1.nc total.nc

cdo exprf,morecalc total.nc popcalc.nc

cdo yearmean popcalc.nc yearlm.nc

cdo -select,timestep=-5/-1 yearlm.nc yearlm5.nc

cdo timavg yearlm5.nc yearlmall.n

Also, should I use timavg or fldavg, I don't really understand the differences.


Replies (3)

RE: operators on variables different names in different files - Added by Karin Meier-Fleischer over 4 years ago

Hi Noam,

you can combine some operator calls, see https://code.mpimet.mpg.de/projects/cdo/wiki/Tutorial#Combining-Operators.

cdo yearmean popcalc.nc yearlm.nc
cdo -select,timestep=-5/-1 yearlm.nc yearlm5.nc
cdo timavg yearlm5.nc yearlmall.n

can be written as

cdo -timavg -select,timestep=-5/-1 -yearmean popcalc.nc yearlmall.nc

Use timavg when averaging over time and fldmean when averaging on the horizontal grid.

-Karin

RE: operators on variables different names in different files - Added by Noam Chomsky over 4 years ago

Thank you Karin, I will try that.

So there is no way to use expr across files? It can be applied to one file only?

RE: operators on variables different names in different files - Added by Miles Sowden almost 2 years ago

combine operators and do the calculation such as

cdo expr,'Temp_avg=(Temp_max + Temp_min)/2' -merge Temp_maximum.nc Temp_minimum.nc Temp_average.nc

    (1-3/3)