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

add tests for transforming to atlas space function #38

Merged
merged 4 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ dev = [
"pyqt5",
"pytest-cov",
"pytest-qt",
"pytest-mock",
"pytest",
"qtpy",
"ruff",
Expand Down
60 changes: 60 additions & 0 deletions tests/tests/test_brainreg/test_transform.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
from pathlib import Path

import numpy as np
import pytest
from bg_atlasapi import BrainGlobeAtlas

from brainglobe_utils.brainreg.transform import (
transform_points_from_downsampled_to_atlas_space,
)


@pytest.mark.parametrize(
(
"mock_deformation_field",
"expected_transformed_points",
"expected_points_out_of_bounds",
),
[
(np.ones((132, 80, 114)), [[10, 10, 10], [10, 10, 10]], []),
(np.ones((4, 4, 4)), np.atleast_3d([]), [[5, 5, 5], [6, 6, 6]]),
],
)
def test_transform_points_from_downsampled_to_atlas_space(
mocker,
mock_deformation_field,
expected_transformed_points,
expected_points_out_of_bounds,
):
"""
Test case for transforming points from downsampled space to atlas space.
* check that deformation field of ones maps to 1,1,1*resolution
* check that too small deformation field maps points to out-of-bounds

Args:
mocker: The mocker object used to patch the reading of deformation
field tiffs.

Returns:
None
"""
mocker.patch(
"brainglobe_utils.brainreg.transform.tifffile.imread",
side_effect=lambda x: mock_deformation_field,
)
downsampled_points = np.array([[5, 5, 5], [6, 6, 6]])
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,
# all coordinates should be mapped to [1,1,1]*1mm/100um = [10,10,10]
assert np.all(transformed_points == expected_transformed_points)
assert points_out_of_bounds == expected_points_out_of_bounds
Loading