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

tests(disordered_tracing): Bulks out missing unittests #978

Merged
merged 1 commit into from
Oct 23, 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
38 changes: 31 additions & 7 deletions tests/tracing/test_disordered_tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1452,12 +1452,12 @@ def test_compile_skan_stats() -> None:

@pytest.mark.skip(reason="Awaiting test to be written 2024-10-15.")
def test_segment_heights() -> None:
"""Test of prep_segment_heights()."""
"""Test of segment_heights()."""


@pytest.mark.skip(reason="Awaiting test to be written 2024-10-15.")
def test_segment_middles() -> None:
"""Test of prep_segment_middles()."""
"""Test of segment_middles()."""


@pytest.mark.skip(reason="Awaiting test to be written 2024-10-15.")
Expand All @@ -1470,16 +1470,40 @@ def test_prep_arrays() -> None:
"""Test of prep_arrays()."""


@pytest.mark.skip(reason="Awaiting test to be written 2024-10-15.")
def test_grain_anchor() -> None:
@pytest.mark.parametrize(
("array_shape", "bounding_box", "pad_width", "target"),
[
pytest.param((3, 3), [1, 1, 2, 2], 1, (0, 0), id="Simple square padded by 1 to edges"),
pytest.param((3, 3), [1, 1, 2, 2], 2, (0, 0), id="Simple square padded by 2 beyond both edges"),
pytest.param((3, 10), [1, 1, 2, 2], 4, (0, 0), id="Simple square padded by 4 beyond rows but within columns"),
pytest.param((10, 10), [7, 7, 9, 9], 4, (3, 3), id="Simple square padded by 4 beyond bottom and right edges"),
],
)
def test_grain_anchor(array_shape: tuple, bounding_box: list, pad_width: int, target: npt.NDArray) -> None:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is grain_anchor used anywhere? I pulled the branch and can't find any references to where it's used
image

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure, I recall I introduced it because we needed a way of putting tracing, done on cropped grains, back into the original image and the solution I came up with was to have an anchor point so we could put it back in the right location.

If its been removed in the refactor in favour of an alternative method of putting everything back that is perfectly fine but there was too much in the code/pull request for me to spot that.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well it's tested and imo potentially useful so let's keep it. Was just wondering 😄

"""Test of grain_anchor()."""
grain_anchor = disordered_tracing.grain_anchor(array_shape, bounding_box, pad_width)
assert grain_anchor == target


@pytest.mark.skip(reason="Awaiting test to be written 2024-10-15.")
def test_get_skan_image() -> None:
"""Test of grain_anchor()."""
"""Test of get_skan_image()."""


@pytest.mark.skip(reason="Awaiting test to be written 2024-10-15.")
def test_pad_bounding_box() -> None:
@pytest.mark.parametrize(
("array_shape", "bounding_box", "pad_width", "target"),
[
pytest.param((3, 3), [1, 1, 2, 2], 1, [0, 0, 3, 3], id="Simple square padded by 1 to edges"),
pytest.param((3, 3), [1, 1, 2, 2], 2, [0, 0, 3, 3], id="Simple square padded by 2 all edges"),
pytest.param(
(3, 10), [1, 1, 2, 2], 4, [0, 0, 3, 6], id="Simple square padded by 4 beyond rows but within columns"
),
pytest.param(
(10, 10), [7, 7, 9, 9], 4, [3, 3, 10, 10], id="Simple square padded by 4 beyond bottom and right edges"
),
],
)
def test_pad_bounding_box(array_shape: tuple, bounding_box: list, pad_width: int, target: npt.NDArray) -> None:
"""Test of pad_bounding_box()."""
padded_box = disordered_tracing.pad_bounding_box(array_shape, bounding_box, pad_width)
assert padded_box == target
7 changes: 4 additions & 3 deletions topostats/tracing/disordered_tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@

LOGGER = logging.getLogger(LOGGER_NAME)

# pylint: disable=too-many-positional-arguments
# too-many-positional-arguments
# pylint: disable=R0917
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah nice! I've been looking for a way to suppress this warning as the # pylint: disable=too-many-positional-arguments doesn't seem to work!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its quite annoying as its a valid name but doesn't seem to be recognised. I should raise an issue but still have to report to the Topoloy developers the issues with Python version releases and other problems uncovered the other day and don't have time for everything.



class disorderedTrace: # pylint: disable=too-many-instance-attributes
Expand Down Expand Up @@ -526,7 +527,7 @@ def prep_arrays(
Returns
-------
Tuple
Returns a tuple of two dictionaries, each consisting of cropped arrays.
Returns a tuple of three dictionaries, the cropped images, cropped masks and bounding boxes.
"""
# Get bounding boxes for each grain
region_properties = skimage_measure.regionprops(labelled_grains_mask)
Expand Down Expand Up @@ -729,7 +730,7 @@ def pad_bounding_box(array_shape: tuple, bounding_box: list, pad_width: int) ->
Parameters
----------
array_shape : tuple
Shape of original image.
Shape of original image (row, columns).
bounding_box : list
List of coordinates 'min_row', 'min_col', 'max_row', 'max_col'.
pad_width : int
Expand Down
Loading