Skip to content

A small functionality added to annotation_utils.py together with a new test for it. #596

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

Skxsmy
Copy link
Contributor

@Skxsmy Skxsmy commented Jun 25, 2025

Before submitting a pull request (PR), please read the contributing guide.

Please fill out as much of this template as you can, but if you have any problems or questions, just leave a comment and we will help out :)

Description

What is this PR

  • Bug fix
  • Addition of a new feature
  • Other

Why is this PR needed?
Currently the read_itk_labels function only supports 1-letter acryonym
What does this PR do?
Now it allows the user to choose the number of first letters the user want to use as structure acryonym.

How has this PR been tested?

Locally

Is this a breaking change?

no

Does this PR require an update to the documentation?

no

Checklist:

  • The code has been tested locally
  • Tests have been added to cover all new functionality (unit & integration)
  • The documentation has been updated to reflect any changes
  • The code has been formatted with pre-commit

@alessandrofelder alessandrofelder self-requested a review June 25, 2025 15:39
@alessandrofelder alessandrofelder marked this pull request as ready for review July 9, 2025 09:28
Copy link
Member

@alessandrofelder alessandrofelder left a comment

Choose a reason for hiding this comment

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

Cool!
Tiny suggestions to improve code clarity but functionality changes are good.
Consider writing a test for these functions, in a separate PR - (if you have time around your thesis)?

return name, acronym


def read_itk_labels(path: Path) -> dict:
def read_itk_labels(path: Path, acryonym_letter=1) -> dict:
Copy link
Member

Choose a reason for hiding this comment

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

rename argument as suggested above.

@@ -3,7 +3,7 @@
from pathlib import Path


def split_label_text(name: str) -> str:
def split_label_text(name: str, acryonym_letter=1) -> str:
"""Split label text into name + acronym.

If the label text ends with ')', extract the acronym inside parentheses.
Copy link
Member

Choose a reason for hiding this comment

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

This docstring needs updating to explain the new function argument:
The "Otherwise, use the first letter as the acronym" part is now wrong!

@Skxsmy Skxsmy changed the title A small functionality added to annotation_utils.py A small functionality added to annotation_utils.py together with a new test for it. Jul 14, 2025
@alessandrofelder alessandrofelder self-requested a review July 14, 2025 20:27
Copy link
Member

@alessandrofelder alessandrofelder left a comment

Choose a reason for hiding this comment

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

Nice to be thinking about catching errors.
I've made some suggestions around improving the tests - I think they could be a lot simpler.

@@ -12,27 +13,67 @@


@pytest.mark.parametrize(
Copy link
Member

Choose a reason for hiding this comment

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

I would suggest to split this test into three smaller tests, for clarity.

  • One test for default (acronym_length=1)
  • One test for non-default (acronym_length=3 or similar)
  • One for error case (acronym_length = len(atlas_name)+1)

instead of using pytest.param?

"BGA-N",
np.random.randint(1),
Copy link
Member

Choose a reason for hiding this comment

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

I am confused why you are using randint here?
I would keep it simple and use 1, 2, len+1 for the three 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.

2 participants