Re: possible bug in wgt_areaave

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Tue Jul 24 2012 - 08:28:15 MDT

Hi Lauren,

According to the documentation for wgt_areaave, it does this calculation:

   x_ave = SUM[x*wgty*wgtx]/SUM[wgty*wgtx]

In your two cases where x had 0.0 values for one set, and missing values for the other, the numerator produces the same value: 6.8284270763397217.
This is because you put the 0's and the missing values in the same location.

The denominator, however, is different, because in the case where x has no missing values, the summation occurs across *all* your "cost" values.
In the case where "x" contains missing values, then only the corresponding weights for non-missing x values are summed.

Hence, you are dividing the 6.8284270763397217 by two different values:

 SUMT = 6.8284270763397217
 SUMW = 4.8284269014941685
 AVE = SUMT/SUMW = 1.4142136177367930

 SUMT = 6.8284270763397217
 SUMW = 4.1213203072547913
 AVE = SUMT/SUMW = 1.6568542523422869

This is kind of similar to why these two produce different results:

   x = (/0,2,3,4,0/)
   print(avg(x)) ; 1.8 ((2+3+4)/5)

   x = (/-99,2,3,4,-99/)
   x@_FillValue = -99
   print(avg(x)) ; 3 ((2+3+4)/3)

--Mary

On Jul 23, 2012, at 10:36 PM, <Lauren.Stevens@csiro.au> <Lauren.Stevens@csiro.au> wrote:

> Hi NCL-Talk,
>
> I am running the attached script using:
>
> NCAR Command Language Version 6.0.0
>
> and a Linux machine.
>
> I just had a question about how wgt_areave should work with missing values.
> Please have a look at the script and tell me if the function wgt_areaave is doing the right thing.
> It's probably something I'm missing but your help would be appreciated.
>
> Kind Regards, Lauren
> <NCL_wgt_areaave_test.rtf>_______________________________________________
> 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 Jul 24 08:28:24 2012

This archive was generated by hypermail 2.1.8 : Tue Jul 24 2012 - 09:48:26 MDT