iamlikeme / rainflow

Implementation of the rainflow-counting algorythm in Python
MIT License
105 stars 34 forks source link

Rainflow Matrix #61

Closed abhijeet-pandey closed 2 years ago

abhijeet-pandey commented 2 years ago

Not really an issue but a request for feature addition to get the rainflow matrix with cycles, mean and range into defined number of bins. This will make it convenient for fatigue calculation. The function count_cycle partially fulfills this need except that it does not produce corresponding means. For calculating bins for the mean one has to take care of weighing the means with number of cycles as explained here:http://www.vibrationdata.com/tutorials2/rainflow_counting_revB.pdf

iamlikeme commented 2 years ago

Hello! Whenever you need both ranges and means you can use the function extract_cycles instead of count_cycles. Constructing a matrix (2-dimensional histogram) is, in my opinion, outside the scope of the rainflow library. There are other, excellent tools for doing that. You could for example use numpy:

ranges = []
means = []
counts = []

for range, mean, count, *_ in rainflow.extract_cycles():
    ranges.append(range)
    means.append(mean)
    counts.append(count)

import numpy as np

matrix = np.histogram2d(x=ranges, y=means, weights=counts)
abhijeet-pandey commented 2 years ago

Thanks.