def test_rainflow_3(): a = np.ones(10) a[::2] *= -1 rf, os = cyclecount.rain.rainflow(a, getoffsets=True) rf2, os2 = rainflow(a, getoffsets=True) assert np.allclose(rf, rf2) assert np.all(os2 == os) # should all be half cycles, amp = 1, means = 0 assert np.allclose(1.0, rf[:, 0]) assert np.allclose(0.0, rf[:, 1]) assert np.allclose(0.5, rf[:, 2]) # offset starts = 0, 1, 2, ... len(a)-1 # offset ends = 1, 2, 3, ... len(a) assert np.all(np.arange(len(a) - 1) == os[:, 0]) assert np.all(np.arange(1, len(a)) == os[:, 1])
def test_rainflow_4(): a = np.ones(10) a[::2] *= -1 a[0] *= 2.0 # make rainflow not accept first point until the end rf, os = cyclecount.rain.rainflow(a, getoffsets=True) rf2, os2 = rainflow(a, getoffsets=True) assert np.allclose(rf, rf2) assert np.all(os2 == os) # should almost all full cycles, amp = 1, means = 0 rf_shouldbe = [ [1.0, 0.0, 1.0], [1.0, 0.0, 1.0], [1.0, 0.0, 1.0], [1.0, 0.0, 1.0], [1.5, -0.5, 0.5], ] # range: -2 to +1 = 3 os_shouldbe = [[1, 2], [3, 4], [5, 6], [7, 8], [0, 9]] assert np.allclose(rf_shouldbe, rf) assert np.allclose(os_shouldbe, os)
def test_rainflow_1(): a = np.arange(25000) a[::2] *= -1 rf, os = cyclecount.rain.rainflow(a, getoffsets=True) rf2, os2 = rainflow(a, getoffsets=True) assert np.allclose(rf, rf2) assert np.all(os2 == os) # should all be half cycles, amp = .5, 1.5, ..., # means = [.5, -.5, .5, -.5 ...] amp = np.arange(len(a) - 1, dtype=float) + 0.5 means = 0.5 * np.ones(len(a) - 1) means[1::2] *= -1.0 assert np.allclose(amp, rf[:, 0]) assert np.allclose(means, rf[:, 1]) assert np.allclose(0.5, rf[:, 2]) # offset starts = 0, 1, 2, ... len(a)-1 # offset ends = 1, 2, 3, ... len(a) assert np.all(np.arange(len(a) - 1) == os[:, 0]) assert np.all(np.arange(1, len(a)) == os[:, 1])