<div dir="ltr"><div><div><div>Hi Alan,<br></div>Yes both Dave's and your suggestion work.<br><br></div>Thanks,<br></div>Rashed<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Nov 24, 2017 at 5:25 PM, Alan Brammer <span dir="ltr"><<a href="mailto:abrammer@albany.edu" target="_blank">abrammer@albany.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_default" style="font-family:verdana,sans-serif"><div dir="auto" style="font-family:arial,sans-serif"><div dir="auto">Rashed,<br><br>How about the dim_avg_wgt_n() or dim_sum_wgt_n() variants. <br>They have a flag to deal with missing values, so you ca<div class="gmail_default" style="font-family:verdana,sans-serif;display:inline">n </div>just use a wgt of 1 for all values<div class="gmail_default" style="font-family:verdana,sans-serif;display:inline"> </div>but still use the missing value flag<div class="gmail_default" style="font-family:verdana,sans-serif;display:inline"></div>. <br><br><br><a href="http://www.ncl.ucar.edu/Document/Functions/Contributed/dim_sum_wgt_n_Wrap.shtml" target="_blank">http://www.ncl.ucar.edu/Docume<wbr>nt/Functions/Contributed/dim_<wbr>sum_wgt_n_Wrap.shtml</a><br>A scalar: (a) opt=0 means compute the weighted sum only if all values are not missing; (b) opt=1 means compute the weighted sum of all non-missing values; (c) opt>1 means to return the weighted sum only if the number of non-missing values is greater-than or equal to opt.<br><br>E.g. </div><div dir="auto"><br><div><div><font face="monospace, monospace">a = (/(/-9.,2,-9/),(/1,-9.,2./)/)</font></div><div><font face="monospace, monospace">a@_FillValue = -9. </font></div><div><font face="monospace, monospace">a_dims = dimsizes(a)</font></div><div><font face="monospace, monospace">dim=0</font></div><div><font face="monospace, monospace">wgt = new( a_dims(dim), float)</font></div><div><font face="monospace, monospace">wgt = 1</font></div><div><font face="monospace, monospace">c = dim_sum_wgt_n(a,wgt,0, dim)</font></div><div><font face="monospace, monospace">print(c)</font></div></div></div><div dir="auto"><div dir="auto"><font face="monospace, monospace"><br></font></div><div dir="auto"><font face="monospace, monospace">Variable: c</font></div><div dir="auto"><font face="monospace, monospace">Type: float</font></div><div dir="auto"><font face="monospace, monospace">Total Size: 12 bytes</font></div><div dir="auto"><font face="monospace, monospace"> 3 values</font></div><div dir="auto"><font face="monospace, monospace">Number of Dimensions: 1</font></div><div dir="auto"><font face="monospace, monospace">Dimensions and sizes:<span class="m_8254767096133248869gmail-m_-1454584694040614666gmail-Apple-tab-span" style="white-space:pre-wrap"> </span>[3]</font></div><div dir="auto"><font face="monospace, monospace">Coordinates:</font></div><div dir="auto"><font face="monospace, monospace">Number Of Attributes: 1</font></div><div dir="auto"><font face="monospace, monospace"> _FillValue :<span class="m_8254767096133248869gmail-m_-1454584694040614666gmail-Apple-tab-span" style="white-space:pre-wrap"> </span>-9</font></div><div dir="auto"><font face="monospace, monospace">(0)<span class="m_8254767096133248869gmail-m_-1454584694040614666gmail-Apple-tab-span" style="white-space:pre-wrap"> </span>-9</font></div><div dir="auto"><font face="monospace, monospace">(1)<span class="m_8254767096133248869gmail-m_-1454584694040614666gmail-Apple-tab-span" style="white-space:pre-wrap"> </span>-9</font></div><div dir="auto"><font face="monospace, monospace">(2)<span class="m_8254767096133248869gmail-m_-1454584694040614666gmail-Apple-tab-span" style="white-space:pre-wrap"> -9</span></font></div></div><div dir="auto"><br></div><div dir="auto"><br></div><div dir="auto"><br></div><div dir="auto"><br></div><div dir="auto">Good luck, </div><span class="HOEnZb"><font color="#888888"><div dir="auto"><div class="gmail_default" style="font-family:verdana,sans-serif">Alan</div><br></div></font></span></div></div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On Fri, Nov 24, 2017 at 3:07 PM, Dave Allured - NOAA Affiliate <span dir="ltr"><<a href="mailto:dave.allured@noaa.gov" target="_blank">dave.allured@noaa.gov</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr">Oops, I missed something. dim_cumsum returns an array of the same shape as the input. To get the desired "final sum" array of rank n-1, you must take the last slice of the function result array. For dim_cumsum_n, you must similarly take the last slice along dimension number n.<div><br></div><div><font face="monospace, monospace"> Let a be dimensioned (3,4,5). Then:</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace"> nz = dimsizes(a(0,0,:))</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace"> opt = 0</font></div><div><font face="monospace, monospace"> b3d = dim_cumsum (a, opt) ; dimensions (3,4,5)</font></div><div><font face="monospace, monospace"> b = b3d(:,:,nz-1) ; dimensions (3,4)<span class="m_8254767096133248869HOEnZb"><font color="#888888"><br></font></span></font><span class="m_8254767096133248869HOEnZb"><font color="#888888"><div><br></div><div>--Dave</div></font></span></div><div><div class="m_8254767096133248869h5"><div class="gmail_extra"><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Nov 24, 2017 at 12:52 PM, Rashed Mahmood <span dir="ltr"><<a href="mailto:rashidcomsis@gmail.com" target="_blank">rashidcomsis@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Thanks Dave, that is exactly what I was looking for...<br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Nov 24, 2017 at 11:46 AM, Dave Allured - NOAA Affiliate <span dir="ltr"><<a href="mailto:dave.allured@noaa.gov" target="_blank">dave.allured@noaa.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Rasheed,<div><br></div><div>I think dim_cumsum and dim_cumsum_n with opt=0 are intended for this purpose. There is no corresponding function for "avg". However, simply dividing the result array from dim_cumsum by N should give the correct array result, with no extra "if" or "where" statement.</div><span class="m_8254767096133248869m_3039093433360599363m_-8148359641793117502HOEnZb"><font color="#888888"><div><br></div><div>--Dave</div></font></span><div><div class="m_8254767096133248869m_3039093433360599363m_-8148359641793117502h5"><div><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Nov 24, 2017 at 12:29 PM, Rashed Mahmood <span dir="ltr"><<a href="mailto:rashidcomsis@gmail.com" target="_blank">rashidcomsis@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div>Hi Arne,<br></div><br></div><div>Thanks for trying to answer the question, however, the things you mentioned would add confusion and possibly wrong results. <br>Actually I know how to achieve what I want using a do loop. For example, let us say we have variable a = (ntimes,nlevel,nlat,nlon) and we want to do sum over time domain which can easily be done using: (dim_sum_n(a,0)), Now the results would be sum over all non-missing values of time1,time2,time2...timeN, which is correct. <br></div><div><br></div><div>But if I want to do sum ONLY when all of the values of time1,time2,time3...timeN are non-missing then we can do this:<br> </div><div> dimz = dimsizes(a)<br></div> b = new(/dimz(1),dimz(2),dimz(3),f<wbr>loat)<br><div> b@_FillValue = a@_FillValue</div><div> <br></div><div> b(:,:,:) = 0. <br></div><div> do n=0,dimz(0)-1</div><div> b = b+a(n,:,:,:)<br></div><div> end do<br></div><div><br></div><div>I just wanted to avoid the loop and use the "sum" function for efficiency. I hope this clarifies the question a bit more.</div><div><br></div><div>Cheers,</div><div>Rashed</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Nov 24, 2017 at 3:01 AM, Arne Melsom <span dir="ltr"><<a href="mailto:arne.melsom@met.no" target="_blank">arne.melsom@met.no</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi!<div>Since 'music piano' replied, I thought I might chime in ;)<br><div>I'm pretty sure that no option(s) to functions allow you to do what you want.</div><div>So you'll need to write alternative functions yourself (perhaps not what you consider 'an easy way'...)</div><div>You may use something like</div><div><br></div><div><div>aDim = dimsizes(a)</div><div>orgFill = a@_FillValue</div><div>newFill = -min(abs(a)) - 1 ; make sure newFill is out of range and <0 </div><div>if (newFill .eq. orgFill) then ; newFill must be different from orgFill</div><div> newFill = newFill - 1</div><div>end if</div><div>newVar = ndtooned(a)</div><div>newVar@_FillValue = newFill</div><div>indx = ind(ismissing(newVar))</div><div>newVar(indx) = orgFill</div><div>newa = onedtond(newVar,aDim)</div><div><br></div><div>...and, if you later want to restore:</div><div>a = newa</div><div>a@_FillValue = orgFill</div></div><div><br></div><div>Hope this helps/clarifies!</div><div>Best regards,</div><div>Arne</div><div><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="m_8254767096133248869m_3039093433360599363m_-8148359641793117502m_5616204217699992538m_7506295658437281984h5">2017-11-24 1:49 GMT+01:00 Rashed Mahmood <span dir="ltr"><<a href="mailto:rashidcomsis@gmail.com" target="_blank">rashidcomsis@gmail.com</a>></span>:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="m_8254767096133248869m_3039093433360599363m_-8148359641793117502m_5616204217699992538m_7506295658437281984h5"><div dir="ltr"><div><div><div>Hello all,<br></div>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:<br><br>ncl 0> a = (/(/-9.,2,-9./),(/1,-9.,2./)/)<br>ncl 1> a@_FillValue = -9. <br>ncl 2> c = (a(0,:)+a(1,:))<br>ncl 3> d = dim_sum_n(a,0)<br>ncl 4> print(" "+c+ " ... "+d)<br>(0) -9 ... 1<br>(1) -9 ... 2<br>(2) -9 ... 2<br><br></div>Thanks,<br></div>Rashed</div></div></div></blockquote></div></div></blockquote></div></div></blockquote></div></div></div></div></div></div></blockquote></div></div></blockquote></div></div></div></div></div>
<br></div></div><span class="">______________________________<wbr>_________________<br>
ncl-talk mailing list<br>
<a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</a><br>
List instructions, subscriber options, unsubscribe:<br>
<a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" rel="noreferrer" target="_blank">http://mailman.ucar.edu/mailma<wbr>n/listinfo/ncl-talk</a><br>
<br></span></blockquote></div><br></div>
</blockquote></div><br></div>