[Thread Prev][Thread Next][Index]

Re: [ferret_users] masking with OR and undefined values doesn't work as expected



Hi Andrew,

thanks a lot! IFV and MISSING() are very helpful.

It would be convenient to mask with something like 'IFV (a OR b)' instead of, e.g., 'IFV a THEN 1 ELSE 1+0*b​' in order to have a mask of 1 where either of a or b is defined. But as OR is applied before IFV and drops the undefined values, that's not meant to be.

'let mask = IFV missing(a,b) THEN 1' is handy.

Don't know if I'll ever get rid of the -1E34 habit ;)


Have a good weekend,
Hella




On 07/21/2017 12:07 AM, Andrew Wittenberg - NOAA Federal wrote:
> ​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*b​
> yes? let mask = ​missing(1+0*a,0) OR missing(1+0*b,0)
> ​
> ​
> You can read about the MISSING() function and IFV command here:
> 
> http://ferret.pmel.noaa.gov/Ferret/documentation/users-
> guide/variables-xpressions/XPRESSIONS#_VPINDEXENTRY_327
> 
> http://ferret.pmel.noaa.gov/Ferret/documentation/users-guide
> /variables-xpressions/XPRESSIONS#_VPID_181
> 
> ​Here's an example:
> 
> % 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



[Thread Prev][Thread Next][Index]
Contact Us
Dept of Commerce / NOAA / OAR / PMEL / Ferret

Privacy Policy | Disclaimer | Accessibility Statement