<div dir="ltr"><div dir="ltr"><div dir="ltr"><div>Hello,</div><div><br></div><div>I am uncertain if this is proper mail thread to submit contributions. If not, please direct me to where I could send the following contribution.</div><div><br></div><div>There is no proper computation of percentiles in NCL presently. Some users have created functions that loosly estimate percentiles based on index, however these are not accurate for smaller data arrays. Additionally, there is no support for missing values when computing percentiles in NCL.</div><div><br></div><div>Included below is a function that accurately determines percentiles for small and large data arrays, and also supports missing values. This function has been tested against other percentile computing software, and shows identical results between them. I would like to recommend the inclusion of this function in future releases of NCL.</div><div><br></div><div>; Percentile function<br>; For 1D X variables and -9999. missing values only<br>undef("Percentile")<br>function Percentile(x:numeric,P:float)<br>begin<br>; Convert incoming percentile value to percent<br>if(P.gt.0) then<br> P = P/100.<br>end if<br>; Set and count the missing values, if any<br>x@_FillValue = -9999.<br>nm = num(ismissing(x))<br>; Sort values<br>ib = dim_pqsort(x,2)<br>; Remove missing value indices from sorted array<br>y = x(nm:dimsizes(x)-1)<br>; For determining percentiles, we need to know if the resultant<br>; index will be an integer or float. With the multiplication of P,<br>; the array index is automatically set to be float, and we lose all<br>; information for what the "true" index would be. So, we introduce<br>; two index values and a difference to determine whether the "true"<br>; index would be a float or integer value. A conditional check,<br>; determines if the difference is zero, i.e., an integer, or if the<br>; difference is not zero, i.e., a float. Float index values are the<br>; percentile value, however integer index values must be averaged<br>; over the n and n+1 indexes to determine the percentile.<br>; *Note: index arrays are subtracted by 1, as the index begins at<br>;        0, and not at 1.<br>; Index integer for value<br>index = toint(ceil(P*dimsizes(y)))-1<br>; Second index float for value<br>index2 = P*dimsizes(y)-1<br>; Index difference<br>i_diff = index-index2<br>if (i_diff.ne.0) then<br>  return(y(index))<br>else<br>  y_a = (y(index)+y(index+1))/2<br>  return(y_a)<br>end if<br>end<br><br></div><div>Cheers,</div><div><div class="gmail_signature" dir="ltr"><div dir="ltr"><div>-------------------------------------------------------------<br><div style="text-align:left;color:rgb(34,34,34);text-transform:none;text-indent:0px;letter-spacing:normal;font-family:Arial,Helvetica,sans-serif;font-size:13.33px;font-style:normal;font-variant:normal;font-weight:400;text-decoration:none;word-spacing:0px;white-space:normal" dir="ltr">Brandon J Fisel<br></div></div></div></div></div></div></div></div>