Skip to content

Commit

Permalink
Fix hemisphere bug in check_orientation (#207)
Browse files Browse the repository at this point in the history
* add test for check_orientation bug #200

* hide left hemi when right requested, and vice-versa
  • Loading branch information
alessandrofelder committed Jun 26, 2024
1 parent 517d578 commit b6a22e5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions brainreg/napari/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,11 +560,11 @@ def check_orientation(event=None):
atlas = BrainGlobeAtlas(widget.atlas_key.value.name)
if brain_geometry.value == "hemisphere_l":
atlas.reference[
atlas.hemispheres == atlas.left_hemisphere_value
atlas.hemispheres == atlas.right_hemisphere_value
] = 0
elif brain_geometry.value == "hemisphere_r":
atlas.reference[
atlas.hemispheres == atlas.right_hemisphere_value
atlas.hemispheres == atlas.left_hemisphere_value
] = 0
input_orientation = getattr(widget, "data_orientation").value
data = getattr(widget, "img_layer").value.data
Expand Down
16 changes: 16 additions & 0 deletions tests/test_brainreg_napari.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,22 @@ def test_orientation_check(
# run again and check previous output was deleted properly
run_and_check_orientation_check(widget, viewer, brain_layer, atlas)

# "allen_mouse_50um" orientation is ASR
# so S-I projection will have origin AR
# so the columns 0 to half should be filled with zeros
# if we only want to register to the left hemisphere
# LR axis is 228
widget.brain_geometry.value = widget.brain_geometry.annotation[
"Left hemisphere"
]
run_and_check_orientation_check(widget, viewer, brain_layer, atlas)
ar_projection = viewer.layers["Ref. proj. 1"].data
import numpy as np

assert ar_projection.shape[1] // 2 == 114
assert np.all(ar_projection[:, 114] == 0)
assert not np.all(ar_projection[:, 115] == 0)


def run_and_check_orientation_check(widget, viewer, brain_layer, atlas):
widget.check_orientation_button.clicked()
Expand Down

0 comments on commit b6a22e5

Please sign in to comment.