<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 class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Jun 30, 2021 at 10:24 PM Dave Allured - NOAA Affiliate <<a href="mailto:dave.allured@noaa.gov">dave.allured@noaa.gov</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>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 class="gmail_quote"><div dir="ltr" class="gmail_attr">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 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;">
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 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" target="_blank">dave.allured@noaa.gov</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 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 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">ncl-talk@mailman.ucar.edu</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>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>