rainflow#

Rainflow cycle counting algorithms for fatigue analysis.

Implements: - ASTM rainflow (Nieslony’s algorithm, standard practice). - Four-point rainflow (Amzallag et al. 1994).

Also includes utilities to find turning points and extrema.

References

[1] WAFO Toolbox https://www.maths.lth.se/matstat/wafo/ [2] PyWAFO wafo-project/pywafo [3] Rychlik (1987), “A new definition of the rainflow cycle counting method” [4] Amzallag et al. (1994), “Standardization of the rainflow counting method”

See also

findtp

Find indices to turning points.

findextrema

Find indices to local maxima and minima.

findcross

Find indices to level crossings.

py_fatigue.cycle_count.rainflow.rainflow(data: ndarray | list, time: ndarray | list | None = None, method: str = 'astm', extended_output: bool = True) ndarray | Tuple#

Returns the cycle-count of the input data calculated through the rainflow method (ASTM or four-point).

Parameters:
  • data (Union[np.ndarray, list]) – time series or residuals sequence

  • time (Optional[Union[np.ndarray, list]], optional) – sampled times, by default None

  • method (str, optional) – “astm” or “fourpoint”

  • extended_output (bool, optional) – If True, also return residuals.

Return type:

Union[np.ndarray, tuple]

py_fatigue.cycle_count.rainflow.findcross(x: ndarray, v=0.0, kind=None) ndarray#

Return indices to level v up and/or downcrossings of a vector

Parameters:
  • x (array_like) – vector with sampled values.

  • v (scalar, real) – level v.

  • kind (string) – defines type of crossing returned. Possible options are - ‘d’ : downcrossings only - ‘u’ : upcrossings only - None : All crossings will be returned

Returns:

ind – indices to the crossings in the original sequence x.

Return type:

array-like

Example

>>> from matplotlib import pyplot as plt
>>> import py_fatigue.wafo.misc as wm
>>> ones = np.ones
>>> np.allclose(findcross([0, 1, -1, 1], 0), [0, 1, 2])
True
>>> v = 0.75
>>> t = np.linspace(0,7*np.pi,250)
>>> x = np.sin(t)
>>> ind = wm.findcross(x,v) # all crossings
>>> np.allclose(ind, [  9,  25,  80,  97, 151, 168, 223, 239])
True
>>> ind2 = wm.findcross(x,v,'u')
>>> np.allclose(ind2, [  9,  80, 151, 223])
True
>>> ind3 = wm.findcross(x,v,'d')
>>> np.allclose(ind3, [  25,  97, 168, 239])
True
>>> t0 = plt.plot(t,x,'.',t[ind],x[ind],'r.', t, ones(t.shape)*v)
>>> t0 = plt.plot(t[ind2],x[ind2],'o')
>>> plt.close('all')
py_fatigue.cycle_count.rainflow.findextrema(x: ndarray) ndarray#

Return indices to minima and maxima of a vector

Parameters:

x (vector with sampled values.)

Returns:

ind

Return type:

indices to minima and maxima in the original sequence x.

Examples

>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> import wafo.misc as wm
>>> t = np.linspace(0,7*np.pi,250)
>>> x = np.sin(t)
>>> ind = wm.findextrema(x)
>>> np.allclose(ind, [ 18,  53,  89, 125, 160, 196, 231])
True
>>> a = plt.plot(t,x,'.',t[ind],x[ind],'r.')
>>> plt.close('all')
py_fatigue.cycle_count.rainflow.findtp(x: ndarray) ndarray#

Return indices to turning points (tp) of ASTM rainflow filtered data.

Parameters:

x (vector) – signal to be filtered.

Returns:

ind – indices to the turning points in the original sequence.

Return type:

Union[np.ndarray, None]

Examples

>>> import matplotlib.pyplot as plt
>>> import py_fatigue.wafo.misc as wm
>>> t = np.linspace(0,30,500).reshape((-1,1))
>>> x = np.hstack((t, np.cos(t) + 0.3 * np.sin(5*t)))
>>> x1 = x[0:100,:]
>>> itp = wm.findtp(x1[:,1])
>>> tp = x1[itp,:]
>>> np.allclose(itp, [ 5, 18, 24, 38, 46, 57, 70, 76, 91, 98, 99])
True
>>> a = plt.plot(
... x1[:,0], x1[:,1], tp[:,0], tp[:,1], 'ro')
>>> plt.close('all')

See also

findextrema

py_fatigue.cycle_count.rainflow.findrfc_astm(tp: ndarray, t: ndarray | None = None) ndarray#

Return rainflow counted cycles

Nieslony’s Matlab implementation of the ASTM standard practice for rainflow counting ported to a Python C module.

Parameters:
  • tp (array-like) – vector of turning-points (NB! Only values, not sampled times)

  • t (array-like, optional) – vector of sampled times

Returns:

sig_rfc – array of shape (n,3) or (n, 5) with: sig_rfc[:,0] Cycles amplitude sig_rfc[:,1] Cycles mean value sig_rfc[:,2] Cycle type, half (=0.5) or full (=1.0) sig_rfc[:,3] cycle_begin_time (only if t is given) sig_rfc[:,4] cycle_period_time (only if t is given)

Return type:

array-like

py_fatigue.cycle_count.rainflow.findrfc_fourpoint(tp: ndarray, t: ndarray | None = None) ndarray#

Return rainflow counted cycles using the four-point method.

Parameters:
  • tp (array-like) – vector of turning-points (NB! Only values, not sampled times)

  • t (array-like, optional) – vector of sampled times

Returns:

sig_rfc – array of shape (n,3) or (n, 5) with: sig_rfc[:,0] Cycles amplitude sig_rfc[:,1] Cycles mean value sig_rfc[:,2] Cycle type, half (=0.5) or full (=1.0) sig_rfc[:,3] cycle_begin_time (only if t is given) sig_rfc[:,4] cycle_period_time (only if t is given)

Return type:

array-like