Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repeated bins for binsize option with float #46

Closed
CWE0 opened this issue Nov 12, 2020 · 3 comments
Closed

Repeated bins for binsize option with float #46

CWE0 opened this issue Nov 12, 2020 · 3 comments

Comments

@CWE0
Copy link
Contributor

CWE0 commented Nov 12, 2020

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
Copy link
Owner

Good catch! Would you like to contribute a fix?

@CWE0
Copy link
Contributor Author

CWE0 commented Nov 16, 2020 via email

@gsokoll
Copy link
Contributor

gsokoll commented Nov 17, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants