Commit d3cbbd8b authored by Clément Haëck's avatar Clément Haëck
Browse files

Add function to compute quantiles from pdf

parent f63d3ac6
......@@ -182,16 +182,16 @@ def get_pdf(hist):
def get_median(pdf):
"""Return median computed from pdf."""
def get_quantile(pdf, q=0.5):
"""Returns quantile computed from pdf."""
bins_name = var_name('bins', pdf.VAR)
bins = get_full_bins(pdf, bins_name)
def uf_med(arr):
return stats.rv_histogram((arr, bins)).median()
def uf_quant(arr):
return stats.rv_histogram((arr, bins)).ppf(q)
med = xr.apply_ufunc(
uf_med, pdf,
quant = xr.apply_ufunc(
uf_quant, pdf,
......@@ -199,7 +199,12 @@ def get_median(pdf):
return med.rename('med')
return quant.rename('q{:g}'.format(q))
def get_median(pdf):
"""Return median computed from pdf."""
return get_quantile(pdf, q=0.5)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment