Re: fill value bug?

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Fri, 20 Mar 2009 09:43:33 -0600

Yes ... this is a bug. IIRC, the int2flt function was written before
the "No_FillValue" option was available for the "new" statement.

By the way ... for the simple example below, I would
make "a" type float be multiplying by 1.0 directly.

a=(/123,345,678,-9999,-999,246/)*1.0
a@_FillValue=-9999

would work
D

Mary Haley wrote:
> Hi Michael,
>
> There appears to be a bug in "int2flt", which is part of
> contributed.ncl.
>
> Assuming "i" is the integer array you want to convert, the "int2flt"
> is doing this:
>
> dimi = dimsizes(i)
> fi = new( dimi, "float")
> fi = i ; values + meta data
>
> What's happening here is that when "fi" gets created,
> it has a default _FillValue of -999. Then when you do:
>
> fi = i
>
> this is going to cause any -999's in the array to be considered
> missing, because "fi" sees its own missing value, and not "i"'s
> missing value.
>
> Then, the code goes on to reset the _FillValue to -9999.
> However, the original -999 is still consider missing, so
> it gets changed to -9999, and the original -9999 values
> are now also considered missing.
>
> The fix is to set the float missing value when you call "new".
> Here's a new version of "int2flt" that you can try:
>
> function int2flt(i:integer)
> local dimi, fi
> begin
> dimi = dimsizes(i)
> if (isatt(i,"_FillValue")) then
> fi = new( dimi, "float", i@_FillValue)
> else
> fi = new( dimi, "float","No_FillValue")
> end if
>
> fi = i ; values + meta data
> return (fi)
> end
>
>
> On Fri, 20 Mar 2009, Michael Notaro wrote:
>
>
>> I seem to be encountering a bug. Imagine I have an array, a, with
>> 6 values. And I specify that -9999 is the FillValue. Then a value
>> of -999 should not be considered missing. However, after using
>> int2flt on a, then it converts the -999 into -9999, missing.
>>
>> a=(/123,345,678,-9999,-999,246/)
>> a@_FillValue=-9999
>> b=int2flt(a)
>> print(b)
>>
>> (0) 123
>> (1) 345
>> (2) 678
>> (3) -9999
>> (4) -9999
>> (5) 246
>>
>> This is a work-around:
>>
>> a=(/123,345,678,-9999,-999,246/)
>> a@_FillValue=-9999
>> b=a*1.
>> print(b)
>>
>> (0) 123
>> (1) 345
>> (2) 678
>> (3) -9999
>> (4) -999
>> (5) 246
>>
>> Any idea what's wrong here?
>> Mike
>> _______________________________________________
>> 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
>

-- 
======================================================
Dennis J. Shea                  tel: 303-497-1361    |
P.O. Box 3000                   fax: 303-497-1333    |
Climate Analysis Section                             |
Climate & Global Dynamics Div.                       |
National Center for Atmospheric Research             |
Boulder, CO  80307                                   |
USA                        email: shea 'at' ucar.edu |
======================================================
Received on Fri Mar 20 2009 - 09:43:33 MDT

This archive was generated by hypermail 2.2.0 : Mon Mar 23 2009 - 12:30:31 MDT