Re: Missing values and divide by zero

From: Dave Allured <dave.allured_at_nyahnyahspammersnyahnyah>
Date: Tue Apr 17 2012 - 16:14:37 MDT

Dave B,

Yes, I made some kind of fumble in my original testing for scalar.
Now I get the same consistent result that you get, divide by zero
error, for either scalar or array. Sorry about that confusion.

Let me generalize my request to any binary operator in the NCL core
language. Suppose A and B are any scalars, arrays, or expressions of
compatible dimensions. I would like to be assured that for any binary
operator, A .op. B can be protected from a computation error by
missing values on either side of the operator. In other words,
masking on either the left or right side should always suffice to
protect from illegal operations.

Divide by zero is only one example of a masking restriction. I see
that the integer mod operator "%" has the same problem as the normal
divide operator. There may be other cases, but I have not looked
farther. I wonder about other operators that might be internally
pre-tested "in the wrong order", such as exponentiation of negative
numbers.

If a fix is to be made, then I hope you can take care of division
first, because, er, we do that rather frequently in climatology. ;-)

This goes directly to the principle of missing value propagation that
you mentioned. NCL offers missing value propagation as an important
feature, but I see the current restriction as a gap in coverage. I
would like to rely on very simple rules for missing values and
expressions. The language is quirky and harder to use if we must
remember additional masking rules for certain operators. Thanks for
giving this due consideration.

-Dave

On Tue, Apr 17, 2012 at 2:33 PM, David Brown <dbrown@ucar.edu> wrote:
> Hi Dave,
>
> I see the behavior you describe for arrays. However, contrary to (1) below, I see the same behavior for scalars:
>
> ncl 9> z1 = -999.0
> ncl 10> z1@_FillValue = -999.0
> ncl 11> print(z1 / 0)
> fatal:divide: Division by 0, Can't continue
> fatal:Div: operator failed, can't continue
> fatal:["Execute.c":7514]:Execute: Error occurred at or near line 11
>
> ncl 12> z1 = (z1 / 0)
> fatal:divide: Division by 0, Can't continue
> fatal:Div: operator failed, can't continue
> fatal:["Execute.c":7514]:Execute: Error occurred at or near line 12
>
> ncl 13> print(z1)
>
> Variable: z1
> Type: float
> Total Size: 4 bytes
>            1 values
> Number of Dimensions: 1
> Dimensions and sizes:   [1]
> Coordinates:
> Number Of Attributes: 1
>  _FillValue :  -999
> (0)     -999
>
> Of course, since the "operator failed" the value remains the same as before. That is true whether the value is scalar or an array. In the case of an array, it seems that all values remain the same as before the operation, even those that could be operated on without error.
>
> If you have a counter-example of scalar division of a missing value by 0 working as in (1), please let us know.
>
> This is not to say that your proposed behavior does not have a lot of merit. We will consider making this change, considering that the docs say _FillValues should always propagate.
>  -dave
>
>
> On Apr 15, 2012, at 6:14 PM, Dave Allured wrote:
>
>> NCL support team,
>>
>> There seems to be inconsistent behavior when the numerator is a
>> missing value in simple division.  In the scalar case:
>>
>> (1)    missing value / 0 gives missing value
>>
>> In the array case:
>>
>> (2)    missing value / 0 gives a fatal error
>>
>> My interpretation of the current NCL manual is that (1) is the correct
>> behavior, and (2) is wrong.  Also, (1) is best behavior for clean user
>> programming.  I request that NCL be changed to correctly handle the
>> array case.  Either way, would you please explicitly document the
>> expected behavior for (missing divided by zero) in the NCL manual?
>>
>> There is a general workaround for user programs, by setting zeros in
>> the denominator array to missing values.  This is less desirable in
>> user cases when missing value information is already contained in the
>> numerator array.
>>
>> I found this behavior consistently through several versions of NCL
>> 5.2.0 through NCL 6.0.0 on Linux and Mac.
>>
>> Following is a short test case which ends in a fatal error.  Thank you
>> for your consideration.
>>
>> begin
>>   a = new (3, float)
>>   a(0) = 3.3
>>   a(2) = 5.5
>>   print ("A missing = " + ismissing (a))
>>   print (a)
>>
>> ; Note, a(1) should be a missing value.
>>
>>   b = (/ 4, 0, 4 /)
>>   print (b)
>>
>>   c = a / b
>>   print (c)
>> end
>>
>> --Dave
>> _______________________________________________
>> 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 Tue Apr 17 16:14:50 2012

This archive was generated by hypermail 2.1.8 : Fri Apr 20 2012 - 16:21:18 MDT