# Re: How does the mask function work?

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Wed Mar 16 2011 - 08:34:36 MDT

I always use a verbal description to remind me how "mask" works:

"mask protects values in first argument at the locations where the second argument equals the third argument".

The statement:

would be:

"mask protects values in x at the locations where (f<3) is True"

which means z will be equal to x where f < 3, and missing everywhere else.

I've added a little more documentation to the documentation for "mask" to help clarify things.

--Mary

On Mar 14, 2011, at 12:19 PM, Dennis Shea wrote:

> The "mask" function 'Description' section states:
>
> "Missing values are placed in the output array in locations where marray
> is *not* equal to the mask value"
>
> It is wired differently than the way my brain works!
>
> The "where" function could be used also
> http://www.ncl.ucar.edu/Document/Functions/Built-in/where.shtml
>
> On 3/14/11 12:10 PM, John Kerfoot wrote:
>> Hi Gibies,
>>
>> Thanks for your response, but I'm still confused by the behavior.
>>
>> My understanding is that since I set the 3rd argument in the function
>> call to True:
>>
>> z = mask(x, (f.lt.3), True);
>>
>> That x should be masked at the points where the expression is true
>> (ie: everywhere that f is less than 3). So this should result in the
>> first 6 values of x:
>>
>> Variable: x
>> Type: integer
>> Total Size: 36 bytes
>> 9 values
>> Number of Dimensions: 1
>> Dimensions and sizes: [9]
>> Coordinates:
>> (0) 0
>> (1) 1
>> (2) 2
>> (3) 3
>> (4) 4
>> (5) 5
>> (6) 6
>> (7) 7
>> (8) 8
>>
>> getting masked because this is where the values in f are less than 3:
>>
>> Variable: f
>> Type: integer
>> Total Size: 36 bytes
>> 9 values
>> Number of Dimensions: 1
>> Dimensions and sizes: [9]
>> Coordinates:
>> (0) 1
>> (1) 1
>> (2) 1
>> (3) 2
>> (4) 2
>> (5) 2
>> (6) 3
>> (7) 3
>> (8) 3
>>
>> Your explanation (and the result from executing the code) seems to be
>> the opposite. Can you provide me with a little clarification?
>>
>> thanks again for your time and help.
>>
>> John
>>
>> On Mon, Mar 14, 2011 at 12:01 AM, gibies george<gibies@tropmet.res.in> wrote:
>>>
>>>
>>> On 14 March 2011 02:01, John Kerfoot<johnkerfoot@gmail.com> wrote:
>>>>
>>>> I've got a large AVHRR sea-surface temperature dataset for which I'm
>>>> trying to mask out some bad values; however I'm seeing some strange
>>>> looking for some clarification.
>>>>
>>>> Before getting to the AVHRR dataset, I tried the following to make
>>>> sure that I understood how mask worked:
>>>>
>>>> x = ispan(0,8,1);
>>>> print(x);
>>>>
>>>> f = (/1, 1, 1, 2, 2, 2, 3, 3, 3/);
>>>> print(f)
>>>>
>>>> : Mask all corresponding values in x where f is less than 3
>>>> z = mask(x, (f.lt.3), True);
>>>
>>>
>>> Here the function have Masked all corresponding values in x except where f
>>> is less than 3
>>>>
>>>> print(z);
>>>>
>>>> I expected the first 6 values of x to be set to the fill value, but
>>>> the opposite happened:
>>>>
>>>> Variable: x
>>>> Type: integer
>>>> Total Size: 36 bytes
>>>> 9 values
>>>> Number of Dimensions: 1
>>>> Dimensions and sizes: [9]
>>>> Coordinates:
>>>> (0) 0
>>>> (1) 1
>>>> (2) 2
>>>> (3) 3
>>>> (4) 4
>>>> (5) 5
>>>> (6) 6
>>>> (7) 7
>>>> (8) 8
>>>>
>>>>
>>>> Variable: f
>>>> Type: integer
>>>> Total Size: 36 bytes
>>>> 9 values
>>>> Number of Dimensions: 1
>>>> Dimensions and sizes: [9]
>>>> Coordinates:
>>>> (0) 1
>>>> (1) 1
>>>> (2) 1
>>>> (3) 2
>>>> (4) 2
>>>> (5) 2
>>>> (6) 3
>>>> (7) 3
>>>> (8) 3
>>>>
>>>
>>> Here the function have Masked all corresponding values in x except where f
>>> is less than 3
>>>
>>>>
>>>> Variable: z
>>>> Type: integer
>>>> Total Size: 36 bytes
>>>> 9 values
>>>> Number of Dimensions: 1
>>>> Dimensions and sizes: [9]
>>>> Coordinates:
>>>> Number Of Attributes: 1
>>>> _FillValue : -999
>>>> (0) 0
>>>> (1) 1
>>>> (2) 2
>>>> (3) 3
>>>> (4) 4
>>>> (5) 5
>>>> (6) -999
>>>> (7) -999
>>>> (8) -999
>>>>
>>>>
>>>>
>>>> So I'm clearly not understanding how to use this function. Can
>>>> someone explain this result? How can I get all values of x to be
>>>> masked where f is less than 3?
>>>>
>>>> Once I understand this, I'll have a follow up question using the AVHRR
>>>> datset.
>>>>
>>>> John
>>>> _______________________________________________
>>>> ncl-talk mailing list
>>>> List instructions, subscriber options, unsubscribe:
>>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>
>>>
>>>
>>> --
>>> Gibies George, CSIR-RF,
>>> Seasonal Scale Prediction Group,
>>> Climate and Global Modelling Division,
>>> Indian Institute of Tropical Meteorology,
>>> NCL (P. O.), Pashan,
>>> Pune 411008, India.
>>>
>>>
>>> Please Think about the environment. Save paper; Save Trees; and don't print
>>> this e-mail unless it is necessary.
>>>
>> _______________________________________________
>> ncl-talk mailing list
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Wed Mar 16 08:34:41 2011

This archive was generated by hypermail 2.1.8 : Wed Mar 16 2011 - 09:22:37 MDT