<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
NCL counts from 0 to n-1, not from 1 to n. So your loop vars need to account for that.
<div class=""><br class="">
</div>
<div class="">Cheers,</div>
<div class="">-Jonathan</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
<div><br class="">
<blockquote type="cite" class="">
<div class="">On Jun 30, 2021, at 1:10 PM, ali mughal via ncl-talk <<a href="mailto:ncl-talk@mailman.ucar.edu" class="">ncl-talk@mailman.ucar.edu</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div dir="ltr" class="">
<div dir="ltr" class="">
<div dir="ltr" class="">Dear community 
<div class="">Thank you very much for your helpful comments. </div>
<div class="">As an initial test, I was trying to obtain statistics at all grid points before plotting them. I used the following code </div>
<div class="">
<div class="">load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"</div>
<div class="">a=addfile("wrfout","r")<br class="">
</div>
<div class="">ta_mean_BEM=a->TA_MEAN<br class="">
</div>
<div class="">ta=ta_mean_BEM(24:719,0,:,:)</div>
<div class="">rf=ta-273.16</div>
<div class="">nlat1=rf(0,:,0)</div>
<div class="">printVarSummary(nlat)</div>
<div class="">mlon1=rf(0,0,:)</div>
<div class="">printVarSummary(mlon)</div>
<div class="">printVarSummary(rf)</div>
<div class="">opt=False<br class="">
</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class="">     nlStrt=0</div>
<div class="">     nlLast=129</div>
<div class="">     mlStrt=0</div>
<div class="">     mlLast=210</div>
<div class="">     nlat=dimsizes(nlat1)</div>
<div class="">     mlon=dimsizes(mlon1)</div>
<div class="">     </div>
<div class="">    grid_stats = new ((/nlat(0),mlon(0)/), typeof(rf), getFillValue(rf))</div>
<div class="">    printVarSummary(grid_stats)</div>
<div class="">    do nl=0,nlLast</div>
<div class="">      do ml=0,mlLast</div>
<div class=""><br class="">
</div>
<div class="">         grid_stats(nl-nlStrt,ml-mlStrt) = stat_dispersion( rf(:,nl,ml), opt)</div>
<div class=""><br class="">
</div>
<div class="">      end do</div>
<div class="">   end do</div>
<div class=""><br class="">
</div>
<div class="">   copy_VarCoords(rf(:,nlStrt:nlLast,mlStrt:mlLast), grid_stats)</div>
<div class="">   grid_stats@long_name = "stat_dispersion at individual grid points"</div>
<div class="">   printVarSummary(grid_stats)</div>
</div>
<div class=""><br class="">
</div>
<div class="">But I obtain the following output from my print statements and the errors</div>
<div class=""><br class="">
</div>
<div class="">
<div class=""><font size="1" class="">Variable: rf</font></div>
<div class=""><font size="1" class="">Type: float</font></div>
<div class=""><font size="1" class="">Total Size: 75418560 bytes</font></div>
<div class=""><font size="1" class="">            18854640 values</font></div>
<div class=""><font size="1" class="">Number of Dimensions: 3</font></div>
<div class=""><font size="1" class="">Dimensions and sizes:   [696] x [129] x [210]</font></div>
<div class=""><font size="1" class="">Coordinates:</font></div>
<div class=""><font size="1" class=""><br class="">
</font></div>
<div class=""><font size="1" class="">Variable: grid_stats</font></div>
<div class=""><font size="1" class="">Type: float</font></div>
<div class=""><font size="1" class="">Total Size: 108360 bytes</font></div>
<div class=""><font size="1" class="">            27090 values</font></div>
<div class=""><font size="1" class="">Number of Dimensions: 2</font></div>
<div class=""><font size="1" class="">Dimensions and sizes:   [129] x [210]</font></div>
<div class=""><font size="1" class="">Coordinates:</font></div>
<div class=""><font size="1" class="">fatal:VarVarWrite: Number of dimensions on left hand side does not match right hand side</font></div>
<div class=""><font size="1" class="">fatal:["Execute.c":8578]:Execute: Error occurred at or near line 46 in file var_Test.ncl</font></div>
<div class=""><font size="1" class=""><br class="">
</font></div>
<div class=""><font size="1" class="">fatal:Subscript out of range, error in subscript #1</font></div>
<div class=""><font size="1" class="">fatal:An error occurred reading rf</font></div>
<div class=""><font size="1" class="">fatal:["Execute.c":8578]:Execute: Error occurred at or near line 51 in file var_Test.ncl</font></div>
<div class=""><font size="1" class=""><br class="">
</font></div>
<div class=""><font size="1" class=""><br class="">
</font></div>
<div class=""><font size="1" class="">Variable: grid_stats</font></div>
<div class=""><font size="1" class="">Type: float</font></div>
<div class=""><font size="1" class="">Total Size: 108360 bytes</font></div>
<div class=""><font size="1" class="">            27090 values</font></div>
<div class=""><font size="1" class="">Number of Dimensions: 2</font></div>
<div class=""><font size="1" class="">Dimensions and sizes:   [129] x [210]</font></div>
<div class=""><font size="1" class="">Coordinates:</font></div>
<div class=""><font size="1" class="">Number Of Attributes: 1</font></div>
<div class=""><font size="1" class="">  long_name :   stat_dispersion at individual grid points</font></div>
</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
</div>
</div>
</div>
<br class="">
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Wed, Jun 30, 2021 at 12:01 AM Dave Allured - NOAA Affiliate <<a href="mailto:dave.allured@noaa.gov" class="">dave.allured@noaa.gov</a>> wrote:<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 dir="ltr" class="">
<div dir="ltr" class="">
<div dir="ltr" class="">
<div class="">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 class="">
</div>
<div class=""><br class="">
</div>
<div class="">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 class=""><br class="">
</div>
<br class="">
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Tue, Jun 29, 2021 at 9:23 AM Buzan, Jonathan via ncl-talk <<a href="mailto:ncl-talk@mailman.ucar.edu" target="_blank" class="">ncl-talk@mailman.ucar.edu</a>> wrote:<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="overflow-wrap: break-word;" class="">Hello,
<div class=""><br class="">
</div>
<div class="">I’ve used that function a bunch. If you only want 10th and 90th percentile, you’ll want to use: </div>
<div class=""><br class="">
</div>
<div class="">qsort</div>
<div class="">Which will sort your data within a single grid cell from lowest to highest.</div>
<div class=""><br class="">
</div>
<div class="">And then grab the specific lines of code for 10th and 90th percentiles from the stat_dispersion function in:</div>
<div class="">$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl</div>
<div class=""><br class="">
</div>
<div class="">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 class=""><br class="">
</div>
<div class="">Cheers,</div>
<div class="">-Jonathan</div>
<div class="">
<div class=""><br class="">
<blockquote type="cite" class="">
<div class="">On Jun 29, 2021, at 5:14 PM, ali mughal via ncl-talk <<a href="mailto:ncl-talk@mailman.ucar.edu" target="_blank" class="">ncl-talk@mailman.ucar.edu</a>> wrote:</div>
<br class="">
<div class="">
<div dir="ltr" class="">
<div dir="ltr" class="">Dear NCL community 
<div class=""><br class="">
</div>
<div class="">In the following ncl function </div>
<div class=""><br class="">
</div>
<div class=""><a href="http://www.ncl.ucar.edu/Document/Functions/Contributed/stat_dispersion.shtml" target="_blank" class="">http://www.ncl.ucar.edu/Document/Functions/Contributed/stat_dispersion.shtml</a><br class="">
</div>
<div class=""><br class="">
</div>
<div class="">Is it possible to use 10th and 90th percentile values only ? </div>
<div class=""><br class="">
</div>
<div class="">Also can these values be used to develop a spatial map? </div>
<div class=""><br class="">
</div>
<div class="">For example if I want to find the 10th and  90th percentile of air temperature within the urban grid cells only.</div>
<div class=""><br class="">
</div>
<div class="">Can anyone share an example script or point me to any web resource will be appreciated. </div>
<div class=""><br class="">
</div>
<div class="">Thanks in advance</div>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</div>
</blockquote>
</div>
_______________________________________________<br class="">
ncl-talk mailing list<br class="">
<a href="mailto:ncl-talk@mailman.ucar.edu" class="">ncl-talk@mailman.ucar.edu</a><br class="">
List instructions, subscriber options, unsubscribe:<br class="">
https://mailman.ucar.edu/mailman/listinfo/ncl-talk</div>
</blockquote>
</div>
<br class="">
</div>
</body>
</html>