<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">Thanks for the reply<div><br></div><div>shouldn't this</div><div>grid_stats(68,160,:) = stat_dispersion( ta(:,68,160), opt)</div><div><br></div><div>be changed to </div><div><br></div><div>grid_stats(68,160,3) = stat_dispersion( ta(:,68,160), opt)<br></div><div><br></div><div>to obtain the 10th Percentile ?</div><div><br></div><div>when I do it I get the following error</div><div><br></div><div><div>fatal:VarVarWrite: Number of dimensions on left hand side does not match right hand side</div><div>fatal:["Execute.c":8576]:Execute: Error occurred at or near line 41</div></div><div><br></div><div><br></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jul 1, 2021 at 3:27 PM Muhammad Omer Mughal <<a href="mailto:m.mughal1@graduate.curtin.edu.au">m.mughal1@graduate.curtin.edu.au</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">




<div dir="ltr">
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
Ali </div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
This was a suggestion.</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div>
<div id="gmail-m_-1656228484489191427Signature">
<div>
<div id="gmail-m_-1656228484489191427divtagdefaultwrapper" style="font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255);font-family:Calibri,Arial,Helvetica,sans-serif">
<div style="font-family:Tahoma;font-size:13px">
<div style="font-family:Tahoma;font-size:13px"><b><br>
</b></div>

<div style="color:rgb(33,33,33);font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif;font-size:15.4545px;margin:0px;background-color:rgb(255,255,255)">
<font face="Times New Roman,serif" size="3"><span style="font-size:12pt"><font face="Arial,sans-serif" size="1" color="#1F497D"><span style="font-size:6pt"><br>
</span></font></span></font></div>
<div style="color:rgb(33,33,33);font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif;font-size:15.4545px;margin:0px;background-color:rgb(255,255,255)">
<font face="Times New Roman,serif" size="3"><span style="font-size:12pt"><font face="Arial,sans-serif" size="1" color="#1F497D"><span style="font-size:6pt"><br>
</span></font></span></font></div>
</div>
</div>
</div>
</div>
</div>
<div id="gmail-m_-1656228484489191427appendonsend"></div>
<hr style="display:inline-block;width:98%">
<div id="gmail-m_-1656228484489191427divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Muhammad Omer Mughal <<a href="mailto:m.mughal1@graduate.curtin.edu.au" target="_blank">m.mughal1@graduate.curtin.edu.au</a>><br>
<b>Sent:</b> Thursday, 1 July 2021 3:22 PM<br>
<b>To:</b> ali mughal <<a href="mailto:mughalali655@gmail.com" target="_blank">mughalali655@gmail.com</a>>; Buzan, Jonathan <<a href="mailto:jbuzan@purdue.edu" target="_blank">jbuzan@purdue.edu</a>><br>
<b>Cc:</b> Ncl-talk <<a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</a>><br>
<b>Subject:</b> Re: [ncl-talk] stat_despersion</font>
<div> </div>
</div>

<div dir="ltr">
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
I used the following script . I also copied the result at the end of the script. Can it be due to the reason that the value is too small </div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
 </div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
a=addfile("BEM_April","r")
<div>ta_mean_BEM=a->TA_MEAN
<div>ta=ta_mean_BEM(24:719,0,:,:)</div>
ta=ta-273.16<br>
</div>
<div><br>
</div>
<div>opt=False</div>
<div></div>
</div>
<div>      nlat=dimsizes(nlat1)</div>
<div>     mlon=dimsizes(mlon1)<br>
</div>
    grid_stats = new ((/nlat,mlon,30/), typeof(ta), getFillValue(ta))<br>
