Hi
Hella,
"
M
issing" points a
re
neither true
(nonzero)
or false
(zero)
, but undefined
--
hence
Ferret's
special treatment of operations involving those values. It's actually
really
nice that Ferret does this
,
since it
offers
precise control over what to do at missing points.
If you want to the mask to be 1 where either A or B is valid, and "missing" where both A and B are missing, then just do:
yes? let mask = 1+0*missing(a,b)
And here are three alternatives that do the same thing:
yes?
let mask = IFV missing(a,b) THEN 1
yes? let mask = IFV a THEN 1 ELSE 1+0*byes? let mask = missing(1+0*a,0) OR missing(1+0*b,0)
You can read about the MISSING() function and IFV command here:
% ferret
NOAA/PMEL TMAP
FERRET v7.2 (optimized)
Linux 2.6.32-696.3.1.el6.x86_64 64-bit - 07/13/17
20-Jul-17 16:30
yes? let a = {0,0,1,1,2,,4,}
yes? let b = {0,1,0,1,3,,,6}
yes?
list/noh
ead
/p
recision
=3 a, b, a OR b, 1+0*missing(a,b)
1 / 1: 0.00 0.00 0.00 1.00
2 / 2: 0.00 1.00 1.00 1.00
3 / 3: 1.00 0.00 1.00 1.00
4 / 4: 1.00 1.00 1.00 1.00
5 / 5: 2.00 3.00 1.00 1.00
6 / 6: .... .... .... ....
7 / 7: 4.00 .... .... 1.00
8 / 8: .... 6.00 .... 1.00
Note that in a list, empty elements indicate mi
ssing values
,
so
you don't have to
remember
what the missing value is
:
e.g. {1,,3} or {,5} or {6,}.
Andrew
On Thu, Jul 20, 2017 at 1:11 PM, Hella Riede <
hella.riede@xxxxxxx> wrote:
>
> Hi ferreters, hi developers,
>
>
> masking is a bit counterintuitive in ferret when involving undefined values:
>
>
> yes? let a = {1,2,-1E34,4}
> yes? let b = {1,-1E34,3,4}
> yes? let bla = if (a OR b) then 1
> yes? list bla
> VARIABLE : IF (A OR B) THEN 1
> SUBSET : 4 points (X)
> 1 / 1: 1.000
> 2 / 2: ....
> 3 / 3: ....
> 4 / 4: 1.000
>
> 'OR' implies that 'bla' should be equal to 1 for all 4 data points, because at all 4 points either a or b is actually defined. However, it sets all points to undefined that are undefined in either a or b.
>
>
> Also this not very elegant version won't work:
>
> yes? let bla = if (a NE -1E34 OR b NE -1E34) then 1
> yes? list bla
> VARIABLE : IF (A NE -1E34 OR B NE -1E34) THEN 1
> SUBSET : 4 points (X)
> 1 / 1: 1.000
> 2 / 2: ....
> 3 / 3: ....
> 4 / 4: 1.000
>
>
> Of course this is only a problem when undefined values are involved. Otherwise masking with OR works as expected:
>
> yes? let a = {1,1,2,1}
> yes? let b = {1,2,1,1}
> yes? let bla = if (a EQ 2 OR b EQ 2) then 1
> yes? list bla
> VARIABLE : IF (A EQ 2 OR B EQ 2) THEN 1
> SUBSET : 4 points (X)
> 1 / 1: ....
> 2 / 2: 1.000
> 3 / 3: 1.000
> 4 / 4: ....
>
>
> A workaround is to set undefined values to zero and then do the masking. However, this makes 'real' zero values indistinguishable from undefined values, which could otherwise be kept apart by 'if (a or a EQ 0) then ...'.
>
> Sorry if I missed a note on this in the ferret documentation.
>
>
>
> Best wishes,
> Hella