The first part of the question is how to add non-consecutive levels, for
example I know I can use myvar[k=3:6@sum] for consecutive ones, but how,
for example, to add levels 2,5, and 7?
One idea is to mask out the other levels:
let myvar_masked = IF (k eq 2) or (k eq 5) or . . . THEN myvar
This new variable has valid values only at levels k = 2, 5, . . . so that the sum you want is myvar_masked[k=1:kmax@SUM].
The second part, my data contains missing values, when I use @sum NaN
are ignored and I get the desired result, for example if I have
3,NaN,2,0 the result is 5. But if instead I use the notation
myvar[k=2]+myvar[k=5]+etc. then I get NaN in every cell where there is
at least one NaN. It seems an inconsistent behavior.
For arithmetic operations (plus, minus, . . .) and functions (sin, exp, . . . ), the entire _expression_ results in a "missing" ("undefined") value if one value is missing. On the other hand, the "@" operations skip missing values. The latter property is crucial when you, for example, want to ignore land points for your ocean temperature average.
In other words, @SUM is NOT