<div>    grid_stats(68,160,:) = stat_dispersion( ta(:,68,160), opt)</div>
<div>    printMinMax (grid_stats, False)</div>
<div>   </div>
<div>(0)     Robust Dispersion Statistics: min=-0.552326   max=696<br>
</div>
<div><br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<span style="font-size:6pt"><br>
</span></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<span style="font-size:6pt"><br>
</span></div>
<div id="gmail-m_-1656228484489191427x_appendonsend"></div>
<hr style="display:inline-block;width:98%">
<div id="gmail-m_-1656228484489191427x_divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> ncl-talk <<a href="mailto:ncl-talk-bounces@mailman.ucar.edu" target="_blank">ncl-talk-bounces@mailman.ucar.edu</a>> on behalf of Buzan, Jonathan via ncl-talk <<a href="mailto:ncl-talk@mailman.ucar.edu" target="_blank">ncl-talk@mailman.ucar.edu</a>><br>
<b>Sent:</b> Thursday, 1 July 2021 2:24 PM<br>
<b>To:</b> ali mughal <<a href="mailto:mughalali655@gmail.com" target="_blank">mughalali655@gmail.com</a>><br>
<b>Cc:</b> Ncl-talk <<a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</a>><br>
<b>Subject:</b> Re: [ncl-talk] stat_despersion</font>
<div> </div>
</div>
<div style="overflow-wrap: break-word;">Hello,
<div><br>
</div>
<div>You should try 1 grid cell first and print the values and print the stat_dispersion, and double check that you are feeding the array the correct data. </div>
<div><br>
</div>
<div>-Jonathan</div>
<div><br>
</div>
<div><br>
<div><br>
<blockquote type="cite">
<div>On Jul 1, 2021, at 5:52 AM, ali mughal via ncl-talk <<a href="mailto:ncl-talk@mailman.ucar.edu" target="_blank">ncl-talk@mailman.ucar.edu</a>> wrote:</div>
<br>
<div>
<div dir="ltr">
<div dir="ltr">Sorry a correction to the above email is that all values in grid_stats, tenthP and nintythP are 0.</div>
</div>
<br>
<div>
<div dir="ltr">On Thu, Jul 1, 2021 at 11:49 AM ali mughal <<a href="mailto:mughalali655@gmail.com" target="_blank">mughalali655@gmail.com</a>> wrote:<br>
</div>
<blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div dir="ltr">
<div dir="ltr">Dear All 
<div><br>
</div>
<div>Here is how I have modified the code according to your suggestions. However, I am getting all values in the output of grid_stats.and when I try plotting the tenth percentile I also have a zero value.  I will be extremely grateful for your support.</div>
<div><br>
</div>
<div><br>
</div>
<div>
<div>load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"</div>
<div>a=addfile("wrfout","r")<br>
</div>
<div>ta_mean_BEM=a->TA_MEAN<br>
</div>
<div>ta=ta_mean_BEM(24:719,0,:,:)</div>
<div>ta=ta-273.16</div>
<div>nlat1=ta(0,:,0)</div>
<div>mlon1=ta(0,0,:)</div>
<div><br>
</div>
<div><br>
</div>
<div> nlStrt=0</div>
<div> nlLast=129</div>
<div> mlStrt=0</div>
<div> mlLast=210</div>
<div> nlat=dimsizes(nlat1)</div>
<div> mlon=dimsizes(mlon1)</div>
<div> </div>
<div> grid_stats = new ((/nlat,mlon,30/), typeof(ta), getFillValue(ta))</div>
<div>    do nl=nlStrt,nlStrt-1</div>
<div>      do ml=mlStrt,mlStrt-1</div>
<div><br>
</div>
<div>         grid_stats(nl-nlStrt,ml-mlStrt,:) = stat_dispersion( ta(:,nl,ml), opt)</div>
<div><br>
</div>
<div>      end do</div>
<div>   end do</div>
<div><br>
</div>
<div>tenthP=grid_stats(:,:,3)</div>
<div><br>
</div>
<div>nintythP=grid_stats(:,:,13)</div>
<div><br>
</div>
<div><br>
</div>
<div>type = "png"</div>
<div>wks = gsn_open_wks(type,"abc")</div>
<div>res =True</div>
<div>opts = res</div>
<div>opts@cnFillOn = True</div>
<div>opts@cnConstFEnableFill           = True</div>
<div>opts@cnConstFLabelBackgroundColor = "transparent"</div>
<div><br>
</div>
<div><br>
</div>
<div>pltres = True</div>
<div>pltres@NoTitles = True</div>
<div>pltres@gsnMaximize = True</div>
<div>pltres@FramePlot = False</div>
<div>pltres@PanelPlot = True</div>
<div>mpres = True</div>
<div>mpres@mpOutlineBoundarySets    ="NoBoundaries"</div>
<div>contour_lh = wrf_contour(a,wks,tenthP,opts)</div>
<div>delete(opts)</div>
<div><br>
</div>
<div>plot = wrf_map_overlays(a,wks,(/contour_lh/),pltres,mpres)</div>
<div>draw(plot)</div>
<div>frame(wks)</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
</div>
</div>
<br>
<div>
<div dir="ltr">On Wed, Jun 30, 2021 at 10:24 PM Dave Allured - NOAA Affiliate <<a href="mailto:dave.allured@noaa.gov" target="_blank">dave.allured@noaa.gov</a>> wrote:<br>
</div>
<blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div dir="ltr">
<div>Also, stat_dispersion returns an array of 30 values each time, not a single value.  See function documentation.  So you need to add an extra dimension in the loop calculation, like this:</div>
<div><br>
</div>
<div>    grid_stats = new ((/ nlat, mlon, 30 /), typeof(rf), getFillValue(rf))</div>
<div><br>
</div>
<div>    do ...</div>
<div>       do ...</div>
<div>         grid_stats(nl-nlStrt,ml-mlStrt,:) = stat_dispersion( rf(:,nl,ml), opt)</div>
<div>      end do</div>
<div>    end do</div>
<div><br>
</div>
<div>When the loop is complete, the 10th percentile values will be in grid_stats(:,:,3), which is a 2-D grid that you can plot.  The 90th percentile values will be in grid_stats(:,:,13).  Again, refer to the function documentation for the correct index
 values to access the desired statistics.</div>
