[ncl-talk] Calculate percentile

Buzan, Jonathan jbuzan at purdue.edu
Tue Mar 15 06:55:18 MDT 2022


Hi Giorgio,

The code for the stat_dispersion is in $NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl
(Search for stat_dispersion for the explicit function)

Here are some snippets to help. Ultimately, the stat_dispersion operates on 1d fields, and you have to put your data into that format. Highly recommend that you have more than 100 data points in your time dimension or the function will not work.

mastervar = ; new array that is the stat dispersion by lat by lon
do k = 0, dimsizes(lat)-1
do j = 0, dimsizes(lon)-1
z = data(:,k,j)
work = ndtooned(z)
nwork = dimsizes(work)
qsort(work) ; reordered from lowest to highest
mastervar(j,k) = work( min((/nwork-1, nwork*70/100-1 /)) ) ; 70%
delete(z)
delete(work)
delete(nwork)
end do
end do


Cheers,
-Jonathan





On Mar 15, 2022, at 13:25, Giorgio Graffino via ncl-talk <ncl-talk at mailman.ucar.edu<mailto:ncl-talk at mailman.ucar.edu>> wrote:


Dear NCLers,


I have a time,lat,lon monthly-mean SST field and I want to compute the 70th percentile month by month. I'm trying to adapt Dennis's suggestion given here (https://www.ncl.ucar.edu/Support/talk_archives/2013/0954.html), but I'm ending up with a single 2-D percentile field, calculated across the entire time period. The problem is that, since it's historical SST, most of the spatial domain is above the threshold at the end of the time period, because of global warming.

I'd like to have something similar to stat_dispersion (https://www.ncl.ucar.edu/Document/Functions/Contributed/stat_dispersion.shtml), but for a custom percentile and without detrending the data. Is there a way to do that? Here is a snippet of my code:


temp_sort = dim_pqsort_n(temp,2,0) ; (time, lat, lon) -> (time, lat, lon)

temp_num = dim_num_n(.not.ismissing(temp_sort),0) ; (time, lat, lon) -> (lat, lon)

do n = 0, ntim-1

temp_warmest30(n,:,:) = where(temp_sort(n,:,:).gt.floor(0.7*temp_num),temp(n,:,:),temp at _FillValue) ; (time, lat, lon) -> (time, lat, lon)

end do


Thanks,

Giorgio

_______________________________________________
ncl-talk mailing list
ncl-talk at mailman.ucar.edu<mailto:ncl-talk at mailman.ucar.edu>
List instructions, subscriber options, unsubscribe:
https://mailman.ucar.edu/mailman/listinfo/ncl-talk

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20220315/92e6daea/attachment.html>


More information about the ncl-talk mailing list