clmm.utils.statistic module

General utility functions that are used in multiple modules

clmm.utils.statistic.compute_radial_averages(xvals, yvals, xbins, yerr=None, error_model='ste', weights=None)[source]

Given a list of xvals, yvals and xbins, sort into bins. If xvals or yvals contain non-finite values, these are filtered.

Parameters:
  • xvals (array_like) -- Values to be binned

  • yvals (array_like) -- Values to compute statistics on

  • xbins (array_like) -- Bin edges to sort into

  • yerr (array_like, None, optional) -- Errors of yvals. Default: None

  • error_model (str, optional) --

    Statistical error model to use for y uncertainties. (letter case independent)

    • 'ste' - Standard error [=std/sqrt(n) in unweighted computation] (Default).

    • 'std' - Standard deviation.

  • weights (array_like, None, optional) -- Weights for averages. Default: None

Returns:

  • mean_x (numpy.ndarray) -- Mean x value in each bin

  • mean_y (numpy.ndarray) -- Mean y value in each bin

  • err_y (numpy.ndarray) -- Error on the mean y value in each bin. Specified by error_model

  • num_objects (numpy.ndarray) -- Number of objects in each bin

  • binnumber (1-D ndarray of ints) -- Indices of the bins (corresponding to xbins) in which each value of xvals belongs. Same length as yvals. A binnumber of i means the corresponding value is between (xbins[i-1], xbins[i]).

  • wts_sum (numpy.ndarray) -- Sum of individual weights in each bin.

clmm.utils.statistic.compute_weighted_bin_sum(xvals, yvals, xbins, weights)[source]

Add yvals * weights in xbins.

Parameters:
  • xvals (array_like) -- Values to be binned

  • yvals (array_like) -- Values to compute statistics on

  • xbins (array_like) -- Bin edges to sort into

  • weights (array_like, None, optional) -- Weights for sum.

Returns:

Sum of yvals * weights in xbins.

Return type:

numpy.ndarray

clmm.utils.statistic.gaussian(value, mean, scatter)[source]

Normal distribution.

Parameters:
  • value (array-like) -- Values for which to evaluate gaussian.

  • mean (float) -- Mean value of normal distribution

  • scatter (float) -- Scatter of normal distribution

Returns:

Gaussian values at value

Return type:

numpy.ndarray

clmm.utils.statistic.make_bins(rmin, rmax, nbins=10, method='evenwidth', source_seps=None)[source]

Define bin edges

Parameters:
  • rmin (float, None) -- Minimum bin edges wanted. If None, min(source_seps) is used.

  • rmax (float, None) -- Maximum bin edges wanted. If None, max(source_seps) is used.

  • nbins (float, optional) -- Number of bins you want to create, default to 10.

  • method (str, optional) --

    Binning method to use (letter case independent):

    • 'evenwidth' - Default, evenly spaced bins between rmin and rmax

    • 'evenlog10width' - Logspaced bins with even width in log10 between rmin and rmax

    • 'equaloccupation' - Bins with equal occupation numbers

  • source_seps (array_like, None, optional) -- Radial distance of source separations. Needed if method='equaloccupation'. Default: None

Returns:

binedges -- array with nbins +1 elements that defines bin edges

Return type:

numpy.ndarray