iamlikeme / rainflow

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

Indexes of the counted cycle range #31

Closed addarnr closed 4 years ago

addarnr commented 4 years ago

Hello,

I am in search of a rainflow counting algorithm in Python that provides the indexes of the counted ranges (similar to the rainflow counting in Matlab) also. Would this implementation rainflow() (rainflow 2.2.0 by PyPI) provide the indexes? If not, is there a way to modify this rainflow() code to obtain the indexes? Are there any other Python based rainflow implementations that provide indexes? Thank you!

iamlikeme commented 4 years ago

Hi! The current version does not provide indices, but it seems fairly straightforward to implement. Are you willing to implement this feature and submit a pull request? Or at least a test case? I am not sure about other Python based implementation of rainflow counting. You would have to research yourself.

addarnr commented 4 years ago

Hello, Yes, I am willing to test a case.
Thank you for your support!

addarnr commented 4 years ago

Hello, please let me know what to do at my end. Thank you!

iamlikeme commented 4 years ago

Hi again. It would be great if you could provide a sample time series and the expected result including indices. Some sample time series are already included in the unit tests, e.g. this one. Perhaps you could generate the expected result using Matlab?

addarnr commented 4 years ago

Hello, yes i will do that and get back to you.

Thanks!

On Thu, Apr 9, 2020, 1:07 PM Piotr Janiszewski notifications@github.com wrote:

Hi again. It would be great if you could provide a sample time series and the expected result including indices. Some sample time series are already included in the unit tests, e.g. this one https://github.com/iamlikeme/rainflow/blob/b1990b4e0c9189479df0b5f720c842e8a9bc66a1/tests/test_rainflow.py#L6. Perhaps you could generate the expected result using Matlab?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/iamlikeme/rainflow/issues/31#issuecomment-611672617, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIFGUYD5YZ7533AZYUBRLFDRLYFGDANCNFSM4MCMKPXQ .

addarnr commented 4 years ago

Hello, I tested (2) series, one from the link you sent me and one my own. The resulting cycle counts, ranges, means, start indices, and end indices are attached.

Thank you!

SERIES 1

series1 = [0, -2, 1, -3, 5, -1, 3, -4, 4, -2, 0];

Count    Range    Mean    Start_Index    End_Index
_____    _____    ____    ___________    _________

 0.5       2        -1         1             2    
 0.5       3      -0.5         2             3    
 0.5       4        -1         3             4    
   1       4         1         6             7    
 0.5       8         1         4             5    
 0.5       9       0.5         5             8    
 0.5       8         0         8             9    
 0.5       6         1         9            10    
 0.5       2        -1        10            11   

SERIES 2

series2 = [-1.5 1 -3 10 -1 3 -8 4 -2 6 -1 -4 -8 2 1 -5 0 2.5 -4 1 0 2 -0.5]

Count    Range    Mean     Start_Index    End_Index
_____    _____    _____    ___________    _________

 0.5      2.5     -0.25         1             2    
 0.5        4        -1         2             3    
   1        4         1         5             6    
 0.5       13       3.5         3             4    
   1        6         1         8             9    
   1       14        -1         7            10    
   1        7      -1.5        14            16    
   1        1       0.5        20            21    
 0.5       18         1         4            13    
 0.5     10.5     -2.75        13            18    
 0.5      6.5     -0.75        18            19    
 0.5        6        -1        19            22    
 0.5      2.5      0.75        22            23    
iamlikeme commented 4 years ago

Thank you for the test cases. I will work on an implementation and get back to you.

gsokoll commented 4 years ago

What is the benefit of this functionality ? Other than for academic interest, it seems to have little to no real world use.

addarnr commented 4 years ago

No, that is not true.
There are cases where the rainflow count of one signal can be used as a representation of another signal that cannot be directly measured. Throttling of a car is an example. Every throttle change causes some damage to the car engine. You can estimate these damages by the rainflow count of the throttle if there is data already available to correlate the two. In this case you need the indices of the throttle rainflow counts to correlate the two.

gsokoll commented 4 years ago

Note that the Matlab rainflow implementation includes an option to return the indices of reversals identified in the data, not cycles. This is not the same as what you have asked for here. https://www.mathworks.com/help/signal/ref/rainflow.html

addarnr commented 4 years ago

Yes the linear indices are what I am after. Sorry if I was not clear. The test results I sent include these linear indices.

On Tue, Apr 14, 2020, 7:26 PM Geoff Sokoll notifications@github.com wrote:

Note that the Matlab rainflow implementation includes an option to return the indices of reversals identified in the data, not cycles. This is not the same as what you have asked for here. https://www.mathworks.com/help/signal/ref/rainflow.html

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/iamlikeme/rainflow/issues/31#issuecomment-613747207, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIFGUYBSKGFE65U6VORMQXLRMT5MVANCNFSM4MCMKPXQ .

iamlikeme commented 4 years ago

The feature you requested is now released in v3.0.0 on PyPI. Here is a usage example:

series = [0, -2, 1, -3, 5, -1, 3, -4, 4, -2, 0]
list(rainflow.extract_cycles(series))
# Output
[(2, -1.0, 0.5, 0, 1),
(3, -0.5, 0.5, 1, 2),
(4, -1.0, 0.5, 2, 3),
...
(2, -1.0, 0.5, 9, 10)]