<div><br>
</div>
<br>
<div>
<div dir="ltr">On Wed, Jun 30, 2021 at 5:13 AM Buzan, Jonathan <<a href="mailto:jbuzan@purdue.edu" target="_blank">jbuzan@purdue.edu</a>> wrote:<br>
</div>
<blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div>NCL counts from 0 to n-1, not from 1 to n. So your loop vars need to account for that.
<div><br>
</div>
<div>Cheers,</div>
<div>-Jonathan</div>
<div>
<div><br>
<blockquote type="cite">
<div>On Jun 30, 2021, at 1:10 PM, ali mughal via ncl-talk <<a href="mailto:ncl-talk@mailman.ucar.edu" target="_blank">ncl-talk@mailman.ucar.edu</a>> wrote:</div>
<br>
<div>
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">Dear community 
<div>Thank you very much for your helpful comments. </div>
<div>As an initial test, I was trying to obtain statistics at all grid points before plotting them. I used the following code </div>
<div>
<div>load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"</div>
<div>a=addfile("wrfout","r")<br>
</div>
<div>ta_mean_BEM=a->TA_MEAN<br>
</div>
<div>ta=ta_mean_BEM(24:719,0,:,:)</div>
<div>rf=ta-273.16</div>
<div>nlat1=rf(0,:,0)</div>
<div>printVarSummary(nlat)</div>
<div>mlon1=rf(0,0,:)</div>
<div>printVarSummary(mlon)</div>
<div>printVarSummary(rf)</div>
<div>opt=False</div>
<div><br>
</div>
<div>     nlStrt=0</div>
<div>     nlLast=129</div>
<div>     mlStrt=0</div>
<div>     mlLast=210</div>
<div>     nlat=dimsizes(nlat1)</div>
<div>     mlon=dimsizes(mlon1)</div>
<div>     </div>
<div>    grid_stats = new ((/nlat(0),mlon(0)/), typeof(rf), getFillValue(rf))</div>
<div>    printVarSummary(grid_stats)</div>
<div>    do nl=0,nlLast</div>
<div>      do ml=0,mlLast</div>
<div><br>
</div>
<div>         grid_stats(nl-nlStrt,ml-mlStrt) = stat_dispersion( rf(:,nl,ml), opt)</div>
<div><br>
</div>
<div>      end do</div>
<div>   end do</div>
<div><br>
</div>
<div>   copy_VarCoords(rf(:,nlStrt:nlLast,mlStrt:mlLast), grid_stats)</div>
<div>   grid_stats@long_name = "stat_dispersion at individual grid points"</div>
<div>   printVarSummary(grid_stats)</div>
</div>
<div><br>
</div>
<div>But I obtain the following output from my print statements and the errors</div>
<div><br>
</div>
<div>
<div><font size="1">Variable: rf</font></div>
<div><font size="1">Type: float</font></div>
<div><font size="1">Total Size: 75418560 bytes</font></div>
<div><font size="1">            18854640 values</font></div>
<div><font size="1">Number of Dimensions: 3</font></div>
<div><font size="1">Dimensions and sizes:   [696] x [129] x [210]</font></div>
<div><font size="1">Coordinates:</font></div>
<div><font size="1"><br>
</font></div>
<div><font size="1">Variable: grid_stats</font></div>
<div><font size="1">Type: float</font></div>
<div><font size="1">Total Size: 108360 bytes</font></div>
<div><font size="1">            27090 values</font></div>
<div><font size="1">Number of Dimensions: 2</font></div>
<div><font size="1">Dimensions and sizes:   [129] x [210]</font></div>
<div><font size="1">Coordinates:</font></div>
<div><font size="1">fatal:VarVarWrite: Number of dimensions on left hand side does not match right hand side</font></div>
<div><font size="1">fatal:["Execute.c":8578]:Execute: Error occurred at or near line 46 in file var_Test.ncl</font></div>
<div><font size="1"><br>
</font></div>
<div><font size="1">fatal:Subscript out of range, error in subscript #1</font></div>
<div><font size="1">fatal:An error occurred reading rf</font></div>
<div><font size="1">fatal:["Execute.c":8578]:Execute: Error occurred at or near line 51 in file var_Test.ncl</font></div>
<div><font size="1"><br>
</font></div>
<div><font size="1">Variable: grid_stats</font></div>
<div><font size="1">Type: float</font></div>
<div><font size="1">Total Size: 108360 bytes</font></div>
<div><font size="1">            27090 values</font></div>
<div><font size="1">Number of Dimensions: 2</font></div>
<div><font size="1">Dimensions and sizes:   [129] x [210]</font></div>
<div><font size="1">Coordinates:</font></div>
<div><font size="1">Number Of Attributes: 1</font></div>
<div><font size="1">  long_name :   stat_dispersion at individual grid points</font></div>
</div>
<div><br>
</div>
</div>
</div>
</div>
<br>
<div>
<div dir="ltr">On Wed, Jun 30, 2021 at 12:01 AM Dave Allured - NOAA Affiliate <<a href="mailto:dave.allured@noaa.gov" target="_blank">dave.allured@noaa.gov</a>> wrote:<br>
</div>
<blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div>Ali, you do not need to make new code to find the 10th and 90th percentile values.  Just use stat_dispersion directly, and take only the output values that you need.  The function is designed to be used in this way.  There is no significant performance
 impact from ignoring all the other result values.<br>
