<div dir="ltr">Hi Guido,<div><br></div><div>Just at a quick glance, I see this in your NCL script:</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<p class="gmail-p1" 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">w=data->w(:,1:150,ind_dry)</p></blockquote><div><br></div><div>In Python, you have this:</div><div><br></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="color:rgb(0,0,0);font-family:"Courier New",Courier,monospace,arial,sans-serif;font-size:14px;white-space:pre-wrap">w=np.array(nc2.variables["w"][:][:,0:150,ind_dry])</span></blockquote><div><br></div><div>You've got difference slices going (both NCL and Python use 0-based indexes), was that intentional?</div><div><br></div><div>Bill</div><div> </div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Feb 21, 2018 at 2:58 AM, Guido Cioni <span dir="ltr"><<a href="mailto:guidocioni@gmail.com" target="_blank">guidocioni@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 style="word-wrap:break-word;line-break:after-white-space"><div>Hey all,</div>I have a weird question addressed to experts of both NCL and Python. <div><br></div><div>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><br></div><div>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><br></div><div><div><font face="Menlo"> w_cloud=where(qc.gt.th_qc .and. w.ge.1, mse, mse@_FillValue)</font></div><div><font face="Menlo"> w_envir=where(qc.le.th_qc .or. w.lt.1, mse, mse@_FillValue)</font></div></div><div><br></div><div>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><br></div><div></div></div><br><div style="word-wrap:break-word;line-break:after-white-space"><div></div><div>The red line shows the difference <font face="Menlo">w_cloud-w_envir</font> which is, as expected, positive meaning that updrafts are moister and warmer than the surrounding. </div><div><br></div><div>Coming to Python I decided to use a similar approach with numpy masked arrays</div><div><br></div><div><div><font face="Menlo">mse_cloud_3D=np.ma.masked_<wbr>where( ((w<1) | (qc<1E-04)), mse)</font></div><div><font face="Menlo">mse_cloud=np.ma.mean(mse_<wbr>cloud_3D, axis=(0,2))</font></div><div><font face="Menlo"><br></font></div><div><font face="Menlo">mse_envir_3D=np.ma.masked_<wbr>where( ((w>=1) & (qc>=1E-04)), mse)</font></div><div><font face="Menlo">mse_envir=np.ma.mean(mse_<wbr>envir_3D, axis=(0,2))</font></div></div><div><br></div><div>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></div></div><br><div style="word-wrap:break-word;line-break:after-white-space"><div></div><div><div>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><br></div><div>I'm attaching the scripts cleaned as much as possible, although it is impossible (for obvious reasons) to send the data along :) </div><div><br></div><div>If anyone has opinion/comments...</div><div><br></div><div>Cheers </div><div>
<div style="color:rgb(0,0,0);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"></div></div></div></div><br><div style="word-wrap:break-word;line-break:after-white-space"><div><div id="m_5904521279072121279AppleMailSignature"><div style="color:rgb(0,0,0);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"></div></div></div></div><br><div style="word-wrap:break-word;line-break:after-white-space"><div><div><div style="color:rgb(0,0,0);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"><br class="m_-8336964382804577570Apple-interchange-newline">Guido Cioni</div><div style="color:rgb(0,0,0);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"><a href="http://guidocioni.altervista" target="_blank">http://guidocioni.altervista</a>.<wbr>org</div>
</div>
<br></div></div><br>______________________________<wbr>_________________<br>
ncl-talk mailing list<br>
<a href="mailto:ncl-talk@ucar.edu">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/<wbr>mailman/listinfo/ncl-talk</a><br>
<br></blockquote></div><br></div>