Forums » Operator News »
expr - New Options with upcomming release 1.7.1
Added by Ralf Mueller over 8 years ago
With CDO release 1.7.1 the expr (and the related exprf, aexpr, aexprf) recieve on important update: the ability to include meta data into user defined computations
- Calculating with horizontal coordinates: With the two new functions clon(V) and clat(V) the user has access to the longitudes and latitudes of a given variable
V
. Suppose the both coordinate fields are given in degrees, this can be used to calculate a global wind field based on a global sin patterncdo shaded,device=png -expr,'wind_u=sin(2*rad(clat(topo)))' -topo analytic_forcing
which leads to westward winds on northern and eastward winds on southern hemisphere
If this is not enough, lets combine it with a cosin longitude pattern:cdo shaded,device=png -setunit,m/s -expr,'wind_u=sin(2*rad(clat(topo)))*cos(2*rad(clon(topo)))' -topo analytic_forcing
to get circular regions with different wind directions - Calculating with vertical coordinates: With the new function clev(V), the vertical coordinates of a variable
V
can be read. Lets compute the potential temperator! Instead of looping over the list vertical levelsfor level in $(cdo showlevel -select,name=temp ifile); do cdo -f nc -expr,"pot_temp=temp*((100000/${level})^0.287)" -sellevel,${level} ifile potTemp_${level}.nc done cdo merge pottemp_?????.nc pottemp_??????.nc pottemp.nc rm pottemp_??????.nc pottemp_?????.nc
the whole procedure can be written in a single line without temporal filescdo expr,"pottemp=temp*((100000/clev(temp))^0.287);" ifile pottemp.nc
- Calculating with temporary data: Variables starting with an underscore, will not be written into the result file. This can increase the readabiliy of the formulars, while keeping the output file clean
cdo-dev -f nc -expr,'_xSquare = sin(rad(clat(topo)))^2; _ySquare = cos(rad(clat(topo)))^2; constant1=sqrt(_xSquare + _ySquare)' -topo constant_1.nc cdo infov constant_1.nc -1 : Date Time Level Gridsize Miss : Minimum Mean Maximum : Parameter name 1 : 0000-00-00 00:00:00 0 259200 0 : 1.0000 1.0000 1.0000 : constant1
- Calculate with cdo-internal functions: Vertical and horizontal operations like fldmean, vertmean, fldstd or vertmax can now be used in formulars. Lets scale a temperature (K) with its maximum value
cdo -f nc -infov -aexpr,'h=temp/fldmax(temp)' -temp -1 : Date Time Level Gridsize Miss : Minimum Mean Maximum : Parameter name 1 : 0001-01-01 00:00:00 0 259200 0 : 220.85 276.72 317.30 : temp 2 : 0001-01-01 00:00:00 0 259200 0 : 0.69603 0.87210 1.0000 : h
For further options, please have a look here