[ncl-talk] Bug in stat_dispersion

Colin Zarzycki zarzycki at umich.edu
Thu Oct 16 16:12:56 MDT 2014


There appears to be a small (but potentially problematic!) bug in
stat_dispersion.

The second index returned in the stats array (ex: stat(1)) should be
standard deviation per the site documentation and function's internal print
routine. However, the function actually appears to return the variance
under the index.

in the actual function in contributed.ncl

<snip>
   if (nwork.gt.1) then
      ;statx(0) = avg(x)                ; mean
      ;statx(1) = stddev(x)             ; std. deviation
       moment   = dim_stat4( work )
       statx(0) = moment(0)             ; mean
       statx(1) = moment(1)             ; std. deviation <---------------

       qsort( work )                    ; sort into ascending order
       statx(2) = work(0)               ; min ( work )
<snip>

dim_stat4 should return variance in the (1) index, not stddev

This can be reproduced with the below code snippet:

;========================================================
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl"
;========================================================
begin

a = new(10,"float",-999)
a = (/1,2,3,4,5,6,7,8,9,10/)
;a(3) = a at _FillValue

opt = True
opt at PrintStat = True
statb = stat_dispersion(a, opt )

print("stdev = "+stddev(a))
print("variance = "+variance(a))

end

;========================================================

-Colin

-- 
Colin M. Zarzycki, ASP postdoctoral fellow
Atmospheric Modeling and Predictability
National Center for Atmospheric Research
http://www.colinzarzycki.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20141016/bc864320/attachment.html 


More information about the ncl-talk mailing list