[ncl-talk] Calculate percentile

Giorgio Graffino g.graffino at tim.it
Tue Mar 15 06:25:55 MDT 2022


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20220315/c2e5b752/attachment.html>


More information about the ncl-talk mailing list