Skip to content

Fix find_rainflow_matrix off-by-one when bins given as int - #32

Open
Ayberkrk wants to merge 1 commit into
Gunnstein:masterfrom
Ayberkrk:fix-rainflow-matrix-bin-count
Open

Ayberkrk wants to merge 1 commit into
Gunnstein:masterfrom
Ayberkrk:fix-rainflow-matrix-bin-count

Conversation

@Ayberkrk

Copy link
Copy Markdown

find_rainflow_matrix(data, rowbins, colbins) treats rowbins/colbins as an edge count when they're given as an int, but np.linspace(min, max, rowbins) needs rowbins + 1 edges to actually produce rowbins bins. Requesting 10 bins on an axis comes back as 9 bins, silently, no error raised.

Reproduced: fatpack.find_rainflow_matrix(data, 10, 10, return_bins=True) returns a 9x9 matrix instead of 10x10.

get_load_classes elsewhere in the same file already does this right (np.linspace(ymin, ymax, k+1)), so this brings find_rainflow_matrix in line with the rest of the module rather than introducing a new convention.

Fix is one line per axis: rowbins + 1 / colbins + 1.

Added TestFindRainflowMatrixIntBins covering the int-bins path, since the existing TestFindRainflowMatrix only exercises explicit bin-edge arrays and never caught this. Verified the new test fails on the old code (git stash) with the wrong shape, passes with the fix.

Full test suite passes, 55 tests.

np.linspace(min, max, rowbins) was using rowbins as the edge count, but
an edge count of N only makes N-1 bins. Requesting 10 bins came back as
a 9x9 matrix, silently wrong shape with no error.

Changed it to rowbins + 1 / colbins + 1 so N bins actually means N bins.
get_load_classes in the same file already does this correctly (k+1), so
this brings find_rainflow_matrix in line with the rest of the module.

Added a test covering the int-bins path specifically, since the existing
TestFindRainflowMatrix only ever exercises the explicit bin-edge-array
path and never caught this. Confirmed the new test fails on the old code
and passes with the fix. Full suite passes, 55 tests.
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

Successfully merging this pull request may close these issues.

1 participant