[ncl-talk] Function for frequency distribution
Dennis Shea
shea at ucar.edu
Thu Sep 3 17:08:49 MDT 2015
Hi Gabriel,
Thank you very much.
---
I have opened a 'ticket' on this.
Issue NCL-2274 -
User donated function: Function for frequency distribution has been
successfully created.
--
As you know, NCL functions are documented and well supported.
The NCL-team can not support everything.
We are trying to decide how we can make user contribute functions best
available to all.
Certainly, we can distribute in a file BUT
(1) How do make all NCL users aware of user contributed functions
(2) Do we require some level of documentation and testing?
(3) Who supports the function? Internally, we have the rule 'you put
it in ... you support i!'
THX for the contribution.
Regards
Dennis
On Wed, Sep 2, 2015 at 6:23 PM, Gabriel Medeiros <gabriel.abrahao at ufv.br> wrote:
> Hi,
>
> I've stumbled upon the problem of getting the frequency distribution
> of data and separating quantiles quite a few times. As i didn't see
> any function doing this specifically, i'd like to share mine with you.
>
> It's very simple and not as elaborated as the ones used in the
> histogram plotting procedures, but work fine for generating CDF's and
> getting quantiles. If there's a built in one for this that i couldn't
> find, i apologize and please let me know.
>
> Gabriel Abrahao
> Grupo de Pesquisa em Interação Atmosfera-Biosfera
> Universidade Federal de Viçosa
>
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> ;
> ; Function: freq_wgt
> ;
> ; Gabriel Abrahao: gabriel.abrahao at ufv.br
> ;
> ; Get the weighted frequency distribution of the n-length data
> vector, returning a 2 by n matrix containing both
> ; the sorted data and the fraction of the total weight below each value
> ;
> ; Removes missing values for the output, and relies on the fact
> that default missing values are very large
> ; (positive or negative) for handling them
> ;
> ; function freq_wgt(
> ; indata [*]
> ; inwegt [*] )
> ;
> ; Return value: A matrix of two rows, the first with the sorted
> values and the second with the fraction
> ; of total nonmissing weights corresponding to them.
> ;
>
> undef("freq_wgt")
> function freq_wgt(indata[*],inwegt[*])
> local indata,inwegt,nmiss,permv,tdata,twegt,cumwegt,out
> begin
>
> ;Make copies of the input variables in order no to mess with them
> data = indata
> wegt = inwegt
>
> ;Makes sure that missing values are large negative numbers
> data at _FillValue = -1*abs(default_fillvalue(typeof(data)))
> wegt at _FillValue = -1*abs(default_fillvalue(typeof(wegt)))
>
> ;Synchronize missing values between data and weights
> data = where(ismissing(wegt),data at _FillValue,data)
> wegt = where(ismissing(data),wegt at _FillValue,wegt)
>
> ;Get number of missing values
> nmiss = num(ismissing(data))
>
> ;Sort in respect to data
> permv = dim_pqsort(data,2)
> wegt = wegt(permv)
>
> ;Trim to non-missing values only
> tdata = data(nmiss:dimsizes(data)-1)
> twegt = wegt(nmiss:dimsizes(wegt)-1)
>
> ;Delete the original copied data to save memory
> delete(data)
> delete(wegt)
>
> ;Calculate cumulative weights and generate fraction vector
> cumwegt = cumsum(twegt,2)
> cumwegt = cumwegt/cumwegt(dimsizes(cumwegt)-1)
>
> out = (/tdata,cumwegt/)
> out at column0 = "Values"
> out at column1 = "Fraction below value"
>
> return(out)
> end
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
More information about the ncl-talk
mailing list