rainflow#

The following code is based on the Python [1] Rainflow algorithm implemented in the WAFO toolbox [2]. The method gives the following definition of rainflow cycles, in accordance with Rychlik (1987) [3]:

From each local maximum Mk one shall try to reach above the same level, in the backward (left) and forward (right) directions, with an as small downward excursion as possible. The minima, m-k and m+k, on each side are identified. The minimum that represents the smallest deviation from the maximum Mk is defined as the corresponding rainflow minimum mRFCk. The k:th rainflow cycle is defined as (mRFCk, Mk).

See also

findtp

Find indices to turning points.

findextrema

Find indices to local maxima and minima.

py_fatigue.cycle_count.rainflow.rainflow(data: ndarray | list, time: ndarray | list | None = None, extended_output: bool = True) ndarray | tuple#

Returns the cycle-count of the input data calculated through the rainflow method.

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

  • time (Optional[Union[np.ndarray, list]], optional) – sampled times, by default None extended_output : bool, optional if False it returns only the rainflow, if True returns also the residuals signal, by default True

Returns:

  • if np.ndarray:
    • rfsnp.ndarray

      rainflow [ampl ampl_mean nr_of_cycle cycle_begin_time cycle_period_time]

  • if tuple:
    • rfsnp.ndarray

      rainflow [ampl ampl_mean nr_of_cycle cycle_begin_time cycle_period_time]

    • data[res_tp]numpy.ndarray

      the residuals signal

    • res_tpnumpy.ndarray

      the indices of the residuals signal

    • time[res_tp]numpy.ndarray

      the time signal for residuals

Return type:

Union[np.ndarray, tuple]

Raises:

TypeError – data shall be numpy.ndarray or list

See also

findtp()

Find indices to turning points.

findextrema()

Find indices to local maxima and minima.

findrfc_astm()

Find rainflow cycles.

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.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')