[ncl-talk] dim_sum_wgt problem with opt=0

Mattia Righi Mattia.Righi at dlr.de
Mon Sep 8 02:01:59 MDT 2014


Dear NCL users,

I'm writing to report a problem with the built-in function dim_sum_wgt.

According to the documentation

http://www.ncl.ucar.edu/Document/Functions/Built-in/dim_sum_wgt.shtml

this function calculates the weighted sum of an input array only if all 
values are non-missing (opt=0) OR considering only the non-missing 
values (opt=1).

This however seems not to be the case for opt=0.
See the attached test script: the first print statement (opt=0) should 
return a missing, given that the input array contains 2 missing values.

Note that the same calculation with the analogous dim_avg_wgt function
provides the expected result, so this seems to be a problem only in 
dim_sum_wgt.

NCL version: 6.2.0.

Thanks for your help!
Best regards,
Mattia

-- 
--------------------------------------------------------------
Dr. Mattia Righi
Deutsches Zentrum fuer Luft- und Raumfahrt (DLR)
Institut fuer Physik der Atmosphaere
Muenchner Strasse 20
D-82234 Wessling - Germany

  Telephone +49 8153 28 1813
  Telefax   +49 8153 28 1841
  E-mail    Mattia.Righi at dlr.de
  Internet  http://www.pa.op.dlr.de/~MattiaRighi/
--------------------------------------------------------------
-------------- next part --------------
; Bug in dim_sum_wgt?
begin

    xx = (/3.7, 1e20, 14.3, 1e20, 7.1 /) 
    xx at _FillValue = 1e20
    ww = (/1,3,5,3,1/)

    print(dim_sum_wgt(xx,ww,0))   ;; this should give 1e+20
    print(dim_sum_wgt(xx,ww,1))   ;; OK
    print(3.7*1 + 14.3*5 + 7.1*1) ;; OK

    ;; Check that missing values are correctly set
    print("-------------")
    print(num(ismissing(xx)))
    print(ind(ismissing(xx)))

    ;; Same test with the analogous function for weighted average
    print("-------------")
    print(dim_avg_wgt(xx,ww,0))             ;; OK
    print(dim_avg_wgt(xx,ww,1))             ;; OK
    print((3.7*1 + 14.3*5 + 7.1*1)/(1+5+1)) ;; OK

end


More information about the ncl-talk mailing list