Skip to content

Commit

Permalink
Merge pull request #755 from AFM-SPM/ns-rse/748-grain-profiles
Browse files Browse the repository at this point in the history
New submodule for feret calculations
  • Loading branch information
ns-rse committed Apr 15, 2024
2 parents 6d24aaa + 4e3db2e commit a5f4926
Show file tree
Hide file tree
Showing 12 changed files with 1,979 additions and 6 deletions.
1,360 changes: 1,360 additions & 0 deletions tests/measure/test_feret.py

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
71 changes: 68 additions & 3 deletions tests/test_grainstats.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,72 @@ def test_grainstats_get_triangle_height(base_point_1, base_point_2, top_point, e
assert GrainStats.get_triangle_height(base_point_1, base_point_2, top_point) == expected


@pytest.mark.parametrize(("edge_points", "expected"), [([[0, 0], [0, 1], [1, 0], [1, 1]], (1.0, 1.4142135623730951))])
def test_get_min_max_ferets(edge_points, expected) -> None:
@pytest.mark.parametrize(
("edge_points", "min_expected", "max_expected"),
[
pytest.param([[0, 0], [0, 1], [1, 0], [1, 1]], 1.0, 1.4142135623730951, id="square"),
pytest.param([[1, 1], [1, 2], [2, 1]], 0.7071067811865476, 1.4142135623730951, id="triangle (isosceles)"),
pytest.param([[0, 0], [1, 0], [0, 2]], 0.8944271909999159, 2.23606797749979, id="triangle"),
pytest.param([[0, 1], [1, 0], [1, 2], [2, 1]], 1.4142135623730951, 2.0, id="circle"),
pytest.param([[1, 2], [2, 1], [2, 4], [5, 2]], 2.4961508830135313, 4, id="quadrilateral"),
pytest.param(
[
[1, 3],
[1, 4],
[1, 5],
[1, 6],
[1, 7],
[2, 2],
[2, 8],
[3, 1],
[3, 9],
[4, 1],
[4, 9],
[5, 1],
[5, 9],
[6, 2],
[6, 8],
[7, 3],
[7, 4],
[7, 5],
[7, 6],
[7, 7],
],
6.0,
8.246211251235321,
id="horizontal ellipse",
),
pytest.param(
[
[1, 2],
[1, 3],
[1, 4],
[2, 1],
[2, 5],
[3, 2],
[3, 6],
[4, 3],
[4, 7],
[5, 4],
[5, 8],
[6, 5],
[6, 6],
[6, 7],
],
2.82842712474619,
7.615773105863909,
id="angled ellipse",
),
pytest.param(
[[1, 5], [2, 3], [2, 4], [3, 2], [4, 1], [5, 1], [6, 2], [6, 3], [7, 4], [7, 5], [7, 6], [8, 7], [8, 8]],
5.252257314388902,
8.06225774829855,
id="curved line",
),
],
)
def test_get_min_max_ferets(edge_points, min_expected, max_expected) -> None:
"""Tests the GrainStats.get_min_max_ferets method."""
assert GrainStats.get_max_min_ferets(edge_points) == expected
min_feret, max_feret = GrainStats.get_max_min_ferets(edge_points)
np.testing.assert_almost_equal(min_feret, min_expected)
np.testing.assert_almost_equal(max_feret, max_expected)
2 changes: 0 additions & 2 deletions topostats/grainstats.py
Original file line number Diff line number Diff line change
Expand Up @@ -1071,7 +1071,6 @@ def get_max_min_ferets(edge_points: list) -> tuple[float, float]: # noqa: C901

upper_hull = np.array(upper_hull)
lower_hull = np.array(lower_hull)

# Create list of contact vertices for calipers on the antipodal hulls
contact_points = []
upper_index = 0
Expand Down Expand Up @@ -1133,7 +1132,6 @@ def get_max_min_ferets(edge_points: list) -> tuple[float, float]: # noqa: C901
min_feret = small_feret

contact_points = np.array(contact_points)

# Find the minimum and maximum distance in the contact points
max_feret = None
for point_pair in contact_points:
Expand Down
Loading

0 comments on commit a5f4926

Please sign in to comment.