[ncl-talk] Percentile

Thu Dec 6 10:13:32 MST 2018

```Hi Soma,
I missed that there is indeed a function that does the exact same thing as
qsort but works on multi-dimensional arrays. See the documentation here:
https://www.ncl.ucar.edu/Document/Functions/Built-in/dim_pqsort.shtml

Modifying the coding I sent yesterday:
arr95 = prc(0,:,:)
arr95 = arr95 at _FillValue
arr5 = arr95
ntime = dimsizes(prc&time)
i5 = toint(ntime*.05)-1    ; approximate 5% index
i95 = toint(ntime*.95)-1  ; approximate 95% index
ip    = dim_pqsort_n(prc, 2, 0)   ; ascending order, sort prc in ascending
order at the 0th dimension.
prc05 = prc(i05,:,:)
prc95 = prc(i95,:,:)

Either method will work.

On Wed, Dec 5, 2018 at 3:38 PM Adam Phillips <asphilli at ucar.edu> wrote:

> Hi Soma,
> You can use qsort:
> https://www.ncl.ucar.edu/Document/Functions/Built-in/qsort.shtml
> Note that qsort only accepts a single dimension, so you'll have to call
> qsort for each lat/lon point individually:
> ; untested
> arr95 = prc(0,:,:)
> arr95 = arr95 at _FillValue
> arr5 = arr95
> ntime = dimsizes(prc&time)
> i5 = toint(ntime*.05)-1    ; approximate 5% index
> i95 = toint(ntime*.95)-1  ; approximate 95% index
> do gg = 0,dimsizes(prc&lat)-1
>     do hh = 0,dimsizes(prc&lon)-1
>         temp = prc(:,gg,hh)
>         qsort(temp)
>         arr5(gg,hh) = temp(i5)
>         arr95(gg,hh) = temp(i95)
>         delete(temp)
>     end do
> end do
>
> As always with any donated script on ncl-talk, make sure you understand
> what is happening in the script by using print statements and
> printVarSummary, and verify that the script is doing what you think it
> should be doing.
> If you have any further questions about ncl please respond to ncl-talk.
>
>
> On Wed, Dec 5, 2018 at 12:49 PM Soma Roy <somaroy892 at gmail.com> wrote:
>
>> Hello,
>>
>> I want to compute rainfall (gridded) values greater than 95th percentile
>> and less than 10th percentile.
>>
>> printVarSummary of the input data is as follows;
>> Variable: prc
>> Type: double
>> ..[snip]
>> Dimensions and sizes:   [time 14965| ] x [lat | 129] x [lon | 135]
>> [snip]
>> ......
>>   _FillValue :  -999
>>   long_name :   GRIDDED RAINFALL
>>   missing_value :       -999
>>
>> Please kindly suggest me a suitable way to execute it.
>> I would like to get my output results over latitude-longitude.
>>
>> Thank you,
>> Soma
>> _______________________________________________
>> ncl-talk mailing list
>> ncl-talk at ucar.edu
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>
>
> --
> Associate Scientist,  Climate and Global Dynamics Laboratory, NCAR
> www.cgd.ucar.edu/staff/asphilli/   303-497-1726
>
> <http://www.cgd.ucar.edu/staff/asphilli>
>

--