chore: junifer.data.parcellations cleanup #238
4 changed files with 105 additions and 106 deletions
|
|
@ -269,7 +269,7 @@ Available
|
|||
| A spatially unbiased atlas template of the human cerebellum.
|
||||
| NeuroImage, Volume 33(1), Pages 127–138 (2006).
|
||||
| https://doi.org/10.1016/j.neuroimage.2006.05.056
|
||||
* - TIAN
|
||||
* - Tian
|
||||
- ``scale``, ``space``, ``magneticfield``
|
||||
- | ``TianxS1x3TxMNI6thgeneration``, ``TianxS1x7TxMNI6thgeneration``,
|
||||
| ``TianxS2x3TxMNI6thgeneration``, ``TianxS2x7TxMNI6thgeneration``,
|
||||
|
|
@ -301,7 +301,7 @@ Available
|
|||
- | Shen, X., Tokoglu, F., Papademetris, X., Constable, R.T.
|
||||
| Groupwise whole-brain parcellation from resting-state fMRI data
|
||||
| for network node identification.
|
||||
| Neuroimage, Volume 82 (2013).
|
||||
| NeuroImage, Volume 82 (2013).
|
||||
| https://doi.org/10.1016/j.neuroimage.2013.05.081.
|
||||
| Finn, E.S., Shen, X., Scheinost, D., et al.
|
||||
| Functional connectome fingerprinting: identifying individuals using
|
||||
|
|
@ -353,7 +353,7 @@ Planned
|
|||
* - AAL
|
||||
- | Rolls, E.T., Huang, C.C., Lin, C.P., et al.
|
||||
| Automated anatomical labelling atlas 3.
|
||||
| Neuroimage, Volume 206 (2020).
|
||||
| NeuroImage, Volume 206 (2020).
|
||||
| https://doi.org/10.1016/j.neuroimage.2019.116189
|
||||
* - Mindboggle 101
|
||||
- | Klein, A., & Tourville, J.
|
||||
|
|
|
|||
1
docs/changes/newsfragments/238.misc
Normal file
1
docs/changes/newsfragments/238.misc
Normal file
|
|
@ -0,0 +1 @@
|
|||
Improve docstrings and code style and parametrize remaining tests for ``junifer.data.parcellations`` by `Synchon Mandal`_
|
||||
|
|
@ -308,7 +308,7 @@ def _retrieve_parcellation(
|
|||
``n_rois`` : {100, 200, 300, 400, 500, 600, 700, 800, 900, 1000}
|
||||
Granularity of parcellation to be used.
|
||||
``yeo_network`` : {7, 17}, optional
|
||||
Number of yeo networks to use (default 7).
|
||||
Number of Yeo networks to use (default 7).
|
||||
* Tian :
|
||||
``scale`` : {1, 2, 3, 4}
|
||||
Scale of parcellation (defines granularity).
|
||||
|
|
@ -430,7 +430,7 @@ def _retrieve_schaefer(
|
|||
n_rois : {100, 200, 300, 400, 500, 600, 700, 800, 900, 1000}, optional
|
||||
Granularity of the parceallation to be used (default None).
|
||||
yeo_networks : {7, 17}, optional
|
||||
Number of yeo networks to use (default 7).
|
||||
Number of Yeo networks to use (default 7).
|
||||
|
||||
Returns
|
||||
-------
|
||||
|
|
@ -447,9 +447,9 @@ def _retrieve_schaefer(
|
|||
|
||||
"""
|
||||
logger.info("Parcellation parameters:")
|
||||
logger.info(f"\tresolution: {resolution}")
|
||||
logger.info(f"\tn_rois: {n_rois}")
|
||||
logger.info(f"\tyeo_networks: {yeo_networks}")
|
||||
logger.info(f"\tresolution: {resolution}")
|
||||
|
||||
_valid_n_rois = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]
|
||||
_valid_networks = [7, 17]
|
||||
|
|
@ -555,10 +555,11 @@ def _retrieve_tian(
|
|||
"""
|
||||
# show parameters to user
|
||||
logger.info("Parcellation parameters:")
|
||||
logger.info(f"\tresolution: {resolution}")
|
||||
logger.info(f"\tscale: {scale}")
|
||||
logger.info(f"\tspace: {space}")
|
||||
logger.info(f"\tmagneticfield: {magneticfield}")
|
||||
logger.info(f"\tresolution: {resolution}")
|
||||
|
||||
# check validity of parameters
|
||||
_valid_scales = [1, 2, 3, 4]
|
||||
if scale not in _valid_scales:
|
||||
|
|
@ -714,6 +715,7 @@ def _retrieve_suit(
|
|||
|
||||
"""
|
||||
logger.info("Parcellation parameters:")
|
||||
logger.info(f"\tresolution: {resolution}")
|
||||
logger.info(f"\tspace: {space}")
|
||||
|
||||
_valid_spaces = ["MNI", "SUIT"]
|
||||
|
|
@ -825,6 +827,7 @@ def _retrieve_aicha(
|
|||
"""
|
||||
# show parameters to user
|
||||
logger.info("Parcellation parameters:")
|
||||
logger.info(f"\tresolution: {resolution}")
|
||||
logger.info(f"\tversion: {version}")
|
||||
|
||||
# Check version value
|
||||
|
|
@ -963,6 +966,7 @@ def _retrieve_shen( # noqa: C901
|
|||
"""
|
||||
# show parameters to user
|
||||
logger.info("Parcellation parameters:")
|
||||
logger.info(f"\tresolution: {resolution}")
|
||||
logger.info(f"\tyear: {year}")
|
||||
logger.info(f"\tn_rois: {n_rois}")
|
||||
|
||||
|
|
|
|||
|
|
@ -207,88 +207,95 @@ def test_retrieve_parcellation_incorrect() -> None:
|
|||
_retrieve_parcellation("wrongparcellation")
|
||||
|
||||
|
||||
# TODO: paramdtrize test
|
||||
def test_schaefer_parcellation(tmp_path: Path) -> None:
|
||||
@pytest.mark.parametrize(
|
||||
"resolution, n_rois, yeo_networks",
|
||||
[
|
||||
(1.0, 100, 7),
|
||||
(1.0, 200, 7),
|
||||
(1.0, 300, 7),
|
||||
(1.0, 400, 7),
|
||||
(1.0, 500, 7),
|
||||
(1.0, 600, 7),
|
||||
(1.0, 700, 7),
|
||||
(1.0, 800, 7),
|
||||
(1.0, 900, 7),
|
||||
(1.0, 1000, 7),
|
||||
(2.0, 100, 7),
|
||||
(2.0, 200, 7),
|
||||
(2.0, 300, 7),
|
||||
(2.0, 400, 7),
|
||||
(2.0, 500, 7),
|
||||
(2.0, 600, 7),
|
||||
(2.0, 700, 7),
|
||||
(2.0, 800, 7),
|
||||
(2.0, 900, 7),
|
||||
(2.0, 1000, 7),
|
||||
(1.0, 100, 17),
|
||||
(1.0, 200, 17),
|
||||
(1.0, 300, 17),
|
||||
(1.0, 400, 17),
|
||||
(1.0, 500, 17),
|
||||
(1.0, 600, 17),
|
||||
(1.0, 700, 17),
|
||||
(1.0, 800, 17),
|
||||
(1.0, 900, 17),
|
||||
(1.0, 1000, 17),
|
||||
(2.0, 100, 17),
|
||||
(2.0, 200, 17),
|
||||
(2.0, 300, 17),
|
||||
(2.0, 400, 17),
|
||||
(2.0, 500, 17),
|
||||
(2.0, 600, 17),
|
||||
(2.0, 700, 17),
|
||||
(2.0, 800, 17),
|
||||
(2.0, 900, 17),
|
||||
(2.0, 1000, 17),
|
||||
],
|
||||
)
|
||||
def test_schaefer(
|
||||
tmp_path: Path,
|
||||
resolution: float,
|
||||
n_rois: int,
|
||||
yeo_networks: int,
|
||||
) -> None:
|
||||
"""Test Schaefer parcellation.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
tmp_path : pathlib.Path
|
||||
The path to the test directory.
|
||||
resolution : float
|
||||
The parametrized resolution values.
|
||||
n_rois : int
|
||||
The parametrized ROI count values.
|
||||
yeo_networks : int
|
||||
The parametrized Yeo networks values.
|
||||
|
||||
"""
|
||||
parcellations = list_parcellations()
|
||||
for n_rois in range(100, 1001, 100):
|
||||
for t_net in [7, 17]:
|
||||
t_name = f"Schaefer{n_rois}x{t_net}"
|
||||
assert t_name in parcellations
|
||||
parcellation_name = f"Schaefer{n_rois}x{yeo_networks}"
|
||||
assert parcellation_name in parcellations
|
||||
|
||||
# Define parcellation file names
|
||||
fname1 = "Schaefer2018_100Parcels_7Networks_order_FSLMNI152_1mm.nii.gz"
|
||||
fname2 = "Schaefer2018_100Parcels_7Networks_order_FSLMNI152_2mm.nii.gz"
|
||||
|
||||
# Load parcellation
|
||||
img, lbl, fname = load_parcellation(
|
||||
name="Schaefer100x7", parcellations_dir=str(tmp_path.absolute())
|
||||
parcellation_file = (
|
||||
f"Schaefer2018_{n_rois}Parcels_{yeo_networks}Networks_order_FSLMNI152_"
|
||||
f"{int(resolution)}mm.nii.gz"
|
||||
)
|
||||
# Load parcellation
|
||||
img, label, img_path = load_parcellation(
|
||||
name=parcellation_name,
|
||||
parcellations_dir=tmp_path,
|
||||
resolution=resolution,
|
||||
)
|
||||
# Check parcellation values
|
||||
assert img is not None
|
||||
assert fname.name == fname1
|
||||
assert len(lbl) == 100
|
||||
assert_array_equal(img.header["pixdim"][1:4], [1, 1, 1]) # type: ignore
|
||||
|
||||
# Test with Path
|
||||
img, lbl, fname = load_parcellation(
|
||||
name="Schaefer100x7", parcellations_dir=tmp_path
|
||||
assert img_path.name == parcellation_file
|
||||
assert len(label) == n_rois
|
||||
assert_array_equal(
|
||||
img.header["pixdim"][1:4], 3 * [resolution] # type: ignore
|
||||
)
|
||||
# Load parcellation
|
||||
img2, lbl, fname = load_parcellation(
|
||||
name="Schaefer100x7", parcellations_dir=tmp_path, resolution=3
|
||||
)
|
||||
# Check parcellation values
|
||||
assert fname.name == fname2
|
||||
assert len(lbl) == 100
|
||||
assert img2 is not None
|
||||
assert_array_equal(img2.header["pixdim"][1:4], [2, 2, 2]) # type: ignore
|
||||
# Load parcellation
|
||||
img2, lbl, fname = load_parcellation(
|
||||
"Schaefer100x7", parcellations_dir=tmp_path, resolution=2.1
|
||||
)
|
||||
# Check parcellation values
|
||||
assert fname.name == fname2
|
||||
assert len(lbl) == 100
|
||||
assert img2 is not None
|
||||
assert_array_equal(img2.header["pixdim"][1:4], [2, 2, 2]) # type: ignore
|
||||
# Load parcellation
|
||||
img2, lbl, fname = load_parcellation(
|
||||
"Schaefer100x7", parcellations_dir=tmp_path, resolution=1.99
|
||||
)
|
||||
# Check parcellation values
|
||||
assert fname.name == fname1
|
||||
assert len(lbl) == 100
|
||||
assert img2 is not None
|
||||
assert_array_equal(img2.header["pixdim"][1:4], [1, 1, 1]) # type: ignore
|
||||
# Load parcellation
|
||||
img2, lbl, fname = load_parcellation(
|
||||
"Schaefer100x7", parcellations_dir=tmp_path, resolution=0.5
|
||||
)
|
||||
# Check parcellation values
|
||||
assert fname.name == fname1
|
||||
assert len(lbl) == 100
|
||||
assert img2 is not None
|
||||
assert_array_equal(img2.header["pixdim"][1:4], [1, 1, 1]) # type: ignore
|
||||
|
||||
|
||||
def test_load_parcellation_schaefer() -> None:
|
||||
"""Test Schaefer parcellation loading."""
|
||||
img, lbl, fname = load_parcellation(name="Schaefer100x7")
|
||||
assert img is not None
|
||||
home_dir = Path().home() / "junifer" / "data" / "parcellations"
|
||||
assert home_dir in fname.parents
|
||||
|
||||
|
||||
def test_retrieve_schaefer_incorrect_n_rois(tmp_path: Path) -> None:
|
||||
"""Test retrieve schaefer with incorrect n_rois.
|
||||
"""Test retrieve Schaefer with incorrect ROIs.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
|
|
@ -306,7 +313,7 @@ def test_retrieve_schaefer_incorrect_n_rois(tmp_path: Path) -> None:
|
|||
|
||||
|
||||
def test_retrieve_schaefer_incorrect_yeo_networks(tmp_path: Path) -> None:
|
||||
"""Test retrieve schaefer with incorrect yeo_networks.
|
||||
"""Test retrieve Schaefer with incorrect Yeo networks.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
|
|
@ -323,53 +330,36 @@ def test_retrieve_schaefer_incorrect_yeo_networks(tmp_path: Path) -> None:
|
|||
)
|
||||
|
||||
|
||||
# TODO: parametrize test
|
||||
def test_suit(tmp_path: Path) -> None:
|
||||
@pytest.mark.parametrize(
|
||||
"space",
|
||||
["SUIT", "MNI"],
|
||||
)
|
||||
def test_suit(tmp_path: Path, space: str) -> None:
|
||||
"""Test SUIT parcellation.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
tmp_path : pathlib.Path
|
||||
The path to the test directory.
|
||||
space : str
|
||||
The parametrized space values.
|
||||
|
||||
"""
|
||||
parcellations = list_parcellations()
|
||||
assert "SUITxSUIT" in parcellations
|
||||
assert "SUITxMNI" in parcellations
|
||||
|
||||
assert f"SUITx{space}" in parcellations
|
||||
# Load parcellation
|
||||
img, lbl, fname = load_parcellation(
|
||||
name="SUITxSUIT", parcellations_dir=tmp_path
|
||||
img, label, img_path = load_parcellation(
|
||||
name=f"SUITx{space}",
|
||||
parcellations_dir=tmp_path,
|
||||
)
|
||||
fname1 = "SUIT_SUITSpace_1mm.nii"
|
||||
assert img is not None
|
||||
assert fname.name == fname1
|
||||
assert len(lbl) == 34
|
||||
assert_array_equal(img.header["pixdim"][1:4], [1, 1, 1]) # type: ignore
|
||||
|
||||
# Load parcellation
|
||||
img, lbl, fname = load_parcellation(
|
||||
name="SUITxSUIT", parcellations_dir=tmp_path
|
||||
)
|
||||
fname1 = "SUIT_SUITSpace_1mm.nii"
|
||||
assert img is not None
|
||||
assert fname.name == fname1
|
||||
assert len(lbl) == 34
|
||||
assert_array_equal(img.header["pixdim"][1:4], [1, 1, 1]) # type: ignore
|
||||
|
||||
# Load parcellation
|
||||
img, lbl, fname = load_parcellation(
|
||||
name="SUITxMNI", parcellations_dir=tmp_path
|
||||
)
|
||||
fname1 = "SUIT_MNISpace_1mm.nii"
|
||||
assert img is not None
|
||||
assert fname.name == fname1
|
||||
assert len(lbl) == 34
|
||||
assert img_path.name == f"SUIT_{space}Space_1mm.nii"
|
||||
assert len(label) == 34
|
||||
assert_array_equal(img.header["pixdim"][1:4], [1, 1, 1]) # type: ignore
|
||||
|
||||
|
||||
def test_retrieve_suit_incorrect_space(tmp_path: Path) -> None:
|
||||
"""Test retrieve suit with incorrect space.
|
||||
"""Test retrieve SUIT with incorrect space.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
|
|
@ -378,7 +368,9 @@ def test_retrieve_suit_incorrect_space(tmp_path: Path) -> None:
|
|||
|
||||
"""
|
||||
with pytest.raises(ValueError, match=r"The parameter `space`"):
|
||||
_retrieve_suit(parcellations_dir=tmp_path, resolution=1, space="wrong")
|
||||
_retrieve_suit(
|
||||
parcellations_dir=tmp_path, resolution=1.0, space="wrong"
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
|
@ -641,7 +633,9 @@ def test_shen(
|
|||
assert f"Shen_{year}_{n_rois}" in parcellations
|
||||
# Load parcellation
|
||||
img, label, img_path = load_parcellation(
|
||||
name=f"Shen_{year}_{n_rois}", parcellations_dir=tmp_path
|
||||
name=f"Shen_{year}_{n_rois}",
|
||||
parcellations_dir=tmp_path,
|
||||
resolution=resolution,
|
||||
)
|
||||
assert img is not None
|
||||
assert img_name in img_path.name
|
||||
|
|
|
|||
Loading…
Reference in a new issue