Skip to content

Commit

Permalink
Fix another dups detection issue
Browse files Browse the repository at this point in the history
Signed-off-by: Johannes Mueller <[email protected]>
  • Loading branch information
johannes-mueller committed Jun 24, 2021
1 parent 5fe5dc6 commit 2894aa0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pylife/stress/rainflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ def plateau_turns(diffs):
edges = np.diff(duplicates)
dups_starts = np.where(edges > 0)[0]
dups_ends = np.where(edges < 0)[0]
if len(dups_starts) and len(dups_ends) and dups_ends[0] < dups_starts[0]:
if len(dups_starts) and len(dups_ends):
cut_ends = dups_ends[0] < dups_starts[0]
cut_starts = dups_starts[-1] > dups_ends[-1]
if cut_ends:
dups_ends = dups_ends[1:]
if cut_starts:
dups_starts = dups_starts[:-1]
plateau_turns[dups_starts[np.where(diffs[dups_starts] * diffs[dups_ends+1] < 0)]] = True
plateau_turns[dups_starts[np.where(diffs[dups_starts] * diffs[dups_ends+1] < 0)]] = True

return plateau_turns

Expand Down
9 changes: 9 additions & 0 deletions tests/stress/test_rainflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,15 @@ def test_rainflow_get_turns_shifted_index_four_initial_dups():
np.testing.assert_array_equal(values, expected_values)


def test_rainflow_get_turns_shifted_index_four_initial_dups():
samples = np.array([32., 32.1, 32.9, 33., 33., 33., 33., 33., 32.5, 32., 32., 32.7, 37.2, 40., 35.2, 33., 33., 33., 33., 33.])
expected_index = [3, 9, 13]
expected_values = [33., 32., 40.]
index, values = RF.get_turns(samples)
np.testing.assert_array_equal(index, expected_index)
np.testing.assert_array_equal(values, expected_values)


def test_rainflow_get_turns_leading_dups():
samples = np.array([1., 1., 1., 2., 1.])
expected_index = [3]
Expand Down

0 comments on commit 2894aa0

Please sign in to comment.