Skip to content

Ensure volume is calculated for right hemisphere#266

Merged
IgorTatarnikov merged 5 commits intomainfrom
hemisphere-volume-bug
Jan 8, 2026
Merged

Ensure volume is calculated for right hemisphere#266
IgorTatarnikov merged 5 commits intomainfrom
hemisphere-volume-bug

Conversation

@IgorTatarnikov
Copy link
Member

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?
See #265

What does this PR do?
Creates a union from the unique right and left values to loop over when calculating volumes.

Correct default parameters such that left_hemisphere_value=1 and right_hemisphere_value=2.

Ensure the brain geometry value is passed back from the napari widget when calculating region volumes.

References

Closes #265

Please reference any existing issues/PRs that relate to this PR.

How has this PR been tested?

Tested:
Registering left hemisphere -> right_volume_mm3 is always 0 and total_volume_mm3 == left_volume_mm3
Registering right hemisphere -> left_volume_mm3 is always 0 and total_volume_mm3 == right_volume_mm3
Registering full brain -> left_volume_mm3 != 0, right_volume_mm3 != 0, total_volume_mm3 == (right_volume_mm3 + left_volume_mm3)

Is this a breaking change?

No

Does this PR require an update to the documentation?

No

Checklist:

  • The code has been tested locally
  • The code has been formatted with pre-commit

Copilot AI review requested due to automatic review settings December 23, 2025 16:29
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a bug where volume calculation failed when registering only the right hemisphere, resulting in an empty volumes.csv file. The issue occurred because the code only iterated over structures present in the left hemisphere.

Key Changes:

  • Fixed volume calculation to include structures from both hemispheres by using a union of unique values from left and right hemispheres
  • Corrected default hemisphere value parameters to match BrainGlobe atlas standards (left=1, right=2)
  • Added brain_geometry parameter passing from napari widget to properly filter warning messages

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
brainreg/napari/register.py Added brain_geometry parameter when calling calculate_volumes from the napari widget
brainreg/core/utils/volume.py Fixed hemisphere value defaults, created union of unique values from both hemispheres for iteration, improved warning logic for hemisphere-specific registrations, and corrected a spelling error

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@imagesc-bot
Copy link

This pull request has been mentioned on Image.sc Forum. There might be relevant details there:

https://forum.image.sc/t/allen-atlas-not-matching-structures-file/118265/4

@IgorTatarnikov IgorTatarnikov requested a review from a team December 23, 2025 16:56
adamltyson
adamltyson previously approved these changes Jan 8, 2026
Copy link
Member

@adamltyson adamltyson left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks @IgorTatarnikov!

@IgorTatarnikov IgorTatarnikov merged commit effa4e1 into main Jan 8, 2026
25 of 27 checks passed
@adamltyson adamltyson deleted the hemisphere-volume-bug branch January 8, 2026 15:37
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.

[BUG] volumes.csv is empty when registering the right hempisphere only

4 participants