Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Feb 22, 2024
1 parent 2271c2d commit e6f71df
Showing 1 changed file with 47 additions and 31 deletions.
78 changes: 47 additions & 31 deletions tests/tests/test_brainreg/test_transform.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
from brainglobe_utils.brainreg.transform import transform_points_from_downsampled_to_atlas_space
import numpy as np
from pathlib import Path

import numpy as np
from bg_atlasapi import BrainGlobeAtlas

from brainglobe_utils.brainreg.transform import (
transform_points_from_downsampled_to_atlas_space,
)


def test_transform_points_from_downsampled_to_atlas_space(mocker):
"""
Test case for transforming points from downsampled space to atlas space.
Expand All @@ -14,26 +19,34 @@ def test_transform_points_from_downsampled_to_atlas_space(mocker):
Returns:
None
"""
mock_deformation_field = np.ones((132, 80, 114)) # shape of allen 100 reference, has unit mm
mock_deformation_field = np.ones(
(132, 80, 114)
) # shape of allen 100 reference, has unit mm
mocker.patch(
"brainglobe_utils.brainreg.transform.tifffile.imread", side_effect=lambda x: mock_deformation_field
"brainglobe_utils.brainreg.transform.tifffile.imread",
side_effect=lambda x: mock_deformation_field,
)
downsampled_points=np.array([[1,1,1], [2,2,2]])
transformed_points, points_out_of_bounds = transform_points_from_downsampled_to_atlas_space(
downsampled_points=downsampled_points,
atlas=BrainGlobeAtlas("allen_mouse_100um"),
deformation_field_paths=[
Path.home()/"dummy_x_deformation.tif",
Path.home()/"dummy_y_deformation.tif",
Path.home()/"dummy_z_deformation.tif"
]
downsampled_points = np.array([[1, 1, 1], [2, 2, 2]])
transformed_points, points_out_of_bounds = (
transform_points_from_downsampled_to_atlas_space(
downsampled_points=downsampled_points,
atlas=BrainGlobeAtlas("allen_mouse_100um"),
deformation_field_paths=[
Path.home() / "dummy_x_deformation.tif",
Path.home() / "dummy_y_deformation.tif",
Path.home() / "dummy_z_deformation.tif",
],
)
)
# because we mock the deformation field as all ones,
# because we mock the deformation field as all ones,
# all coordinates should be mapped to [1,1,1]*1mm/100um = [10,10,10]
assert np.all(transformed_points == np.ones_like(transformed_points)*10)
assert np.all(transformed_points == np.ones_like(transformed_points) * 10)
assert not points_out_of_bounds, str(points_out_of_bounds)

def test_transform_points_from_downsampled_to_atlas_space_out_of_bounds(mocker):


def test_transform_points_from_downsampled_to_atlas_space_out_of_bounds(
mocker,
):
"""
Test case for transforming points from downsampled space to atlas space when points are out of bounds.
Points are out of bounds when they cause an index error on the deformation field.
Expand All @@ -44,21 +57,24 @@ def test_transform_points_from_downsampled_to_atlas_space_out_of_bounds(mocker):
Returns:
None
"""
mock_deformation_field = np.ones((4,4,4))
mock_deformation_field = np.ones((4, 4, 4))
mocker.patch(
"brainglobe_utils.brainreg.transform.tifffile.imread", side_effect=lambda x: mock_deformation_field
"brainglobe_utils.brainreg.transform.tifffile.imread",
side_effect=lambda x: mock_deformation_field,
)
downsampled_points=np.array([[5,5,5]])
transformed_points, points_out_of_bounds = transform_points_from_downsampled_to_atlas_space(
downsampled_points=downsampled_points,
atlas=BrainGlobeAtlas("allen_mouse_100um"),
deformation_field_paths=[
Path.home()/"dummy_x_deformation.tif",
Path.home()/"dummy_y_deformation.tif",
Path.home()/"dummy_z_deformation.tif"
]
downsampled_points = np.array([[5, 5, 5]])
transformed_points, points_out_of_bounds = (
transform_points_from_downsampled_to_atlas_space(
downsampled_points=downsampled_points,
atlas=BrainGlobeAtlas("allen_mouse_100um"),
deformation_field_paths=[
Path.home() / "dummy_x_deformation.tif",
Path.home() / "dummy_y_deformation.tif",
Path.home() / "dummy_z_deformation.tif",
],
)
)

assert len(transformed_points)==0
assert len(points_out_of_bounds)==1
assert points_out_of_bounds[0]==[5,5,5]
assert len(transformed_points) == 0
assert len(points_out_of_bounds) == 1
assert points_out_of_bounds[0] == [5, 5, 5]

0 comments on commit e6f71df

Please sign in to comment.