<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">As a matter of fact it was, yes.<div class=""><br class=""></div><div class="">Slicing in Python works differently so that using 1:150 would yield an array with vertical dimension 149 and not 150. :) </div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">Il giorno 21 feb 2018, alle ore 19:25, Bill Ladwig <<a href="mailto:ladwig@ucar.edu" class="">ladwig@ucar.edu</a>> ha scritto:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Hi Guido,<div class=""><br class=""></div><div class="">Just at a quick glance, I see this in your NCL script:</div><div class=""><br class=""></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="margin: 0px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Monaco;" class="">w=data->w(:,1:150,ind_dry)</div></blockquote><div class=""><br class=""></div><div class="">In Python, you have this:</div><div class=""><br class=""></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"> <span style="font-family: 'Courier New', Courier, monospace, arial, sans-serif; font-size: 14px; white-space: pre-wrap;" class="">w=np.array(nc2.variables["w"][:][:,0:150,ind_dry])</span></blockquote><div class=""><br class=""></div><div class="">You've got difference slices going (both NCL and Python use 0-based indexes), was that intentional?</div><div class=""><br class=""></div><div class="">Bill</div><div class=""> </div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Wed, Feb 21, 2018 at 2:58 AM, Guido Cioni <span dir="ltr" class=""><<a href="mailto:guidocioni@gmail.com" target="_blank" class="">guidocioni@gmail.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space" class=""><div class="">Hey all,</div>I have a weird question addressed to experts of both NCL and Python. <div class=""><br class=""></div><div class="">In my effort to speed up a NCL script which computes the Moist Static Energy of updraft points and of the environment in a LES model simulation of diurnal convection, I've tried to translate the entire script into Python. I was interested to see whether Python was faster than NCL: long story short, it's not :) The problem is that my data is really big (72 x 150 x 1280000 points) so that a single assignment a = file->var takes approx. 40 minutes. A single plot takes about 3 hours to be produced. And I'm using no single loop! :) </div><div class=""><br class=""></div><div class="">But let's come to the problem. I have to select updrafts, which I defined as grid points having a vertical velocity of at least 1 m/s and a cloud water content of at least 1E-4 kg/kg. For these points I want to construct a vertical profile of moist static energy. Thus, it seems to me that using the where function was going to be my best shot. This is what I tried to do to select the grid points:</div><div class=""><br class=""></div><div class=""><div class=""><font face="Menlo" class=""> w_cloud=where(qc.gt.th_qc .and. w.ge.1, mse, mse@_FillValue)</font></div><div class=""><font face="Menlo" class=""> w_envir=where(qc.le.th_qc .or. w.lt.1, mse, mse@_FillValue)</font></div></div><div class=""><br class=""></div><div class="">And then averaged over time and space to get a single vertical profile (I know that NCL will take care of the missing values using these operations). The result is not bad..</div><div class=""><br class=""></div><div class=""></div></div><br class=""><div style="word-wrap:break-word;line-break:after-white-space" class=""><div class=""></div><div class="">The red line shows the difference <font face="Menlo" class="">w_cloud-w_envir</font> which is, as expected, positive meaning that updrafts are moister and warmer than the surrounding. </div><div class=""><br class=""></div><div class="">Coming to Python I decided to use a similar approach with numpy masked arrays</div><div class=""><br class=""></div><div class=""><div class=""><font face="Menlo" class="">mse_cloud_3D=np.ma.masked_<wbr class="">where( ((w<1) | (qc<1E-04)), mse)</font></div><div class=""><font face="Menlo" class="">mse_cloud=np.ma.mean(mse_<wbr class="">cloud_3D, axis=(0,2))</font></div><div class=""><font face="Menlo" class=""><br class=""></font></div><div class=""><font face="Menlo" class="">mse_envir_3D=np.ma.masked_<wbr class="">where( ((w>=1) & (qc>=1E-04)), mse)</font></div><div class=""><font face="Menlo" class="">mse_envir=np.ma.mean(mse_<wbr class="">envir_3D, axis=(0,2))</font></div></div><div class=""><br class=""></div><div class="">For the average MSE the profile looks almost exactly the same (good!) but the difference instead is completely different, also considering the order of magnitude.</div><div class=""></div></div><br class=""><div style="word-wrap:break-word;line-break:after-white-space" class=""><div class=""></div><div class=""><div class="">So my question is...what I'm doing wrong? How could the average MSE be fine and the difference between the updraft and the environment not? I would tend to trust more NCL as the masked arrays of numpy are behaving pretty weird sometimes.</div><div class=""><br class=""></div><div class="">I'm attaching the scripts cleaned as much as possible, although it is impossible (for obvious reasons) to send the data along :) </div><div class=""><br class=""></div><div class="">If anyone has opinion/comments...</div><div class=""><br class=""></div><div class="">Cheers </div><div class="">
<div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class=""></div></div></div></div><br class=""><div style="word-wrap:break-word;line-break:after-white-space" class=""><div class=""><div id="m_5904521279072121279AppleMailSignature" class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class=""></div></div></div></div><br class=""><div style="word-wrap:break-word;line-break:after-white-space" class=""><div class=""><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class=""><br class="m_-8336964382804577570Apple-interchange-newline">Guido Cioni</div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class=""><a href="http://guidocioni.altervista/" target="_blank" class="">http://guidocioni.altervista</a>.<wbr class="">org</div>
</div>
<br class=""></div></div><br class="">______________________________<wbr class="">_________________<br class="">
ncl-talk mailing list<br class="">
<a href="mailto:ncl-talk@ucar.edu" class="">ncl-talk@ucar.edu</a><br class="">
List instructions, subscriber options, unsubscribe:<br class="">
<a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" rel="noreferrer" target="_blank" class="">http://mailman.ucar.edu/<wbr class="">mailman/listinfo/ncl-talk</a><br class="">
<br class=""></blockquote></div><br class=""></div>
</div></blockquote></div><br class=""></div></body></html>