pyyeti.cyclecount.rainflow¶
- pyyeti.cyclecount.rainflow(peaks, getoffsets=False, use_pandas=True)[source]¶
Rainflow cycle counting.
- Parameters:
peaks (1d array_like) – Vector of alternating peaks (as returned by
findap(), for example)getoffsets (bool; optional) – If True, the tuple
(rf, os)is returned; otherwise, only rf is returned.use_pandas (bool; optional) – If True, this routine will return pandas DataFrames
- Returns:
rf (pandas DataFrame or 2d ndarray) – n x 3 matrix with the rainflow cycle count information with the index going from 0 to n-1 and the columns being [‘amp’, ‘mean’, ‘count’]:
amp is the cycle amplitude (half the peak-to-peak range)
mean is mean of the cycle
count is either 0.5 or 1.0 depending on whether it’s half or full cycle
os (pandas DataFrame or 2d ndarray) – Only returned if getoffsets is True. n x 2 matrix of cycle offsets with index going from 0 to n-1 and the columns being [‘start’, ‘stop’]:
start is the offset into peaks for start of cycle
stop is the offset into peaks for end of cycle
Notes
This algorithm is derived from reference [1]. This routine is a wrapper for either the C version (
pyyeti.rainflow.c_rain()) or the Python version (pyyeti.rainflow.py_rain()) of the algorithm. Both versions give identical results. They also run in comparable times ifnumba.jit()is available (ifimport numbaworks). Ifnumba.jit()is not available, the C version is much faster.References
Examples
Run the example from the ASTM paper:
>>> from pyyeti.cyclecount import rainflow >>> rainflow([-2, 1, -3, 5, -1, 3, -4, 4, -2]) 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
With offsets:
>>> rf, os = rainflow([-2, 1, -3, 5, -1, 3, -4, 4, -2], ... getoffsets=True) >>> 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 >>> os start stop 0 0 1 1 1 2 2 4 5 3 2 3 4 3 6 5 6 7 6 7 8
If not using pandas:
>>> rf, os = rainflow([-2, 1, -3, 5, -1, 3, -4, 4, -2], ... getoffsets=True, use_pandas=False) >>> rf array([[ 1.5, -0.5, 0.5], [ 2. , -1. , 0.5], [ 2. , 1. , 1. ], [ 4. , 1. , 0.5], [ 4.5, 0.5, 0.5], [ 4. , 0. , 0.5], [ 3. , 1. , 0.5]]) >>> os array([[0, 1], [1, 2], [4, 5], [2, 3], [3, 6], [6, 7], [7, 8]]...)