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

Skip empty slicegroups to avoid creating blank rows in output metric CSV file #4487

Merged
merged 4 commits into from
May 22, 2024

Conversation

joshuacwnewton
Copy link
Member

@joshuacwnewton joshuacwnewton commented May 17, 2024

Description

For data where an image is split into multiple chunks, you may want to call the same sct_extract_metric command on multiple chunks spanning a range of vertlevels (e.g. -vert 1:12). But, not all chunks will contain all of the specified levels.

For this case, there is a bug where an agg_metric entry will be created for the slicegroup "()", i.e. a group containing no slices. This will result in an empty row containing no data.

This PR adds a test that reproduces the condition and fails. As soon as the empty slicegroup row is removed, the test will pass.

Linked issues

Fixes sct-pipeline/spine-park#35.

For data where an image is split into multiple chunks, you may want to call the same command
on multiple chunks spanning a range of vertlevels (e.g. -vert 1:12). But, not all chunks will
span all levels.

In this case, there is a bug where a table entry will be created for the slicegroup "()", i.e.
a group containing no slices. This is a useless row containing no data.

This commit adds a test that reproduces the condition and fails. As soon as the empty slicegroup
row is removed, the test will pass.
@joshuacwnewton joshuacwnewton added bug category: fixes an error in the code sct_extract_metric context: SCT API: aggregate_slicewise.py context: labels May 17, 2024
@joshuacwnewton joshuacwnewton added this to the 6.4 milestone May 17, 2024
@joshuacwnewton joshuacwnewton self-assigned this May 17, 2024
The `if slicegroups`/`if not slicegroups` check is duplicated, which I don't love. An alternative
could be to remove empty slicegroups from `slicegroups` entirely. But, then we wouldn't be able
to use `vertgroups[slicegroups.index(slicegroup)]`, since vertgroups and slicegroups would be
different sizes.

In general, this code really needs a refactor. See this already open issue:

- #4005
This is a slight tidy up as a follow-up to the comment in the previous commit.
@joshuacwnewton joshuacwnewton marked this pull request as ready for review May 17, 2024 15:22
Copy link
Member

@jcohenadad jcohenadad left a comment

Choose a reason for hiding this comment

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

I have not tested the code, but the change makes sense, there is now a test, so i'm approving. Thank you @joshuacwnewton

Copy link
Member

@mguaypaq mguaypaq left a comment

Choose a reason for hiding this comment

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

Looks good, and thanks for the little cleanup.

@joshuacwnewton joshuacwnewton merged commit a7a3f8d into master May 22, 2024
20 checks passed
@joshuacwnewton joshuacwnewton deleted the jn/35-empty-sct_extract_metric-entries branch May 22, 2024 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug category: fixes an error in the code SCT API: aggregate_slicewise.py context: sct_extract_metric context:
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sct_extract_metric outputs empty lines
3 participants