pyyeti.cyclecount.binify

pyyeti.cyclecount.binify(rf, ampbins=10, meanbins=1, right=True, precision=3, retbins=False, use_pandas=True, check_bounds=True)[source]

Summarize cycle count results (as from rainflow()) into bins.

Parameters:
  • rf (2d array_like) – 2d matrix with (at least) 3 columns: [amp, mean, count]. See rainflow().

  • ampbins (scalar or 1d array_like; optional) – Defines the cycle amplitude bins; see getbins() for more complete description on how bins are defined.

    ampbins type

    Brief description (see also getbins())

    scalar

    Defines number of bins to use

    vector

    Defines lower bin boundaries

  • meanbins (scalar or 1d array_like; optional) – Defines the cycle mean-value bins; see ampbins description and getbins() for more complete description on how bins are defined.

  • 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].

  • precision (integer; optional) – Precision to use for DataFrame labels; only used if use_pandas is True.

  • retbins (bool; optional) – If True, return the ampbins and meanbins vectors.

  • use_pandas (bool; optional) – If True, this routine will return table as a pandas DataFrame.

  • check_bounds (bool; optional) – If True, routine will check to see if the final bin boundaries for both the amplitude and mean cover the range of the data. Note that the range is guaranteed to be covered if the ampbins and meanbins inputs are scalars.

Returns:

  • table (pandas DataFrame or 2d ndarray) – A cycle count table (len(meanbins) x len(ampbins)). Each value in table entry is the number of cycles in the bin (see below).

  • ampbins (1d ndarray; optional) – Boundaries of amplitude bins used; length = # of bins + 1. Only returned if retbins is True.

  • meanbins (1d ndarray; optional) – Boundaries of mean-value bins used; length = # of bins + 1. Only returned if retbins is True.

Notes

Algorithm works as follows:

For each mean value bin (i’th):
  1. rf is filtered down to only those rows where the mean value falls in the mean-bin (call this subset of rf rffilt).

  2. For each amplitude bin (j’th): count number of cycles in rffilt with amplitude that falls in the amp-bin and store in table[i, j]

A value falls in bin i if:

bin[i] < value <= bin[i+1]        } if right is True
bin[i] <= value < bin[i+1]        } if right is not True

Examples

>>> from pyyeti import cyclecount
>>> rf = cyclecount.rainflow([-2, 1, -3, 5, -1, 3, -4, 4, -2])
>>> rf
   amp  mean  count
0  1.5  -0.5    0.5
1  2.0  -1.0    0.5
2  2.0   1.0    1.0
3  4.0   1.0    0.5
4  4.5   0.5    0.5
5  4.0   0.0    0.5
6  3.0   1.0    0.5
>>> format = lambda x: f"{x:.1f}"
>>> df = cyclecount.binify(rf, 3, 2)
>>> df.map(format)
Amp             (1.497, 2.500] (2.500, 3.500] (3.500, 4.500]
Mean...
(-1.002, 0.000]            1.0            0.0            0.5
(0.000, 1.000]             1.0            0.5            1.0
>>> df = cyclecount.binify(rf, 3, 2, right=0)
>>> df.map(format)
Amp             [1.500, 2.500) [2.500, 3.500) [3.500, 4.503)
Mean...
[-1.000, 0.000)            1.0            0.0            0.0
[0.000, 1.002)             1.0            0.5            1.5

If not using pandas:

>>> cyclecount.binify(rf, 3, 2, use_pandas=False)
array([[ 1. ,  0. ,  0.5],
       [ 1. ,  0.5,  1. ]])