[ncl-talk] Bug in stat_dispersion

Dennis Shea shea at ucar.edu
Fri Oct 17 08:17:07 MDT 2014


THX. The fix will be in NCL v6.3.0

==
[1] The simplest fix is the to take the sqrt of the 1-th element upon return
          statd = stat_dispersion(x, False)
          statd(1) = sqrt( statd(1) )

[2] IMHO ... a better solution is to use an editor to extract the
stat_dispersion function from contributed.ncl

     vi  $NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl
<http://www.ncl.ucar.edu/Document/Functions/Contributed/contrib.shtml>

     Save the extracted code as a file named stat_dispersion.ncl

     Edit the stat_dispersion.ncl file:

       Change:  statx(1) = moment(1)
       To:           statx(1) = sqrt(moment(1))

     Save the file,

[3] explicitly load the corrected file

     load "./stat_dispersion.ncl'

D


On Thu, Oct 16, 2014 at 4:12 PM, Colin Zarzycki <zarzycki at umich.edu> wrote:

> 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
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20141017/6df4b2e8/attachment.html 


More information about the ncl-talk mailing list