[Thread Prev][Thread Next][Index]

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



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

 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]
Contact Us
Dept of Commerce / NOAA / OAR / PMEL / Ferret

Privacy Policy | Disclaimer | Accessibility Statement