</div>
<div><br>
</div>
<div>You can easily make a spatial map of 10th or 90th percentile values.  Just call stat_dispersion inside a double loop over X and Y dimensions.</div>
<div><br>
</div>
<br>
<div>
<div dir="ltr">On Tue, Jun 29, 2021 at 9:23 AM Buzan, Jonathan via ncl-talk <<a href="mailto:ncl-talk@mailman.ucar.edu" target="_blank">ncl-talk@mailman.ucar.edu</a>> wrote:<br>
</div>
<blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div>Hello,
<div><br>
</div>
<div>I’ve used that function a bunch. If you only want 10th and 90th percentile, you’ll want to use: </div>
<div><br>
</div>
<div>qsort</div>
<div>Which will sort your data within a single grid cell from lowest to highest.</div>
<div><br>
</div>
<div>And then grab the specific lines of code for 10th and 90th percentiles from the stat_dispersion function in:</div>
<div>$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl</div>
<div><br>
</div>
<div>If you look at the function, you’ll see that it uses qsort, then goes step by step through calculating all the different applications.</div>
<div><br>
</div>
<div>Cheers,</div>
<div>-Jonathan</div>
<div>
<div><br>
<blockquote type="cite">
<div>On Jun 29, 2021, at 5:14 PM, ali mughal via ncl-talk <<a href="mailto:ncl-talk@mailman.ucar.edu" target="_blank">ncl-talk@mailman.ucar.edu</a>> wrote:</div>
<br>
<div>
<div dir="ltr">
<div dir="ltr">Dear NCL community 
<div><br>
</div>
<div>In the following ncl function </div>
<div><br>
</div>
<div><a href="http://www.ncl.ucar.edu/Document/Functions/Contributed/stat_dispersion.shtml" target="_blank">http://www.ncl.ucar.edu/Document/Functions/Contributed/stat_dispersion.shtml</a><br>
</div>
<div><br>
</div>
<div>Is it possible to use 10th and 90th percentile values only ? </div>
<div><br>
</div>
<div>Also can these values be used to develop a spatial map? </div>
<div><br>
</div>
<div>For example if I want to find the 10th and  90th percentile of air temperature within the urban grid cells only.</div>
<div><br>
</div>
<div>Can anyone share an example script or point me to any web resource will be appreciated. </div>
<div><br>
</div>
<div>Thanks in advance</div>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</blockquote>
</div>
</blockquote>
</div>
_______________________________________________<br>
ncl-talk mailing list<br>
<a href="mailto:ncl-talk@mailman.ucar.edu" target="_blank">ncl-talk@mailman.ucar.edu</a><br>
List instructions, subscriber options, unsubscribe:<br>
<a href="https://mailman.ucar.edu/mailman/listinfo/ncl-talk" target="_blank">https://mailman.ucar.edu/mailman/listinfo/ncl-talk</a></div>
</blockquote>
</div>
<br>
</div>
</div>
</div>
</div>

</blockquote></div></div></div>