The AbstractDetector class#

class pylife.stress.rainflow.AbstractDetector(recorder=None)[source]#

Define the common base class for streaming rainflow detectors.

Subclasses implement a concrete rainflow counting rule, such as three-point or four-point counting. A detector receives load samples and reports closed hysteresis loops to its recorder through record_values(). Detectors that know the source sample indices also call record_index() and report_chunk().

Parameters:

recorder (AbstractRecorder, optional) – Recorder that receives the detected rainflow loops. If None (the default), a new pylife.stress.rainflow.LoopValueRecorder is created for this detector.

Notes

Implement process() so processing is independent of chunk size: detector.process(signal) should be equivalent to detector.process(signal[:n]).process(signal[n:]) for any split point 0 < n < len(signal). This enables streamed rainflow counting for large signals.

Rainflow counting in pyLife is based on common three-point and four-point algorithms, including the DIN 45667 / ASTM E1049 family of rainflow counting methods.

__init__(recorder=None)[source]#

Instantiate a detector base.

Parameters:

recorder (AbstractRecorder, optional) – Recorder that receives detected rainflow loops. If None (the default), a new pylife.stress.rainflow.LoopValueRecorder is created for this detector.

flush(samples=[])[source]#

Flush cached values after processing an optional final sample chunk.

If process is called instead of flush, the last value of a load sequence is cached for a subsequent call to process, because it may or may not be a turning point of the sequence.

Using flush forces processing of the last value. This may not be the desired effect as multiple increasing or decreasing values in a row could occur, instead of processing only turning points.

Parameters:

samples (array_like, optional) – Final load samples to process, typically in MPa. Default is [].

Returns:

The detector itself so processing can be chained.

Return type:

AbstractDetector

See also

process

Process samples without forcing cached values to be emitted.

Notes

This method is equivalent to process(samples, flush=True).

abstractmethod process(samples, flush=False)[source]#

Process a sample chunk.

Parameters:
Returns:

The detector itself so processing can be chained.

Return type:

AbstractDetector

See also

flush

Process samples and force cached values to be emitted.

Notes

Must be implemented by subclasses.

property recorder#

Return the recorder that receives detected loops.

Returns:

Recorder instance passed at construction time.

Return type:

AbstractRecorder

property residual_index#

Return the sample indices of residual turning points.

Returns:

Global sample indices of residual turning points.

Return type:

numpy.ndarray

property residuals#

Return the residual turning points of the signal processed so far.

Returns:

Load values of turning points that have not yet formed closed hysteresis loops.

Return type:

numpy.ndarray