[Thread Prev][Thread Next][Index]

Re: [ferret_users] percentile for gridded data



Hi Nadia,
Here is an example which does what I think you are talking about. It starts with the quantile script from the previous message from Andrew, and then uses the variable a_q, the "quantile" function to define a new variable which is 5 for function values between 0 and 10% quantile, 15 for values between 10 and 20%, 25 for values between 20 and 30% and so on.

! quantiles.jnl
! Example script.
!
! To form quartiles, or percentiles, use the ZSEQUENCE function.
! Based on a contribution from Andrew Wittenberg Fri, 17 Sep 2004

! Here's an example showing how to compute quartiles (and more generally,
! quantiles/percentiles) from some 2-dimensional data:

use coads_climatology
let svar = sst[l=1]

set mode interp

! unwrap January SSTs into a 1-dimensional array
let a = zsequence(svar)

! define a quantile axis
let ngood = `a[k=@ngd]`
def ax/z=0:1/np=`ngood` z_q

! sort the data (missing values will be last)
let a_z = samplek(a,sortk(a))

! place the sorted valid data onto the quantile axis
let/title="quantiles of `sst,r=title`"/unit="`sst,r=unit`" a_q = a_z[gz=z_q@asn]

! plot the quantile function (inverse cumulative distribution function)
plot/trans a_q

! list the min, 1st quartile, median, 3rd quartile, and max
list a_q[z=0],a_q[z=.25],a_q[z=.5],a_q[z=.75],a_q[z=1]


! Plot shaded percentiles. pct_levs contains the variable values separating
! each range of 10 percentile points

let pct_levs = a_q[z=0:1:0.1]
list pct_levs

! We will define a set of variables each containing a range of 10 percentile
! points, e.g.
!
! let mask2 = if svar le hi then 1 else 0
! let v2 = if svar gt lo then 15* mask2 else 0 !
! mask2=1 where svar LE 30th percentile
! then v2 contains the value 15 where svar is between the tenth and 20th
! percentile, and v2 is 0 everwhere else.

! Inialize the first of a series of variables
let v1 = if svar le `pct_levs[k=1]` then 0 else 0

! Define variables each representing a 10 percent range

repeat/range=2:11:1/name=m (let vhi = pct_levs[k=`m`]; let vlo = pct_levs[k=`m-1`]; \
let mask`m` = if svar le `vhi` then 1 else 0; \
let v`m` = if svar GT `vlo` then `10*(m-1)-5` * mask`m` else 0)

! Add them to form a single varible which is 5 for 0-10%, 15 for 10-20% and so on.

let pct = v1 + v2 + v3 + v4 + v5 + v6 + v7 + v8 + v9 + v10 + v11

! Finally, define a mask to restore the missing data from the original variable,
! missing_mask=1 where the variable has valid data

let missing_mask = if svar then 1

shade/lev=(0,100,10)/palette=blue_orange/title="percentiles" pct * missing_mask
go fland



nadia.rehman wrote:
Hi Ansely,

Thanks for the help and I have used the way which was mentioned in that e-mail but it generate the inverse cumulative distribution for any quantile. Me actually want the picture which is attached with this mail. It is the spatial picture of the difference of future and present 10th percentile calculated for gridded data.


Thanks




--
Nadia Rehman Yousafzai
Research Fellow (Climate Section)
Global Change Impact Studies Centre
First Floor Saudi Pak tower Blue Area Islamabad Pakistan
Ph : 92-51-9219785
Fax : 92-51-9219787 --

GIF image


[Thread Prev][Thread Next][Index]

Dept of Commerce / NOAA / OAR / PMEL / TMAP

Contact Us | Privacy Policy | Disclaimer | Accessibility Statement