[Thread Prev][Thread Next][Index]

Re: [ferret_users] Adding non-consecutive levels containing missing values



Good ideas, Ryo.

There's a useful discussion about how transformations are done, here: "General Infrormation about Transformations"

And here's another way to define a mask,

! Define a list having the same number of values as the axis, and
! reshape it to the direction

let maskvals = { , 1, , 1 , , 1 , , , , 1 , 1}
let mask = reshape(maskvals, k[gz=myvar])

let myvar_masked = myvar* mask




On 2/26/2020 6:13 PM, Ryo Furue wrote:
Dear Fabio,

On Thu, Feb 27, 2020 at 6:32 AM 'Fabio B.' via _OAR PMEL Ferret Users <ferret_users@xxxxxxxx> wrote:

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 skipmissing 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

a(1)+ a(2)+ a(3)+ . . .

BUT

sum = 0
for i = 1 to N
if (a(i) is not missing) then
sum = sum+ a(i)
endif
endfor

Hope this helps.

Ryo


[Thread Prev][Thread Next][Index]