[Thread Prev][Thread Next][Index]
Re: [ferret_users] masking with OR and undefined values doesn't work as expected
- To: Andrew Wittenberg - NOAA Federal <andrew.wittenberg@xxxxxxxx>
- Subject: Re: [ferret_users] masking with OR and undefined values doesn't work as expected
- From: "Riede, Hella" <hella.riede@xxxxxxx>
- Date: Fri, 21 Jul 2017 16:04:52 +0000
- Accept-language: en-US, de-DE
- Arc-authentication-results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of hella.riede@xxxxxxx designates 192.67.218.51 as permitted sender) smtp.mailfrom=hella.riede@xxxxxxx
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:content-transfer-encoding:content-id:fcc:user-agent :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:cc:to:from :arc-authentication-results; bh=l8n8uVEYOMqmOZhuDAqV7V1LCrGuEFskmPrYYcbpe2Q=; b=Sjv9A7Y3rtVcOmAvcdIo0a2Sa4oMbjcfnSNR1/1Lbw+Svv8yx8GbxliKcahyUsTtaS beWhZJhlXuCgXhgrszBp2DMkxuQ2W7nsUqUAoSVwNxrI8sbLihnFCXjv4NhgVHXJJ2WE J1tlpDFspAuZvjsLe9oXPN4aaeoKUPZNkzMm2perOIUrrL+8go3v2pfs6uLWo0QYWtOr qmHquBbmE5LJjNcReqDeWXYgRlwlBSKpohkyAEeXz8geT0ZditdXIFQzk/Mb+VhaEgB2 z1R11ZAQpmk4tIVdthGq+CcAX4jvn/3BN857O5kCe9HVL4iN9h3eevREhb7h9dtACp1W 2WIw==
- Arc-seal: i=1; a=rsa-sha256; t=1500653101; cv=none; d=google.com; s=arc-20160816; b=S7NOBvxiICQMkyYMUMRTGfSjHuWeFiFyW4NofChzVPrQtPJlj8+E9109vpLBDc9FKV 3rI9OQA5q49T1nsgPfJEWCVogtH5WqP1sXFG7BlD6axGzkwox4PGFLMPTx0tnfW4iIx3 Ygeh/HA2qGSzlWaIEDgHn8sgG4C6lUYc4hlk/OMIfMbsXHFENnslEFot/3K2nwGMA5EQ 4iIacHRVxU6dUprb+8kvIovj50uzgbrf63RKrfQXWN8YpbNKR9zYpOi8/onPCJhzx4i5 oxhS9wvCV6UrhxnE9XYl+lQI7Xu0rDeFpu6iTrnq2bAYl/gjUePrEmSfyiclRmv4Ebwv TH6g==
- Cc: ferret users <ferret_users@xxxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=noaa-gov.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:thread-topic:thread-index:date:message-id :references:in-reply-to:accept-language:content-language:user-agent :fcc:content-id:content-transfer-encoding:mime-version :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:list-post:list-help:list-archive; bh=l8n8uVEYOMqmOZhuDAqV7V1LCrGuEFskmPrYYcbpe2Q=; b=FbAAlFTzFFcLqq2v9Lb2uxdr5FV/cI+Q9t+jUxoVCP9SH3chC6p7qTBEeuGHHajeuU /gTx0euAn2Rgy+8jOpib7hdHvMdf8KJjZq0PMU+g1Z78g32lXb7RXqtqw7ewiLj0qT/n 8zaWwAUVyHHGFmtJZtYaozdQWELpFtQk8oOny+8BDWfQu+nLeAaLOTynGsSPPckPO4wq H0OE440MkiVr/pwHi+/0rb/ntbPnZVpqBvhHEMohFjnMD+34f3sYk8vE98DozapcSxsj u8dm7pYKWxUS9FYchy4KxgkIoeMMfmEERmh6+c9OZJrO0AgcUxkGfuXVnofwjC5N2Nav /8og==
- Fcc: imap://hella.riede@xxxxxxxxxxxx/Sent Items
- In-reply-to: <CAKoe08SdwdPHNwFQ-TypnbXaER-gzFyatapowsA0YFh3=zCFOQ@mail.gmail.com>
- List-archive: <https://groups.google.com/a/noaa.gov/group/ferret_users/>
- List-help: <https://support.google.com/a/noaa.gov/bin/topic.py?topic=25838>, <mailto:ferret_users+help@noaa.gov>
- List-id: <ferret_users.noaa.gov>
- List-post: <https://groups.google.com/a/noaa.gov/group/ferret_users/post>, <mailto:ferret_users@noaa.gov>
- Mailing-list: list ferret_users@xxxxxxxx; contact ferret_users+owners@xxxxxxxx
- References: <e1e0cd1d-3033-5695-661c-1eaf1e65add4@mpic.de> <CAKoe08SdwdPHNwFQ-TypnbXaER-gzFyatapowsA0YFh3=zCFOQ@mail.gmail.com>
- Sender: owner-ferret_users@xxxxxxxx
- Thread-index: AQHTAXsuPLhVilUxRk2X10SP3MHqt6JdJJ6AgAFOT4A=
- Thread-topic: [ferret_users] masking with OR and undefined values doesn't work as expected
- User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1
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