[ncl-talk] "sum" and "avg" functions without ignoring missing values

Arne Melsom arne.melsom at met.no
Fri Nov 24 04:01:40 MST 2017


Hi!
Since 'music piano' replied, I thought I might chime in ;)
I'm pretty sure that no option(s) to functions allow you to do what you
want.
So you'll need to write alternative functions yourself (perhaps not what
you consider 'an easy way'...)
You may use something like

aDim = dimsizes(a)
orgFill = a at _FillValue
newFill = -min(abs(a)) - 1    ; make sure newFill is out of range and <0
if (newFill .eq. orgFill) then  ; newFill must be different from orgFill
  newFill = newFill - 1
end if
newVar = ndtooned(a)
newVar at _FillValue = newFill
indx = ind(ismissing(newVar))
newVar(indx) = orgFill
newa = onedtond(newVar,aDim)

...and, if you later want to restore:
a = newa
a at _FillValue = orgFill

Hope this helps/clarifies!
Best regards,
Arne


2017-11-24 1:49 GMT+01:00 Rashed Mahmood <rashidcomsis at gmail.com>:

> Hello all,
> I am just wondering if there is an easy way to tell the "sum" and "avg"
> functions NOT ignore the missing values. Below lines clarify my question
> where I would like to see same values for c and d:
>
> ncl 0> a = (/(/-9.,2,-9./),(/1,-9.,2./)/)
> ncl 1> a at _FillValue = -9.
> ncl 2> c = (a(0,:)+a(1,:))
> ncl 3> d = dim_sum_n(a,0)
> ncl 4> print("  "+c+ " ... "+d)
> (0)       -9 ... 1
> (1)       -9 ... 2
> (2)       -9 ... 2
>
> Thanks,
> Rashed
>
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> 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/20171124/10418d95/attachment.html>


More information about the ncl-talk mailing list