Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[ENH]: Add UKB_15K_GM mask #350

Merged
merged 2 commits into from
Jul 17, 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 docs/changes/newsfragments/350.enh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support for ``UKB_15K_GM`` mask by `Synchon Mandal`_
36 changes: 36 additions & 0 deletions junifer/data/masks.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ def compute_brain_mask(
"func": compute_epi_mask,
"space": "inherit",
},
"UKB_15K_GM": {
"family": "UKB",
"space": "MNI152NLin6Asym",
},
}


Expand Down Expand Up @@ -567,6 +571,8 @@ def load_mask(
elif t_family == "Callable":
mask_img = mask_definition["func"]
mask_fname = None
elif t_family == "UKB":
mask_fname = _load_ukb_mask(name)
else:
raise_error(f"I don't know about the {t_family} mask family.")

Expand Down Expand Up @@ -632,3 +638,33 @@ def _load_vickery_patil_mask(
mask_fname = _masks_path / "vickery-patil" / mask_fname

return mask_fname


def _load_ukb_mask(name: str) -> Path:
"""Load UKB mask.

Parameters
----------
name : {"UKB_15K_GM"}
The name of the mask.

Returns
-------
pathlib.Path
File path to the mask image.

Raises
------
ValueError
If ``name`` is invalid.

"""
if name == "UKB_15K_GM":
mask_fname = "UKB_15K_GM_template.nii.gz"
else:
raise_error(f"Cannot find a UKB mask called {name}")

# Set path for masks
mask_fname = _masks_path / "ukb" / mask_fname

return mask_fname
Binary file not shown.
17 changes: 17 additions & 0 deletions junifer/data/tests/test_masks.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

from junifer.data.masks import (
_available_masks,
_load_ukb_mask,
_load_vickery_patil_mask,
compute_brain_mask,
get_mask,
Expand Down Expand Up @@ -212,6 +213,7 @@ def test_register_mask(
[
"GM_prob0.2",
"GM_prob0.2_cortex",
"UKB_15K_GM",
],
)
def test_list_masks_correct(mask_name: str) -> None:
Expand Down Expand Up @@ -291,6 +293,21 @@ def test_vickery_patil_error() -> None:
_load_vickery_patil_mask(name="wrong", resolution=2.0)


def test_ukb() -> None:
"""Test UKB mask."""
mask, mask_fname, space = load_mask("UKB_15K_GM", resolution=2.0)
assert_array_almost_equal(mask.header["pixdim"][1:4], 2.0) # type: ignore
assert space == "MNI152NLin6Asym"
assert mask_fname is not None
assert mask_fname.name == "UKB_15K_GM_template.nii.gz"


def test_ukb_error() -> None:
"""Test error for UKB mask."""
with pytest.raises(ValueError, match=r"find a UKB mask "):
_load_ukb_mask(name="wrong")


def test_get_mask() -> None:
"""Test the get_mask function."""
with OasisVBMTestingDataGrabber() as dg:
Expand Down
Loading