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

refactor(grainstats): GrainStats.get_max_min_feret() > measure.feret #823

Merged
merged 4 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
centre_x centre_y radius_min radius_max radius_mean radius_median height_min height_max height_median height_mean volume area area_cartesian_bbox smallest_bounding_width smallest_bounding_length smallest_bounding_area aspect_ratio threshold max_feret min_feret image
molecule_number
0 7.500895e-08 4.775362e-08 4.044948e-09 2.542964e-08 1.600048e-08 1.647888e-08 1.006306e-09 2.696640e-09 1.597337e-09 1.596062e-09 1.084371e-24 6.794043e-16 1.319762e-15 2.053897e-08 5.037861e-08 1.034725e-15 2.452830 above 5.037861e-08 2.053897e-08 None
1 8.028649e-08 7.895237e-08 6.658610e-09 2.623645e-08 1.609777e-08 1.573693e-08 1.009513e-09 2.480685e-09 1.668932e-09 1.683197e-09 1.031843e-24 6.130257e-16 1.526707e-15 2.017441e-08 4.942135e-08 9.970467e-16 2.449704 above 4.987228e-08 2.017441e-08 None
2 4.001424e-08 7.585689e-08 9.745734e-09 2.369314e-08 1.746942e-08 1.818722e-08 1.006681e-09 2.139365e-09 1.646541e-09 1.598842e-09 1.123717e-24 7.028320e-16 1.546230e-15 3.359220e-08 4.149625e-08 1.393950e-15 1.235294 above 4.440534e-08 3.176819e-08 None
centre_x centre_y radius_min radius_max radius_mean radius_median height_min height_max height_median height_mean volume area area_cartesian_bbox smallest_bounding_width smallest_bounding_length smallest_bounding_area aspect_ratio threshold max_feret min_feret max_feret_coords min_feret_coords image
molecule_number
0 7.500895e-08 4.775362e-08 4.044948e-09 2.542964e-08 1.600048e-08 1.647888e-08 1.006306e-09 2.696640e-09 1.597337e-09 1.596062e-09 1.084371e-24 6.794043e-16 1.319762e-15 2.053897e-08 5.037861e-08 1.034725e-15 2.452830 above 5.037861e-08 2.053897e-08 [[10, 0], [5, 25]] [[10.1923076923077, 15.0384615384615], [0.0, 13.0]] None
1 8.028649e-08 7.895237e-08 6.658610e-09 2.623645e-08 1.609777e-08 1.573693e-08 1.009513e-09 2.480685e-09 1.668932e-09 1.683197e-09 1.031843e-24 6.130257e-16 1.526707e-15 2.017441e-08 4.942135e-08 9.970467e-16 2.449704 above 4.987228e-08 2.017441e-08 [[1, 1], [15, 22]] [[10.2518248175182, 6.6824817518248], [1.0, 11.0]] None
2 4.001424e-08 7.585689e-08 9.745734e-09 2.369314e-08 1.746942e-08 1.818722e-08 1.006681e-09 2.139365e-09 1.646541e-09 1.598842e-09 1.123717e-24 7.028320e-16 1.546230e-15 3.359220e-08 4.149625e-08 1.393950e-15 1.235294 above 4.440534e-08 3.176819e-08 [[21, 6], [0, 14]] [[11.1834319526627, 14.8402366863905], [5.0, 0.0]] None
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
image_size_x_m image_size_y_m image_area_m2 image_size_x_px image_size_y_px image_area_px2 grains_number_above grains_per_m2_above grains_number_below grains_per_m2_below rms_roughness
image
image
minicircle_small 1.2646e-07 1.2646e-07 1.5993e-14 64 64 4096 3 1.8758e+14 0 0.0000e+00 6.8208e-10
centre_x centre_y radius_min radius_max radius_mean radius_median height_min height_max height_median height_mean volume area area_cartesian_bbox smallest_bounding_width smallest_bounding_length smallest_bounding_area aspect_ratio threshold max_feret min_feret image contour_length circular end_to_end_distance
molecule_number
0 7.5100e-08 4.7559e-08 3.9431e-09 2.5631e-08 1.6016e-08 1.6680e-08 9.1991e-10 2.6422e-09 1.5338e-09 1.5341e-09 1.0543e-24 6.8721e-16 1.3198e-15 2.0539e-08 5.0379e-08 1.0347e-15 2.4528e+00 above 5.0379e-08 2.0539e-08 minicircle_small 6.0226e-08 False 8.6738e-09
1 8.0241e-08 7.8677e-08 6.8951e-09 2.7188e-08 1.6272e-08 1.6263e-08 9.0630e-10 2.4586e-09 1.6144e-09 1.6264e-09 1.0352e-24 6.3645e-16 1.5931e-15 2.0174e-08 5.1212e-08 1.0332e-15 2.5385e+00 above 5.1262e-08 2.0174e-08 minicircle_small 6.6355e-08 True 0.0000e+00
2 4.0012e-08 7.5644e-08 9.9461e-09 2.3654e-08 1.7561e-08 1.8364e-08 9.0641e-10 2.1066e-09 1.5939e-09 1.5493e-09 1.1192e-24 7.2236e-16 1.5462e-15 3.3592e-08 4.1496e-08 1.3940e-15 1.2353e+00 above 4.4405e-08 3.2528e-08 minicircle_small 9.6106e-08 True 0.0000e+00
centre_x centre_y radius_min radius_max radius_mean radius_median height_min height_max height_median height_mean volume area area_cartesian_bbox smallest_bounding_width smallest_bounding_length smallest_bounding_area aspect_ratio threshold max_feret min_feret max_feret_coords min_feret_coords image contour_length circular end_to_end_distance
molecule_number
0 7.5100e-08 4.7559e-08 3.9431e-09 2.5631e-08 1.6016e-08 1.6680e-08 9.1991e-10 2.6422e-09 1.5338e-09 1.5341e-09 1.0543e-24 6.8721e-16 1.3198e-15 2.0539e-08 5.0379e-08 1.0347e-15 2.4528e+00 above 5.0379e-08 2.0539e-08 [[10, 0], [5, 25]] [[10.1923076923077, 15.0384615384615], [0.0, 13.0]] minicircle_small 6.0226e-08 False 8.6738e-09
1 8.0241e-08 7.8677e-08 6.8951e-09 2.7188e-08 1.6272e-08 1.6263e-08 9.0630e-10 2.4586e-09 1.6144e-09 1.6264e-09 1.0352e-24 6.3645e-16 1.5931e-15 2.0174e-08 5.1212e-08 1.0332e-15 2.5385e+00 above 5.1262e-08 2.0174e-08 [[2, 0], [14, 23]] [[10.2518248175182, 6.6824817518248], [1.0, 11.0]] minicircle_small 6.6355e-08 True 0.0000e+00
2 4.0012e-08 7.5644e-08 9.9461e-09 2.3654e-08 1.7561e-08 1.8364e-08 9.0641e-10 2.1066e-09 1.5939e-09 1.5493e-09 1.1192e-24 7.2236e-16 1.5462e-15 3.3592e-08 4.1496e-08 1.3940e-15 1.2353e+00 above 4.4405e-08 3.2528e-08 [[21, 6], [0, 14]] [[10.3313609467456, 15.1952662721894], [4.0, 0.0]] minicircle_small 9.6106e-08 True 0.0000e+00
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
image_size_x_m image_size_y_m image_area_m2 image_size_x_px image_size_y_px image_area_px2 grains_number_above grains_per_m2_above grains_number_below grains_per_m2_below rms_roughness
image
image
minicircle_small 1.2646e-07 1.2646e-07 1.5993e-14 64 64 4096 0 0.0000e+00 1 6.2526e+13 6.8208e-10
centre_x centre_y radius_min radius_max radius_mean radius_median height_min height_max height_median height_mean volume area area_cartesian_bbox smallest_bounding_width smallest_bounding_length smallest_bounding_area aspect_ratio threshold max_feret min_feret image contour_length circular end_to_end_distance
molecule_number
0 3.2366e-08 1.4036e-08 7.7690e-10 1.2272e-08 6.4301e-09 6.4170e-09 -3.7937e-10 -2.1207e-10 -2.4477e-10 -2.6816e-10 -3.0364e-26 1.1323e-16 3.0066e-16 7.0841e-09 2.1505e-08 1.5234e-16 3.0357e+00 below 2.2092e-08 7.0841e-09 minicircle_small NaN NaN NaN
centre_x centre_y radius_min radius_max radius_mean radius_median height_min height_max height_median height_mean volume area area_cartesian_bbox smallest_bounding_width smallest_bounding_length smallest_bounding_area aspect_ratio threshold max_feret min_feret max_feret_coords min_feret_coords image contour_length circular end_to_end_distance
molecule_number
0 3.2366e-08 1.4036e-08 7.7690e-10 1.2272e-08 6.4301e-09 6.4170e-09 -3.7937e-10 -2.1207e-10 -2.4477e-10 -2.6816e-10 -3.0364e-26 1.1323e-16 3.0066e-16 7.0841e-09 2.1505e-08 1.5234e-16 3.0357e+00 below 2.2092e-08 7.0841e-09 [[10, 5], [0, 0]] [[5.7049180327869, 5.7540983606557], [8.0, 3.0]] minicircle_small NaN NaN NaN
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
image_size_x_m image_size_y_m image_area_m2 image_size_x_px image_size_y_px image_area_px2 grains_number_above grains_per_m2_above grains_number_below grains_per_m2_below rms_roughness
image
image
minicircle_small 1.2646e-07 1.2646e-07 1.5993e-14 64 64 4096 3 1.8758e+14 1 6.2526e+13 6.8208e-10
centre_x centre_y radius_min radius_max radius_mean radius_median height_min height_max height_median height_mean volume area area_cartesian_bbox smallest_bounding_width smallest_bounding_length smallest_bounding_area aspect_ratio threshold max_feret min_feret image contour_length circular end_to_end_distance
molecule_number
0 3.2366e-08 1.4036e-08 7.7690e-10 1.2272e-08 6.4301e-09 6.4170e-09 -3.7937e-10 -2.1207e-10 -2.4477e-10 -2.6816e-10 -3.0364e-26 1.1323e-16 3.0066e-16 7.0841e-09 2.1505e-08 1.5234e-16 3.0357e+00 below 2.2092e-08 7.0841e-09 minicircle_small NaN NaN NaN
0 7.5100e-08 4.7559e-08 3.9431e-09 2.5631e-08 1.6016e-08 1.6680e-08 9.1991e-10 2.6422e-09 1.5338e-09 1.5341e-09 1.0543e-24 6.8721e-16 1.3198e-15 2.0539e-08 5.0379e-08 1.0347e-15 2.4528e+00 above 5.0379e-08 2.0539e-08 minicircle_small 6.0226e-08 0.0000e+00 8.6738e-09
1 8.0241e-08 7.8677e-08 6.8951e-09 2.7188e-08 1.6272e-08 1.6263e-08 9.0630e-10 2.4586e-09 1.6144e-09 1.6264e-09 1.0352e-24 6.3645e-16 1.5931e-15 2.0174e-08 5.1212e-08 1.0332e-15 2.5385e+00 above 5.1262e-08 2.0174e-08 minicircle_small 6.6355e-08 1.0000e+00 0.0000e+00
2 4.0012e-08 7.5644e-08 9.9461e-09 2.3654e-08 1.7561e-08 1.8364e-08 9.0641e-10 2.1066e-09 1.5939e-09 1.5493e-09 1.1192e-24 7.2236e-16 1.5462e-15 3.3592e-08 4.1496e-08 1.3940e-15 1.2353e+00 above 4.4405e-08 3.2528e-08 minicircle_small 9.6106e-08 1.0000e+00 0.0000e+00
centre_x centre_y radius_min radius_max radius_mean radius_median height_min height_max height_median height_mean volume area area_cartesian_bbox smallest_bounding_width smallest_bounding_length smallest_bounding_area aspect_ratio threshold max_feret min_feret max_feret_coords min_feret_coords image contour_length circular end_to_end_distance
molecule_number
0 3.2366e-08 1.4036e-08 7.7690e-10 1.2272e-08 6.4301e-09 6.4170e-09 -3.7937e-10 -2.1207e-10 -2.4477e-10 -2.6816e-10 -3.0364e-26 1.1323e-16 3.0066e-16 7.0841e-09 2.1505e-08 1.5234e-16 3.0357e+00 below 2.2092e-08 7.0841e-09 [[10, 5], [0, 0]] [[5.7049180327869, 5.7540983606557], [8.0, 3.0]] minicircle_small NaN NaN NaN
0 7.5100e-08 4.7559e-08 3.9431e-09 2.5631e-08 1.6016e-08 1.6680e-08 9.1991e-10 2.6422e-09 1.5338e-09 1.5341e-09 1.0543e-24 6.8721e-16 1.3198e-15 2.0539e-08 5.0379e-08 1.0347e-15 2.4528e+00 above 5.0379e-08 2.0539e-08 [[10, 0], [5, 25]] [[10.1923076923077, 15.0384615384615], [0.0, 13.0]] minicircle_small 6.0226e-08 0.0000e+00 8.6738e-09
1 8.0241e-08 7.8677e-08 6.8951e-09 2.7188e-08 1.6272e-08 1.6263e-08 9.0630e-10 2.4586e-09 1.6144e-09 1.6264e-09 1.0352e-24 6.3645e-16 1.5931e-15 2.0174e-08 5.1212e-08 1.0332e-15 2.5385e+00 above 5.1262e-08 2.0174e-08 [[2, 0], [14, 23]] [[10.2518248175182, 6.6824817518248], [1.0, 11.0]] minicircle_small 6.6355e-08 1.0000e+00 0.0000e+00
2 4.0012e-08 7.5644e-08 9.9461e-09 2.3654e-08 1.7561e-08 1.8364e-08 9.0641e-10 2.1066e-09 1.5939e-09 1.5493e-09 1.1192e-24 7.2236e-16 1.5462e-15 3.3592e-08 4.1496e-08 1.3940e-15 1.2353e+00 above 4.4405e-08 3.2528e-08 [[21, 6], [0, 14]] [[10.3313609467456, 15.1952662721894], [4.0, 0.0]] minicircle_small 9.6106e-08 1.0000e+00 0.0000e+00
84 changes: 0 additions & 84 deletions tests/test_grainstats.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,87 +285,3 @@ def test_get_cropped_region(grainstats: GrainStats, length, centre, img_len, exp
output = grainstats.get_cropped_region(image, length, centre)
assert output.shape == (2 * length + 1, 2 * length + 1)
assert output[expected[0], expected[1]] == 5


@pytest.mark.parametrize(
("base_point_1", "base_point_2", "top_point", "expected"),
[
(np.array([0, 0]), np.array([1, 0]), np.array([1, 1]), 1),
(np.array([0, 0]), np.array([5, 0]), np.array([2, 5]), 5),
(np.array([0, 0]), np.array([1, 0]), np.array([1, -1]), 1),
],
)
def test_grainstats_get_triangle_height(base_point_1, base_point_2, top_point, expected) -> None:
"""Tests the GrainStats.get_triangle_height method."""
assert GrainStats.get_triangle_height(base_point_1, base_point_2, top_point) == expected


@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."""
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)
4 changes: 2 additions & 2 deletions tests/test_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ def test_process_scan_align_grainstats_dnatracing(
)
tracing_to_check = ["contour_length", "circular", "end_to_end_distance"]

assert results.shape == (3, 25)
assert results.shape == (3, 27)
assert np.isnan(results.loc[2, "contour_length"])
assert np.isnan(sum(results.loc[2, tracing_to_check]))

Expand Down Expand Up @@ -497,7 +497,7 @@ def test_run_grainstats(process_scan_config: dict, tmp_path: Path) -> None:

assert isinstance(grainstats_df, pd.DataFrame)
assert grainstats_df.shape[0] == 13
assert len(grainstats_df.columns) == 21
assert len(grainstats_df.columns) == 23


def test_run_dnatracing(process_scan_config: dict, tmp_path: Path) -> None:
Expand Down
Loading
Loading