iamlikeme / rainflow

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

Repeated bins for binsize option with float #46

Closed CWE0 closed 3 years ago

CWE0 commented 3 years ago

The following script:

from rainflow import count_cycles
import math

def amplitude(t):
    return (0.54*math.sin(2.*math.pi*0.5*t)+
            0.27*math.sin(2.*math.pi*1.6*t)+
            0.09*math.sin(2.*math.pi*9.7*t))

signal = [amplitude(i*0.01) for i in range(1000)]

cyc = count_cycles(signal,binsize=0.2)

for c in cyc:
    print('{0:f} : {1:f}'.format(c[0],c[1]))

produces:

0.200000 : 81.000000
0.400000 : 9.000000
0.600000 : 2.000000
0.800000 : 1.000000
1.000000 : 0.000000
1.200000 : 0.000000
1.400000 : 0.000000
1.600000 : 0.000000
1.600000 : 2.000000
1.800000 : 0.000000
1.800000 : 2.500000

The reason is that rng in line 154-157 is computed via summation while it is computed via the product n*binsize above. Due to round-off the keys are not identical.

iamlikeme commented 3 years ago

Good catch! Would you like to contribute a fix?

CWE0 commented 3 years ago

Sure I will do

Am 15.11.2020 um 13:30 schrieb Piotr Janiszewski notifications@github.com:

 Good catch! Would you like to contribute a fix?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

gsokoll commented 3 years ago

I've never liked the use of the [n * binsize] floats as keys into the countsdictionary. Perhaps it would be more elegant to use int keys instead.