pyyeti.cyclecount.getbins

pyyeti.cyclecount.getbins(bins, mx, mn, right=True, check_bounds=False)[source]

Utility routine used by sigcount() to get bin boundaries.

Parameters:
  • bins (scalar integer or 1d array_like) – Used to define bin boundaries. If array_like, must be monotonically increasing. See description below.

  • mx, mn (scalar) – Maximum and minimum values of data to be put in bins. mx and mn may be input in either order. If bins is a 1d array_like, mx and mn are ignored unless check_bounds is True; see below.

  • right (bool; optional) – Indicates whether the bins include the rightmost edge or the leftmost edge. If right == True (the default), then the bins [1,2,3,4] indicate (1,2], (2,3], (3,4].

  • check_bounds (bool; optional) – If True, routine will check to see if the final bin boundaries cover the mn to mx range. Note that the range is guaranteed to be covered if bins is a scalar.

Returns:

  • bb (1d ndarray) – The bin boundaries; length = bins + 1

  • out_of_bounds (bool; optional) – True if either mx or mn will fall out of range of the bins (according to right). Only returned if check_bounds is True.

Notes

If mx and mn are equal, they are reset:

mx = mx + 0.5
mn = mn - 0.5

If bins is a scalar, this routine tries to mimic the behavior of the pandas.cut() routine:

bb = np.linspace(mn, mx, bins+1)
p = 0.001 * (mx - mn)
if right:
    bb[0] -= p
else:
    bb[-1] += p

If bins is a vector, it defines the boundaries directly and is returned as is:

bb = np.array(bins)
Raises:

ValueError – If bins is a vector but is not monotonically increasing

Examples

>>> from pyyeti import cyclecount
>>> cyclecount.getbins(4, 12, 4)
array([  3.992,   6.   ,   8.   ,  10.   ,  12.   ])
>>> cyclecount.getbins(4, 12, 4, right=False)
array([  4.   ,   6.   ,   8.   ,  10.   ,  12.008])
>>> cyclecount.getbins([1, 2, 3, 4], 12, 4, check_bounds=True)
(array([1, 2, 3, 4]), True)