Skip to content

Commit

Permalink
add tests for transforming to atlas space function (#38)
Browse files Browse the repository at this point in the history
* add tests for transforming to atlas space function

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Ruff is not smart enough to break strings

* parametrise test

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: willGraham01 <[email protected]>
  • Loading branch information
3 people authored Feb 27, 2024
1 parent 0b5884f commit e075840
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
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

0 comments on commit e075840

Please sign in to comment.