The FourPointDetector class

class pylife.stress.rainflow.FourPointDetector(recorder)[source]

Implements four point rainflow counting algorithm.

from pylife.stress.timesignal import TimeSignalGenerator
import pylife.stress.rainflow as RF

ts = TimeSignalGenerator(10, {
    'number': 50,
    'amplitude_median': 1.0, 'amplitude_std_dev': 0.5,
    'frequency_median': 4, 'frequency_std_dev': 3,
    'offset_median': 0, 'offset_std_dev': 0.4}, None, None).query(10000)

rfc = RF.FourPointDetector(recorder=RF.LoopValueRecorder())
rfc.process(ts)

rfc.recorder.collective
from to
0 7.892309 2.130314
1 8.591024 -2.329407
2 9.136343 -3.298622
3 5.877199 4.764618
4 6.932680 0.908978
... ... ...
1048 -7.040707 11.344779
1049 -8.420708 13.834843
1050 4.104557 1.518426
1051 4.516507 1.166879
1052 7.178845 -1.093137

1053 rows × 2 columns

Alternatively you can ask the recorder for a histogram matrix:

rfc.recorder.histogram(bins=16)
from                                        to                                        
(-15.954577819514435, -13.731340813663124]  (-14.738071277378355, -12.508766836735951]    0.0
                                            (-12.508766836735951, -10.27946239609355]     0.0
                                            (-10.27946239609355, -8.050157955451146]      0.0
                                            (-8.050157955451146, -5.820853514808743]      0.0
                                            (-5.820853514808743, -3.5915490741663394]     0.0
                                                                                         ... 
(17.393977268255234, 19.61721427410654]     (9.784277569688077, 12.01358201033048]        0.0
                                            (12.01358201033048, 14.242886450972884]       0.0
                                            (14.242886450972884, 16.472190891615284]      0.0
                                            (16.472190891615284, 18.701495332257693]      0.0
                                            (18.701495332257693, 20.93079977290009]       0.0
Length: 256, dtype: float64

We take four turning points into account to detect closed hysteresis loops.

Consider four consecutive peak/valley points say, A, B, C, and D If B and C are contained within A and B, then a cycle is counted from B to C; otherwise no cycle is counted.

i.e, If X Y AND Z Y then a cycle exist FROM = B and TO = C where, ranges X = |D–C|, Y = |C–B|, and Z = |B–A|

Load -----------------------------
|        x B               F x
--------/-\-----------------/-----
|      /   \   x D         /
------/-----\-/-\---------/-------
|    /     C x   \       /
--\-/-------------\-----/---------
|  x A             \   /
--------------------\-/-----------
|                    x E
----------------------------------
|              Time

So, if a cycle exsist from B to C then delete these peaks from the turns array and perform next iteration by joining A&D else if no cylce exsists, then B would be the next strarting point.

__init__(recorder)[source]

Instantiate a FourPointDetector.

Parameters:

recorder (subclass of AbstractRecorder) – The recorder that the detector will report to.

process(samples)[source]

Process a sample chunk.

Parameters:

samples (array_like, shape (N, )) – The samples to be processed

Returns:

self – The self object so that processing can be chained

Return type:

FourPointDetector