# Re: missing value in array operating

From: Dave Allured - NOAA Affiliate <dave.allured_at_nyahnyahspammersnyahnyah>
Date: Wed Mar 13 2013 - 11:48:01 MDT

Good question. In NCL, missing values propagate through the ordinary
math OPERATORS (+ - * / etc.). So in the general case for most math
operators "#", A # B results in a missing value if EITHER A or B is
missing, OR BOTH. This holds true for the individual elements of
array expressions A(j) # B(j), as well as for scalar expressions.

However, many of the math ARRAY FUNCTIONS (dim_sum, dim_avg, etc.)
truly ignore missing values, rather than propagating them. Look for
this feature in the function documentation. For example, the result
of dim_sum ((/ A, B, C //) is missing only if ALL of A, B, C are
missing. If ANY A, B, C are NOT missing, then the result is a partial
sum, a valid non-missing number.

An easy way to extend your example is like this:

a = ((/3/), float, -9999.0)
b = ((/3/), float, -9999.0)
a = (/-9999.0, 0, 2/)
b = (/1, -9999.0, 3/)

ab = (/ a, b /) ; concatenate two 1-D arrays to make a 2-D array
c = dim_sum_n (ab, 0)

And the result is (/1, 0, 5/), what you wanted.

For more complex calculations, you might need to use use missing value
masks and the "where" function. But for simple calculations like sums
or averages of array data, the code is much simpler if you take
advantage of library math functions that have the missing value
feature.

--Dave

On Wed, Mar 13, 2013 at 8:15 AM, Zhifeng Yang <yangzf01@gmail.com> wrote:
> Hi all
>
> I have the following problem when I try to add two arrays, both including
> missing value.
>
> For example,
> a = ((/3/), float, -9999.0)
> b = ((/3/), float, -9999.0)
> a = (/-9999.0, 0, 2/)
> b = (/1, -9999.0, 3/)
> c = a + b
>
> Finally I get c = (/-9999.0, -9999.0, 5/). however what I supposed should be
> (/1, 0, 5/)
>
> So how can I set up to ignore missing value and get the results that I want.
>
> Thank you
> Bruce
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Wed Mar 13 09:48:14 2013

This archive was generated by hypermail 2.1.8 : Wed Mar 13 2013 - 14:19:38 MDT