junifer 0.0.5.dev240__py3-none-any.whl → 0.0.6__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- junifer/__init__.py +2 -31
- junifer/__init__.pyi +37 -0
- junifer/_version.py +9 -4
- junifer/api/__init__.py +3 -5
- junifer/api/__init__.pyi +4 -0
- junifer/api/decorators.py +14 -19
- junifer/api/functions.py +165 -109
- junifer/api/py.typed +0 -0
- junifer/api/queue_context/__init__.py +2 -4
- junifer/api/queue_context/__init__.pyi +5 -0
- junifer/api/queue_context/gnu_parallel_local_adapter.py +22 -6
- junifer/api/queue_context/htcondor_adapter.py +23 -6
- junifer/api/queue_context/py.typed +0 -0
- junifer/api/queue_context/tests/test_gnu_parallel_local_adapter.py +3 -3
- junifer/api/queue_context/tests/test_htcondor_adapter.py +3 -3
- junifer/api/tests/test_functions.py +168 -74
- junifer/cli/__init__.py +24 -0
- junifer/cli/__init__.pyi +3 -0
- junifer/{api → cli}/cli.py +141 -125
- junifer/cli/parser.py +235 -0
- junifer/cli/py.typed +0 -0
- junifer/{api → cli}/tests/test_cli.py +8 -8
- junifer/{api/tests/test_api_utils.py → cli/tests/test_cli_utils.py} +5 -4
- junifer/{api → cli}/tests/test_parser.py +2 -2
- junifer/{api → cli}/utils.py +6 -16
- junifer/configs/juseless/__init__.py +2 -2
- junifer/configs/juseless/__init__.pyi +3 -0
- junifer/configs/juseless/datagrabbers/__init__.py +2 -12
- junifer/configs/juseless/datagrabbers/__init__.pyi +13 -0
- junifer/configs/juseless/datagrabbers/ixi_vbm.py +2 -2
- junifer/configs/juseless/datagrabbers/py.typed +0 -0
- junifer/configs/juseless/datagrabbers/tests/test_ucla.py +2 -2
- junifer/configs/juseless/datagrabbers/ucla.py +4 -4
- junifer/configs/juseless/py.typed +0 -0
- junifer/conftest.py +25 -0
- junifer/data/__init__.py +2 -42
- junifer/data/__init__.pyi +29 -0
- junifer/data/_dispatch.py +248 -0
- junifer/data/coordinates/__init__.py +9 -0
- junifer/data/coordinates/__init__.pyi +5 -0
- junifer/data/coordinates/_ants_coordinates_warper.py +104 -0
- junifer/data/coordinates/_coordinates.py +385 -0
- junifer/data/coordinates/_fsl_coordinates_warper.py +81 -0
- junifer/data/{tests → coordinates/tests}/test_coordinates.py +26 -33
- junifer/data/masks/__init__.py +9 -0
- junifer/data/masks/__init__.pyi +6 -0
- junifer/data/masks/_ants_mask_warper.py +177 -0
- junifer/data/masks/_fsl_mask_warper.py +106 -0
- junifer/data/masks/_masks.py +802 -0
- junifer/data/{tests → masks/tests}/test_masks.py +67 -63
- junifer/data/parcellations/__init__.py +9 -0
- junifer/data/parcellations/__init__.pyi +6 -0
- junifer/data/parcellations/_ants_parcellation_warper.py +166 -0
- junifer/data/parcellations/_fsl_parcellation_warper.py +89 -0
- junifer/data/parcellations/_parcellations.py +1388 -0
- junifer/data/{tests → parcellations/tests}/test_parcellations.py +165 -295
- junifer/data/pipeline_data_registry_base.py +76 -0
- junifer/data/py.typed +0 -0
- junifer/data/template_spaces.py +44 -79
- junifer/data/tests/test_data_utils.py +1 -2
- junifer/data/tests/test_template_spaces.py +8 -4
- junifer/data/utils.py +109 -4
- junifer/datagrabber/__init__.py +2 -26
- junifer/datagrabber/__init__.pyi +27 -0
- junifer/datagrabber/aomic/__init__.py +2 -4
- junifer/datagrabber/aomic/__init__.pyi +5 -0
- junifer/datagrabber/aomic/id1000.py +81 -52
- junifer/datagrabber/aomic/piop1.py +83 -55
- junifer/datagrabber/aomic/piop2.py +85 -56
- junifer/datagrabber/aomic/py.typed +0 -0
- junifer/datagrabber/aomic/tests/test_id1000.py +19 -12
- junifer/datagrabber/aomic/tests/test_piop1.py +52 -18
- junifer/datagrabber/aomic/tests/test_piop2.py +50 -17
- junifer/datagrabber/base.py +22 -18
- junifer/datagrabber/datalad_base.py +71 -34
- junifer/datagrabber/dmcc13_benchmark.py +31 -18
- junifer/datagrabber/hcp1200/__init__.py +2 -3
- junifer/datagrabber/hcp1200/__init__.pyi +4 -0
- junifer/datagrabber/hcp1200/datalad_hcp1200.py +3 -3
- junifer/datagrabber/hcp1200/hcp1200.py +26 -15
- junifer/datagrabber/hcp1200/py.typed +0 -0
- junifer/datagrabber/hcp1200/tests/test_hcp1200.py +8 -2
- junifer/datagrabber/multiple.py +14 -9
- junifer/datagrabber/pattern.py +132 -96
- junifer/datagrabber/pattern_validation_mixin.py +206 -94
- junifer/datagrabber/py.typed +0 -0
- junifer/datagrabber/tests/test_datalad_base.py +27 -12
- junifer/datagrabber/tests/test_dmcc13_benchmark.py +28 -11
- junifer/datagrabber/tests/test_multiple.py +48 -2
- junifer/datagrabber/tests/test_pattern_datalad.py +1 -1
- junifer/datagrabber/tests/test_pattern_validation_mixin.py +6 -6
- junifer/datareader/__init__.py +2 -2
- junifer/datareader/__init__.pyi +3 -0
- junifer/datareader/default.py +6 -6
- junifer/datareader/py.typed +0 -0
- junifer/external/nilearn/__init__.py +2 -3
- junifer/external/nilearn/__init__.pyi +4 -0
- junifer/external/nilearn/junifer_connectivity_measure.py +25 -17
- junifer/external/nilearn/junifer_nifti_spheres_masker.py +4 -4
- junifer/external/nilearn/py.typed +0 -0
- junifer/external/nilearn/tests/test_junifer_connectivity_measure.py +17 -16
- junifer/external/nilearn/tests/test_junifer_nifti_spheres_masker.py +2 -3
- junifer/markers/__init__.py +2 -38
- junifer/markers/__init__.pyi +37 -0
- junifer/markers/base.py +11 -14
- junifer/markers/brainprint.py +12 -14
- junifer/markers/complexity/__init__.py +2 -18
- junifer/markers/complexity/__init__.pyi +17 -0
- junifer/markers/complexity/complexity_base.py +9 -11
- junifer/markers/complexity/hurst_exponent.py +7 -7
- junifer/markers/complexity/multiscale_entropy_auc.py +7 -7
- junifer/markers/complexity/perm_entropy.py +7 -7
- junifer/markers/complexity/py.typed +0 -0
- junifer/markers/complexity/range_entropy.py +7 -7
- junifer/markers/complexity/range_entropy_auc.py +7 -7
- junifer/markers/complexity/sample_entropy.py +7 -7
- junifer/markers/complexity/tests/test_complexity_base.py +1 -1
- junifer/markers/complexity/tests/test_hurst_exponent.py +5 -5
- junifer/markers/complexity/tests/test_multiscale_entropy_auc.py +5 -5
- junifer/markers/complexity/tests/test_perm_entropy.py +5 -5
- junifer/markers/complexity/tests/test_range_entropy.py +5 -5
- junifer/markers/complexity/tests/test_range_entropy_auc.py +5 -5
- junifer/markers/complexity/tests/test_sample_entropy.py +5 -5
- junifer/markers/complexity/tests/test_weighted_perm_entropy.py +5 -5
- junifer/markers/complexity/weighted_perm_entropy.py +7 -7
- junifer/markers/ets_rss.py +12 -11
- junifer/markers/falff/__init__.py +2 -3
- junifer/markers/falff/__init__.pyi +4 -0
- junifer/markers/falff/_afni_falff.py +38 -45
- junifer/markers/falff/_junifer_falff.py +16 -19
- junifer/markers/falff/falff_base.py +7 -11
- junifer/markers/falff/falff_parcels.py +9 -9
- junifer/markers/falff/falff_spheres.py +8 -8
- junifer/markers/falff/py.typed +0 -0
- junifer/markers/falff/tests/test_falff_spheres.py +3 -1
- junifer/markers/functional_connectivity/__init__.py +2 -12
- junifer/markers/functional_connectivity/__init__.pyi +13 -0
- junifer/markers/functional_connectivity/crossparcellation_functional_connectivity.py +9 -8
- junifer/markers/functional_connectivity/edge_functional_connectivity_parcels.py +8 -8
- junifer/markers/functional_connectivity/edge_functional_connectivity_spheres.py +7 -7
- junifer/markers/functional_connectivity/functional_connectivity_base.py +13 -12
- junifer/markers/functional_connectivity/functional_connectivity_parcels.py +8 -8
- junifer/markers/functional_connectivity/functional_connectivity_spheres.py +7 -7
- junifer/markers/functional_connectivity/py.typed +0 -0
- junifer/markers/functional_connectivity/tests/test_edge_functional_connectivity_parcels.py +1 -2
- junifer/markers/functional_connectivity/tests/test_edge_functional_connectivity_spheres.py +1 -2
- junifer/markers/functional_connectivity/tests/test_functional_connectivity_parcels.py +6 -6
- junifer/markers/functional_connectivity/tests/test_functional_connectivity_spheres.py +5 -5
- junifer/markers/parcel_aggregation.py +22 -17
- junifer/markers/py.typed +0 -0
- junifer/markers/reho/__init__.py +2 -3
- junifer/markers/reho/__init__.pyi +4 -0
- junifer/markers/reho/_afni_reho.py +29 -35
- junifer/markers/reho/_junifer_reho.py +13 -14
- junifer/markers/reho/py.typed +0 -0
- junifer/markers/reho/reho_base.py +7 -11
- junifer/markers/reho/reho_parcels.py +10 -10
- junifer/markers/reho/reho_spheres.py +9 -9
- junifer/markers/sphere_aggregation.py +22 -17
- junifer/markers/temporal_snr/__init__.py +2 -3
- junifer/markers/temporal_snr/__init__.pyi +4 -0
- junifer/markers/temporal_snr/py.typed +0 -0
- junifer/markers/temporal_snr/temporal_snr_base.py +11 -10
- junifer/markers/temporal_snr/temporal_snr_parcels.py +8 -8
- junifer/markers/temporal_snr/temporal_snr_spheres.py +7 -7
- junifer/markers/tests/test_ets_rss.py +3 -3
- junifer/markers/tests/test_parcel_aggregation.py +24 -24
- junifer/markers/tests/test_sphere_aggregation.py +6 -6
- junifer/markers/utils.py +3 -3
- junifer/onthefly/__init__.py +2 -1
- junifer/onthefly/_brainprint.py +138 -0
- junifer/onthefly/read_transform.py +5 -8
- junifer/pipeline/__init__.py +2 -10
- junifer/pipeline/__init__.pyi +13 -0
- junifer/{markers/collection.py → pipeline/marker_collection.py} +8 -14
- junifer/pipeline/pipeline_component_registry.py +294 -0
- junifer/pipeline/pipeline_step_mixin.py +15 -11
- junifer/pipeline/py.typed +0 -0
- junifer/{markers/tests/test_collection.py → pipeline/tests/test_marker_collection.py} +2 -3
- junifer/pipeline/tests/test_pipeline_component_registry.py +200 -0
- junifer/pipeline/tests/test_pipeline_step_mixin.py +36 -37
- junifer/pipeline/tests/test_update_meta_mixin.py +4 -4
- junifer/pipeline/tests/test_workdir_manager.py +43 -0
- junifer/pipeline/update_meta_mixin.py +21 -17
- junifer/pipeline/utils.py +6 -6
- junifer/pipeline/workdir_manager.py +19 -5
- junifer/preprocess/__init__.py +2 -10
- junifer/preprocess/__init__.pyi +11 -0
- junifer/preprocess/base.py +10 -10
- junifer/preprocess/confounds/__init__.py +2 -2
- junifer/preprocess/confounds/__init__.pyi +3 -0
- junifer/preprocess/confounds/fmriprep_confound_remover.py +243 -64
- junifer/preprocess/confounds/py.typed +0 -0
- junifer/preprocess/confounds/tests/test_fmriprep_confound_remover.py +121 -14
- junifer/preprocess/py.typed +0 -0
- junifer/preprocess/smoothing/__init__.py +2 -2
- junifer/preprocess/smoothing/__init__.pyi +3 -0
- junifer/preprocess/smoothing/_afni_smoothing.py +40 -40
- junifer/preprocess/smoothing/_fsl_smoothing.py +22 -32
- junifer/preprocess/smoothing/_nilearn_smoothing.py +35 -14
- junifer/preprocess/smoothing/py.typed +0 -0
- junifer/preprocess/smoothing/smoothing.py +11 -13
- junifer/preprocess/warping/__init__.py +2 -2
- junifer/preprocess/warping/__init__.pyi +3 -0
- junifer/preprocess/warping/_ants_warper.py +136 -32
- junifer/preprocess/warping/_fsl_warper.py +73 -22
- junifer/preprocess/warping/py.typed +0 -0
- junifer/preprocess/warping/space_warper.py +39 -11
- junifer/preprocess/warping/tests/test_space_warper.py +5 -9
- junifer/py.typed +0 -0
- junifer/stats.py +5 -5
- junifer/storage/__init__.py +2 -10
- junifer/storage/__init__.pyi +11 -0
- junifer/storage/base.py +47 -13
- junifer/storage/hdf5.py +95 -33
- junifer/storage/pandas_base.py +12 -11
- junifer/storage/py.typed +0 -0
- junifer/storage/sqlite.py +11 -11
- junifer/storage/tests/test_hdf5.py +86 -4
- junifer/storage/tests/test_sqlite.py +2 -2
- junifer/storage/tests/test_storage_base.py +5 -2
- junifer/storage/tests/test_utils.py +33 -7
- junifer/storage/utils.py +95 -9
- junifer/testing/__init__.py +2 -3
- junifer/testing/__init__.pyi +4 -0
- junifer/testing/datagrabbers.py +10 -11
- junifer/testing/py.typed +0 -0
- junifer/testing/registry.py +4 -7
- junifer/testing/tests/test_testing_registry.py +9 -17
- junifer/tests/test_stats.py +2 -2
- junifer/typing/__init__.py +9 -0
- junifer/typing/__init__.pyi +31 -0
- junifer/typing/_typing.py +68 -0
- junifer/utils/__init__.py +2 -12
- junifer/utils/__init__.pyi +18 -0
- junifer/utils/_config.py +110 -0
- junifer/utils/_yaml.py +16 -0
- junifer/utils/helpers.py +6 -6
- junifer/utils/logging.py +117 -8
- junifer/utils/py.typed +0 -0
- junifer/{pipeline → utils}/singleton.py +19 -14
- junifer/utils/tests/test_config.py +59 -0
- {junifer-0.0.5.dev240.dist-info → junifer-0.0.6.dist-info}/METADATA +43 -38
- junifer-0.0.6.dist-info/RECORD +350 -0
- {junifer-0.0.5.dev240.dist-info → junifer-0.0.6.dist-info}/WHEEL +1 -1
- junifer-0.0.6.dist-info/entry_points.txt +2 -0
- junifer/api/parser.py +0 -118
- junifer/data/coordinates.py +0 -408
- junifer/data/masks.py +0 -670
- junifer/data/parcellations.py +0 -1828
- junifer/pipeline/registry.py +0 -177
- junifer/pipeline/tests/test_registry.py +0 -150
- junifer-0.0.5.dev240.dist-info/RECORD +0 -275
- junifer-0.0.5.dev240.dist-info/entry_points.txt +0 -2
- /junifer/{api → cli}/tests/data/gmd_mean.yaml +0 -0
- /junifer/{api → cli}/tests/data/gmd_mean_htcondor.yaml +0 -0
- /junifer/{api → cli}/tests/data/partly_cloudy_agg_mean_tian.yml +0 -0
- /junifer/data/{VOIs → coordinates/VOIs}/meta/AutobiographicalMemory_VOIs.txt +0 -0
- /junifer/data/{VOIs → coordinates/VOIs}/meta/CogAC_VOIs.txt +0 -0
- /junifer/data/{VOIs → coordinates/VOIs}/meta/CogAR_VOIs.txt +0 -0
- /junifer/data/{VOIs → coordinates/VOIs}/meta/DMNBuckner_VOIs.txt +0 -0
- /junifer/data/{VOIs → coordinates/VOIs}/meta/Dosenbach2010_MNI_VOIs.txt +0 -0
- /junifer/data/{VOIs → coordinates/VOIs}/meta/Empathy_VOIs.txt +0 -0
- /junifer/data/{VOIs → coordinates/VOIs}/meta/Motor_VOIs.txt +0 -0
- /junifer/data/{VOIs → coordinates/VOIs}/meta/MultiTask_VOIs.txt +0 -0
- /junifer/data/{VOIs → coordinates/VOIs}/meta/PhysioStress_VOIs.txt +0 -0
- /junifer/data/{VOIs → coordinates/VOIs}/meta/Power2011_MNI_VOIs.txt +0 -0
- /junifer/data/{VOIs → coordinates/VOIs}/meta/Power2013_MNI_VOIs.tsv +0 -0
- /junifer/data/{VOIs → coordinates/VOIs}/meta/Rew_VOIs.txt +0 -0
- /junifer/data/{VOIs → coordinates/VOIs}/meta/Somatosensory_VOIs.txt +0 -0
- /junifer/data/{VOIs → coordinates/VOIs}/meta/ToM_VOIs.txt +0 -0
- /junifer/data/{VOIs → coordinates/VOIs}/meta/VigAtt_VOIs.txt +0 -0
- /junifer/data/{VOIs → coordinates/VOIs}/meta/WM_VOIs.txt +0 -0
- /junifer/data/{VOIs → coordinates/VOIs}/meta/eMDN_VOIs.txt +0 -0
- /junifer/data/{VOIs → coordinates/VOIs}/meta/eSAD_VOIs.txt +0 -0
- /junifer/data/{VOIs → coordinates/VOIs}/meta/extDMN_VOIs.txt +0 -0
- {junifer-0.0.5.dev240.dist-info → junifer-0.0.6.dist-info/licenses}/AUTHORS.rst +0 -0
- {junifer-0.0.5.dev240.dist-info → junifer-0.0.6.dist-info/licenses}/LICENSE.md +0 -0
- {junifer-0.0.5.dev240.dist-info → junifer-0.0.6.dist-info}/top_level.txt +0 -0
@@ -6,7 +6,6 @@
|
|
6
6
|
# License: AGPL
|
7
7
|
|
8
8
|
from pathlib import Path
|
9
|
-
from typing import List
|
10
9
|
|
11
10
|
import nibabel as nib
|
12
11
|
import numpy as np
|
@@ -14,20 +13,16 @@ import pytest
|
|
14
13
|
from nilearn.image import new_img_like, resample_to_img
|
15
14
|
from numpy.testing import assert_array_almost_equal, assert_array_equal
|
16
15
|
|
17
|
-
from junifer.data
|
16
|
+
from junifer.data import ParcellationRegistry
|
17
|
+
from junifer.data.parcellations import merge_parcellations
|
18
|
+
from junifer.data.parcellations._parcellations import (
|
18
19
|
_retrieve_aicha,
|
19
20
|
_retrieve_brainnetome,
|
20
|
-
_retrieve_parcellation,
|
21
21
|
_retrieve_schaefer,
|
22
22
|
_retrieve_shen,
|
23
23
|
_retrieve_suit,
|
24
24
|
_retrieve_tian,
|
25
25
|
_retrieve_yan,
|
26
|
-
get_parcellation,
|
27
|
-
list_parcellations,
|
28
|
-
load_parcellation,
|
29
|
-
merge_parcellations,
|
30
|
-
register_parcellation,
|
31
26
|
)
|
32
27
|
from junifer.datareader import DefaultDataReader
|
33
28
|
from junifer.pipeline.utils import _check_ants
|
@@ -37,10 +32,10 @@ from junifer.testing.datagrabbers import (
|
|
37
32
|
)
|
38
33
|
|
39
34
|
|
40
|
-
def
|
35
|
+
def test_register_built_in_check() -> None:
|
41
36
|
"""Test parcellation registration check for built-in parcellations."""
|
42
37
|
with pytest.raises(ValueError, match=r"built-in parcellation"):
|
43
|
-
|
38
|
+
ParcellationRegistry().register(
|
44
39
|
name="SUITxSUIT",
|
45
40
|
parcellation_path="testparc.nii.gz",
|
46
41
|
parcels_labels=["1", "2", "3"],
|
@@ -49,35 +44,36 @@ def test_register_parcellation_built_in_check() -> None:
|
|
49
44
|
)
|
50
45
|
|
51
46
|
|
52
|
-
def
|
47
|
+
def test_list_incorrect() -> None:
|
53
48
|
"""Test incorrect information check for list parcellations."""
|
54
|
-
|
55
|
-
assert "testparc" not in parcellations
|
49
|
+
assert "testparc" not in ParcellationRegistry().list
|
56
50
|
|
57
51
|
|
58
|
-
def
|
52
|
+
def test_register_already_registered() -> None:
|
59
53
|
"""Test parcellation registration check for already registered."""
|
60
54
|
# Register custom parcellation
|
61
|
-
|
55
|
+
ParcellationRegistry().register(
|
62
56
|
name="testparc",
|
63
57
|
parcellation_path="testparc.nii.gz",
|
64
58
|
parcels_labels=["1", "2", "3"],
|
65
59
|
space="MNI152Lin",
|
66
60
|
)
|
67
61
|
assert (
|
68
|
-
|
62
|
+
ParcellationRegistry()
|
63
|
+
.load("testparc", target_space="MNI152Lin", path_only=True)[2]
|
64
|
+
.name
|
69
65
|
== "testparc.nii.gz"
|
70
66
|
)
|
71
67
|
|
72
68
|
# Try registering again
|
73
69
|
with pytest.raises(ValueError, match=r"already registered."):
|
74
|
-
|
70
|
+
ParcellationRegistry().register(
|
75
71
|
name="testparc",
|
76
72
|
parcellation_path="testparc.nii.gz",
|
77
73
|
parcels_labels=["1", "2", "3"],
|
78
74
|
space="MNI152Lin",
|
79
75
|
)
|
80
|
-
|
76
|
+
ParcellationRegistry().register(
|
81
77
|
name="testparc",
|
82
78
|
parcellation_path="testparc2.nii.gz",
|
83
79
|
parcels_labels=["1", "2", "3"],
|
@@ -86,7 +82,9 @@ def test_register_parcellation_already_registered() -> None:
|
|
86
82
|
)
|
87
83
|
|
88
84
|
assert (
|
89
|
-
|
85
|
+
ParcellationRegistry()
|
86
|
+
.load("testparc", target_space="MNI152Lin", path_only=True)[2]
|
87
|
+
.name
|
90
88
|
== "testparc2.nii.gz"
|
91
89
|
)
|
92
90
|
|
@@ -100,24 +98,27 @@ def test_parcellation_wrong_labels_values(tmp_path: Path) -> None:
|
|
100
98
|
The path to the test directory.
|
101
99
|
|
102
100
|
"""
|
103
|
-
schaefer, labels, schaefer_path, _ =
|
101
|
+
schaefer, labels, schaefer_path, _ = ParcellationRegistry().load(
|
102
|
+
"Schaefer100x7",
|
103
|
+
"MNI152NLin6Asym",
|
104
|
+
)
|
104
105
|
assert schaefer is not None
|
105
106
|
|
106
107
|
# Test wrong number of labels
|
107
|
-
|
108
|
+
ParcellationRegistry().register(
|
108
109
|
"WrongLabels", schaefer_path, labels[:10], "MNI152Lin"
|
109
110
|
)
|
110
111
|
|
111
112
|
with pytest.raises(ValueError, match=r"has 100 parcels but 10"):
|
112
|
-
|
113
|
+
ParcellationRegistry().load("WrongLabels", "MNI152NLin6Asym")
|
113
114
|
|
114
115
|
# Test wrong number of labels
|
115
|
-
|
116
|
+
ParcellationRegistry().register(
|
116
117
|
"WrongLabels2", schaefer_path, [*labels, "wrong"], "MNI152Lin"
|
117
118
|
)
|
118
119
|
|
119
120
|
with pytest.raises(ValueError, match=r"has 100 parcels but 101"):
|
120
|
-
|
121
|
+
ParcellationRegistry().load("WrongLabels2", "MNI152NLin6Asym")
|
121
122
|
|
122
123
|
schaefer_data = schaefer.get_fdata().copy()
|
123
124
|
schaefer_data[schaefer_data == 50] = 0
|
@@ -125,11 +126,11 @@ def test_parcellation_wrong_labels_values(tmp_path: Path) -> None:
|
|
125
126
|
new_schaefer_img = new_img_like(schaefer, schaefer_data)
|
126
127
|
nib.save(new_schaefer_img, new_schaefer_path)
|
127
128
|
|
128
|
-
|
129
|
+
ParcellationRegistry().register(
|
129
130
|
"WrongValues", new_schaefer_path, labels[:-1], "MNI152Lin"
|
130
131
|
)
|
131
|
-
with pytest.raises(ValueError, match=r"the
|
132
|
-
|
132
|
+
with pytest.raises(ValueError, match=r"must have all the values in the"):
|
133
|
+
ParcellationRegistry().load("WrongValues", "MNI152NLin6Asym")
|
133
134
|
|
134
135
|
schaefer_data = schaefer.get_fdata().copy()
|
135
136
|
schaefer_data[schaefer_data == 50] = 200
|
@@ -137,11 +138,11 @@ def test_parcellation_wrong_labels_values(tmp_path: Path) -> None:
|
|
137
138
|
new_schaefer_img = new_img_like(schaefer, schaefer_data)
|
138
139
|
nib.save(new_schaefer_img, new_schaefer_path)
|
139
140
|
|
140
|
-
|
141
|
+
ParcellationRegistry().register(
|
141
142
|
"WrongValues2", new_schaefer_path, labels, "MNI152Lin"
|
142
143
|
)
|
143
|
-
with pytest.raises(ValueError, match=r"the
|
144
|
-
|
144
|
+
with pytest.raises(ValueError, match=r"must have all the values in the"):
|
145
|
+
ParcellationRegistry().load("WrongValues2", "MNI152NLin6Asym")
|
145
146
|
|
146
147
|
|
147
148
|
@pytest.mark.parametrize(
|
@@ -170,10 +171,10 @@ def test_parcellation_wrong_labels_values(tmp_path: Path) -> None:
|
|
170
171
|
),
|
171
172
|
],
|
172
173
|
)
|
173
|
-
def
|
174
|
+
def test_register(
|
174
175
|
name: str,
|
175
176
|
parcellation_path: str,
|
176
|
-
parcels_labels:
|
177
|
+
parcels_labels: list[str],
|
177
178
|
space: str,
|
178
179
|
overwrite: bool,
|
179
180
|
) -> None:
|
@@ -194,7 +195,7 @@ def test_register_parcellation(
|
|
194
195
|
|
195
196
|
"""
|
196
197
|
# Register custom parcellation
|
197
|
-
|
198
|
+
ParcellationRegistry().register(
|
198
199
|
name=name,
|
199
200
|
parcellation_path=parcellation_path,
|
200
201
|
parcels_labels=parcels_labels,
|
@@ -202,11 +203,10 @@ def test_register_parcellation(
|
|
202
203
|
overwrite=overwrite,
|
203
204
|
)
|
204
205
|
# List available parcellation and check registration
|
205
|
-
|
206
|
-
assert name in parcellations
|
206
|
+
assert name in ParcellationRegistry().list
|
207
207
|
# Load registered parcellation
|
208
|
-
_, lbl, fname, parcellation_space =
|
209
|
-
name=name, path_only=True
|
208
|
+
_, lbl, fname, parcellation_space = ParcellationRegistry().load(
|
209
|
+
name=name, target_space=space, path_only=True
|
210
210
|
)
|
211
211
|
# Check values for registered parcellation
|
212
212
|
assert lbl == parcels_labels
|
@@ -228,7 +228,7 @@ def test_register_parcellation(
|
|
228
228
|
"TianxS4x3TxMNInonlinear2009cAsym",
|
229
229
|
],
|
230
230
|
)
|
231
|
-
def
|
231
|
+
def test_list_correct(parcellation_name: str) -> None:
|
232
232
|
"""Test correct information check for list parcellations.
|
233
233
|
|
234
234
|
Parameters
|
@@ -237,20 +237,13 @@ def test_list_parcellations_correct(parcellation_name: str) -> None:
|
|
237
237
|
The parametrized parcellation name.
|
238
238
|
|
239
239
|
"""
|
240
|
-
|
241
|
-
assert parcellation_name in parcellations
|
240
|
+
assert parcellation_name in ParcellationRegistry().list
|
242
241
|
|
243
242
|
|
244
|
-
def
|
243
|
+
def test_load_incorrect() -> None:
|
245
244
|
"""Test loading of invalid parcellations."""
|
246
245
|
with pytest.raises(ValueError, match=r"not found"):
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
def test_retrieve_parcellation_incorrect() -> None:
|
251
|
-
"""Test retrieval of invalid parcellations."""
|
252
|
-
with pytest.raises(ValueError, match=r"provided parcellation name"):
|
253
|
-
_retrieve_parcellation("wrongparcellation")
|
246
|
+
ParcellationRegistry().load("wrongparcellation", "MNI152NLin6Asym")
|
254
247
|
|
255
248
|
|
256
249
|
@pytest.mark.parametrize(
|
@@ -299,7 +292,6 @@ def test_retrieve_parcellation_incorrect() -> None:
|
|
299
292
|
],
|
300
293
|
)
|
301
294
|
def test_schaefer(
|
302
|
-
tmp_path: Path,
|
303
295
|
resolution: float,
|
304
296
|
n_rois: int,
|
305
297
|
yeo_networks: int,
|
@@ -308,8 +300,6 @@ def test_schaefer(
|
|
308
300
|
|
309
301
|
Parameters
|
310
302
|
----------
|
311
|
-
tmp_path : pathlib.Path
|
312
|
-
The path to the test directory.
|
313
303
|
resolution : float
|
314
304
|
The parametrized resolution values.
|
315
305
|
n_rois : int
|
@@ -318,18 +308,17 @@ def test_schaefer(
|
|
318
308
|
The parametrized Yeo networks values.
|
319
309
|
|
320
310
|
"""
|
321
|
-
parcellations = list_parcellations()
|
322
311
|
parcellation_name = f"Schaefer{n_rois}x{yeo_networks}"
|
323
|
-
assert parcellation_name in
|
312
|
+
assert parcellation_name in ParcellationRegistry().list
|
324
313
|
|
325
314
|
parcellation_file = (
|
326
315
|
f"Schaefer2018_{n_rois}Parcels_{yeo_networks}Networks_order_FSLMNI152_"
|
327
316
|
f"{int(resolution)}mm.nii.gz"
|
328
317
|
)
|
329
318
|
# Load parcellation
|
330
|
-
img, label, img_path, space =
|
319
|
+
img, label, img_path, space = ParcellationRegistry().load(
|
331
320
|
name=parcellation_name,
|
332
|
-
|
321
|
+
target_space="MNI152NLin6Asym",
|
333
322
|
resolution=resolution,
|
334
323
|
)
|
335
324
|
assert img is not None
|
@@ -341,36 +330,20 @@ def test_schaefer(
|
|
341
330
|
)
|
342
331
|
|
343
332
|
|
344
|
-
def test_retrieve_schaefer_incorrect_n_rois(
|
345
|
-
"""Test retrieve Schaefer with incorrect ROIs.
|
346
|
-
|
347
|
-
Parameters
|
348
|
-
----------
|
349
|
-
tmp_path : pathlib.Path
|
350
|
-
The path to the test directory.
|
351
|
-
|
352
|
-
"""
|
333
|
+
def test_retrieve_schaefer_incorrect_n_rois() -> None:
|
334
|
+
"""Test retrieve Schaefer with incorrect ROIs."""
|
353
335
|
with pytest.raises(ValueError, match=r"The parameter `n_rois`"):
|
354
336
|
_retrieve_schaefer(
|
355
|
-
parcellations_dir=tmp_path,
|
356
337
|
resolution=1,
|
357
338
|
n_rois=101,
|
358
339
|
yeo_networks=7,
|
359
340
|
)
|
360
341
|
|
361
342
|
|
362
|
-
def test_retrieve_schaefer_incorrect_yeo_networks(
|
363
|
-
"""Test retrieve Schaefer with incorrect Yeo networks.
|
364
|
-
|
365
|
-
Parameters
|
366
|
-
----------
|
367
|
-
tmp_path : pathlib.Path
|
368
|
-
The path to the test directory.
|
369
|
-
|
370
|
-
"""
|
343
|
+
def test_retrieve_schaefer_incorrect_yeo_networks() -> None:
|
344
|
+
"""Test retrieve Schaefer with incorrect Yeo networks."""
|
371
345
|
with pytest.raises(ValueError, match=r"The parameter `yeo_networks`"):
|
372
346
|
_retrieve_schaefer(
|
373
|
-
parcellations_dir=tmp_path,
|
374
347
|
resolution=1,
|
375
348
|
n_rois=100,
|
376
349
|
yeo_networks=8,
|
@@ -381,25 +354,22 @@ def test_retrieve_schaefer_incorrect_yeo_networks(tmp_path: Path) -> None:
|
|
381
354
|
"space_key, space",
|
382
355
|
[("SUIT", "SUIT"), ("MNI", "MNI152NLin6Asym")],
|
383
356
|
)
|
384
|
-
def test_suit(
|
357
|
+
def test_suit(space_key: str, space: str) -> None:
|
385
358
|
"""Test SUIT parcellation.
|
386
359
|
|
387
360
|
Parameters
|
388
361
|
----------
|
389
|
-
tmp_path : pathlib.Path
|
390
|
-
The path to the test directory.
|
391
362
|
space_key : str
|
392
363
|
The parametrized space values for the key.
|
393
364
|
space : str
|
394
365
|
The parametrized space values.
|
395
366
|
|
396
367
|
"""
|
397
|
-
|
398
|
-
assert f"SUITx{space_key}" in parcellations
|
368
|
+
assert f"SUITx{space_key}" in ParcellationRegistry().list
|
399
369
|
# Load parcellation
|
400
|
-
img, label, img_path, parcellation_space =
|
370
|
+
img, label, img_path, parcellation_space = ParcellationRegistry().load(
|
401
371
|
name=f"SUITx{space_key}",
|
402
|
-
|
372
|
+
target_space=space,
|
403
373
|
)
|
404
374
|
assert img is not None
|
405
375
|
assert img_path.name == f"SUIT_{space_key}Space_1mm.nii"
|
@@ -408,130 +378,123 @@ def test_suit(tmp_path: Path, space_key: str, space: str) -> None:
|
|
408
378
|
assert_array_equal(img.header["pixdim"][1:4], [1, 1, 1]) # type: ignore
|
409
379
|
|
410
380
|
|
411
|
-
def test_retrieve_suit_incorrect_space(
|
412
|
-
"""Test retrieve SUIT with incorrect space.
|
413
|
-
|
414
|
-
Parameters
|
415
|
-
----------
|
416
|
-
tmp_path : pathlib.Path
|
417
|
-
The path to the test directory.
|
418
|
-
|
419
|
-
"""
|
381
|
+
def test_retrieve_suit_incorrect_space() -> None:
|
382
|
+
"""Test retrieve SUIT with incorrect space."""
|
420
383
|
with pytest.raises(ValueError, match=r"The parameter `space`"):
|
421
|
-
_retrieve_suit(
|
422
|
-
parcellations_dir=tmp_path, resolution=1.0, space="wrong"
|
423
|
-
)
|
384
|
+
_retrieve_suit(resolution=1.0, space="wrong")
|
424
385
|
|
425
386
|
|
426
387
|
@pytest.mark.parametrize(
|
427
388
|
"scale, n_label", [(1, 16), (2, 32), (3, 50), (4, 54)]
|
428
389
|
)
|
429
|
-
def test_tian_3T_6thgeneration(
|
430
|
-
tmp_path: Path, scale: int, n_label: int
|
431
|
-
) -> None:
|
390
|
+
def test_tian_3T_6thgeneration(scale: int, n_label: int) -> None:
|
432
391
|
"""Test Tian parcellation.
|
433
392
|
|
434
393
|
Parameters
|
435
394
|
----------
|
436
|
-
tmp_path : pathlib.Path
|
437
|
-
The path to the test directory.
|
438
395
|
scale : int
|
439
396
|
The parametrized scale values.
|
440
397
|
n_label : int
|
441
398
|
The parametrized n_label values.
|
442
399
|
|
443
400
|
"""
|
444
|
-
parcellations =
|
401
|
+
parcellations = ParcellationRegistry().list
|
445
402
|
assert "TianxS1x3TxMNI6thgeneration" in parcellations
|
446
403
|
assert "TianxS2x3TxMNI6thgeneration" in parcellations
|
447
404
|
assert "TianxS3x3TxMNI6thgeneration" in parcellations
|
448
405
|
assert "TianxS4x3TxMNI6thgeneration" in parcellations
|
449
406
|
# Load parcellation
|
450
|
-
img, lbl, fname,
|
451
|
-
name=f"TianxS{scale}x3TxMNI6thgeneration",
|
407
|
+
img, lbl, fname, space = ParcellationRegistry().load(
|
408
|
+
name=f"TianxS{scale}x3TxMNI6thgeneration",
|
409
|
+
target_space="MNI152NLin2009cAsym", # force highest resolution
|
452
410
|
)
|
453
|
-
|
411
|
+
expected_fname = f"Tian_Subcortex_S{scale}_3T_1mm.nii.gz"
|
454
412
|
assert img is not None
|
455
|
-
assert fname.name ==
|
456
|
-
assert
|
413
|
+
assert fname.name == expected_fname
|
414
|
+
assert space == "MNI152NLin6Asym"
|
457
415
|
assert len(lbl) == n_label
|
458
|
-
assert_array_equal(img.header["pixdim"][1:4], [1, 1, 1])
|
416
|
+
assert_array_equal(img.header["pixdim"][1:4], [1, 1, 1])
|
459
417
|
# Load parcellation
|
460
|
-
img, lbl, fname,
|
418
|
+
img, lbl, fname, space = ParcellationRegistry().load(
|
461
419
|
name=f"TianxS{scale}x3TxMNI6thgeneration",
|
462
|
-
|
420
|
+
target_space="MNI152NLin6Asym",
|
463
421
|
resolution=2,
|
464
422
|
)
|
465
|
-
|
423
|
+
expected_fname = f"Tian_Subcortex_S{scale}_3T.nii.gz"
|
466
424
|
assert img is not None
|
467
|
-
assert fname.name ==
|
468
|
-
assert
|
425
|
+
assert fname.name == expected_fname
|
426
|
+
assert space == "MNI152NLin6Asym"
|
469
427
|
assert len(lbl) == n_label
|
470
|
-
assert_array_equal(img.header["pixdim"][1:4], [2, 2, 2])
|
428
|
+
assert_array_equal(img.header["pixdim"][1:4], [2, 2, 2])
|
471
429
|
|
472
430
|
|
473
431
|
@pytest.mark.parametrize(
|
474
432
|
"scale, n_label", [(1, 16), (2, 32), (3, 50), (4, 54)]
|
475
433
|
)
|
476
|
-
def test_tian_3T_nonlinear2009cAsym(
|
477
|
-
tmp_path: Path, scale: int, n_label: int
|
478
|
-
) -> None:
|
434
|
+
def test_tian_3T_nonlinear2009cAsym(scale: int, n_label: int) -> None:
|
479
435
|
"""Test Tian parcellation.
|
480
436
|
|
481
437
|
Parameters
|
482
438
|
----------
|
483
|
-
tmp_path : pathlib.Path
|
484
|
-
The path to the test directory.
|
485
439
|
scale : int
|
486
440
|
The parametrized scale values.
|
487
441
|
n_label : int
|
488
442
|
The parametrized n_label values.
|
489
443
|
|
490
444
|
"""
|
491
|
-
parcellations =
|
445
|
+
parcellations = ParcellationRegistry().list
|
492
446
|
assert "TianxS1x3TxMNInonlinear2009cAsym" in parcellations
|
493
447
|
assert "TianxS2x3TxMNInonlinear2009cAsym" in parcellations
|
494
448
|
assert "TianxS3x3TxMNInonlinear2009cAsym" in parcellations
|
495
449
|
assert "TianxS4x3TxMNInonlinear2009cAsym" in parcellations
|
496
450
|
# Load parcellation
|
497
|
-
img, lbl, fname, space =
|
451
|
+
img, lbl, fname, space = ParcellationRegistry().load(
|
498
452
|
name=f"TianxS{scale}x3TxMNInonlinear2009cAsym",
|
499
|
-
|
453
|
+
target_space="MNI152NLin6Asym", # force highest resolution
|
500
454
|
)
|
501
|
-
|
455
|
+
expected_fname = f"Tian_Subcortex_S{scale}_3T_2009cAsym_1mm.nii.gz"
|
502
456
|
assert img is not None
|
503
|
-
assert fname.name ==
|
457
|
+
assert fname.name == expected_fname
|
504
458
|
assert space == "MNI152NLin2009cAsym"
|
505
459
|
assert len(lbl) == n_label
|
506
|
-
assert_array_equal(img.header["pixdim"][1:4], [
|
460
|
+
assert_array_equal(img.header["pixdim"][1:4], [1, 1, 1])
|
461
|
+
# Load parcellation
|
462
|
+
img, lbl, fname, space = ParcellationRegistry().load(
|
463
|
+
name=f"TianxS{scale}x3TxMNInonlinear2009cAsym",
|
464
|
+
target_space="MNI152NLin2009cAsym",
|
465
|
+
resolution=2,
|
466
|
+
)
|
467
|
+
expected_fname = f"Tian_Subcortex_S{scale}_3T_2009cAsym.nii.gz"
|
468
|
+
assert img is not None
|
469
|
+
assert fname.name == expected_fname
|
470
|
+
assert space == "MNI152NLin2009cAsym"
|
471
|
+
assert len(lbl) == n_label
|
472
|
+
assert_array_equal(img.header["pixdim"][1:4], [2, 2, 2])
|
507
473
|
|
508
474
|
|
509
475
|
@pytest.mark.parametrize(
|
510
476
|
"scale, n_label", [(1, 16), (2, 34), (3, 54), (4, 62)]
|
511
477
|
)
|
512
|
-
def test_tian_7T_6thgeneration(
|
513
|
-
tmp_path: Path, scale: int, n_label: int
|
514
|
-
) -> None:
|
478
|
+
def test_tian_7T_6thgeneration(scale: int, n_label: int) -> None:
|
515
479
|
"""Test Tian parcellation.
|
516
480
|
|
517
481
|
Parameters
|
518
482
|
----------
|
519
|
-
tmp_path : pathlib.Path
|
520
|
-
The path to the test directory.
|
521
483
|
scale : int
|
522
484
|
The parametrized scale values.
|
523
485
|
n_label : int
|
524
486
|
The parametrized n_label values.
|
525
487
|
|
526
488
|
"""
|
527
|
-
parcellations =
|
489
|
+
parcellations = ParcellationRegistry().list
|
528
490
|
assert "TianxS1x7TxMNI6thgeneration" in parcellations
|
529
491
|
assert "TianxS2x7TxMNI6thgeneration" in parcellations
|
530
492
|
assert "TianxS3x7TxMNI6thgeneration" in parcellations
|
531
493
|
assert "TianxS4x7TxMNI6thgeneration" in parcellations
|
532
494
|
# Load parcellation
|
533
|
-
img, lbl, fname, space =
|
534
|
-
name=f"TianxS{scale}x7TxMNI6thgeneration",
|
495
|
+
img, lbl, fname, space = ParcellationRegistry().load(
|
496
|
+
name=f"TianxS{scale}x7TxMNI6thgeneration",
|
497
|
+
target_space="MNI152NLin6Asym",
|
535
498
|
)
|
536
499
|
fname1 = f"Tian_Subcortex_S{scale}_7T.nii.gz"
|
537
500
|
assert img is not None
|
@@ -543,23 +506,13 @@ def test_tian_7T_6thgeneration(
|
|
543
506
|
)
|
544
507
|
|
545
508
|
|
546
|
-
def test_retrieve_tian_incorrect_space(
|
547
|
-
"""Test retrieve tian with incorrect space.
|
548
|
-
|
549
|
-
Parameters
|
550
|
-
----------
|
551
|
-
tmp_path : pathlib.Path
|
552
|
-
The path to the test directory.
|
553
|
-
|
554
|
-
"""
|
509
|
+
def test_retrieve_tian_incorrect_space() -> None:
|
510
|
+
"""Test retrieve tian with incorrect space."""
|
555
511
|
with pytest.raises(ValueError, match=r"The parameter `space`"):
|
556
|
-
_retrieve_tian(
|
557
|
-
parcellations_dir=tmp_path, resolution=1, scale=1, space="wrong"
|
558
|
-
)
|
512
|
+
_retrieve_tian(resolution=1, scale=1, space="wrong")
|
559
513
|
|
560
514
|
with pytest.raises(ValueError, match=r"MNI152NLin6Asym"):
|
561
515
|
_retrieve_tian(
|
562
|
-
parcellations_dir=tmp_path,
|
563
516
|
resolution=1,
|
564
517
|
scale=1,
|
565
518
|
magneticfield="7T",
|
@@ -567,18 +520,10 @@ def test_retrieve_tian_incorrect_space(tmp_path: Path) -> None:
|
|
567
520
|
)
|
568
521
|
|
569
522
|
|
570
|
-
def test_retrieve_tian_incorrect_magneticfield(
|
571
|
-
"""Test retrieve tian with incorrect magneticfield.
|
572
|
-
|
573
|
-
Parameters
|
574
|
-
----------
|
575
|
-
tmp_path : pathlib.Path
|
576
|
-
The path to the test directory.
|
577
|
-
|
578
|
-
"""
|
523
|
+
def test_retrieve_tian_incorrect_magneticfield() -> None:
|
524
|
+
"""Test retrieve tian with incorrect magneticfield."""
|
579
525
|
with pytest.raises(ValueError, match=r"The parameter `magneticfield`"):
|
580
526
|
_retrieve_tian(
|
581
|
-
parcellations_dir=tmp_path,
|
582
527
|
resolution=1,
|
583
528
|
scale=1,
|
584
529
|
magneticfield="wrong",
|
@@ -586,17 +531,9 @@ def test_retrieve_tian_incorrect_magneticfield(tmp_path: Path) -> None:
|
|
586
531
|
|
587
532
|
|
588
533
|
def test_retrieve_tian_incorrect_scale(tmp_path: Path) -> None:
|
589
|
-
"""Test retrieve tian with incorrect scale.
|
590
|
-
|
591
|
-
Parameters
|
592
|
-
----------
|
593
|
-
tmp_path : pathlib.Path
|
594
|
-
The path to the test directory.
|
595
|
-
|
596
|
-
"""
|
534
|
+
"""Test retrieve tian with incorrect scale."""
|
597
535
|
with pytest.raises(ValueError, match=r"The parameter `scale`"):
|
598
536
|
_retrieve_tian(
|
599
|
-
parcellations_dir=tmp_path,
|
600
537
|
resolution=1,
|
601
538
|
scale=5,
|
602
539
|
space="MNI152NLin6Asym",
|
@@ -604,7 +541,7 @@ def test_retrieve_tian_incorrect_scale(tmp_path: Path) -> None:
|
|
604
541
|
|
605
542
|
|
606
543
|
@pytest.mark.parametrize("version", [1, 2])
|
607
|
-
def test_aicha(
|
544
|
+
def test_aicha(version: int) -> None:
|
608
545
|
"""Test AICHA parcellation.
|
609
546
|
|
610
547
|
Parameters
|
@@ -615,11 +552,11 @@ def test_aicha(tmp_path: Path, version: int) -> None:
|
|
615
552
|
The parametrized version values.
|
616
553
|
|
617
554
|
"""
|
618
|
-
|
619
|
-
assert f"AICHA_v{version}" in parcellations
|
555
|
+
assert f"AICHA_v{version}" in ParcellationRegistry().list
|
620
556
|
# Load parcellation
|
621
|
-
img, label, img_path, space =
|
622
|
-
name=f"AICHA_v{version}",
|
557
|
+
img, label, img_path, space = ParcellationRegistry().load(
|
558
|
+
name=f"AICHA_v{version}",
|
559
|
+
target_space="IXI549Space",
|
623
560
|
)
|
624
561
|
assert img is not None
|
625
562
|
assert img_path.name == "AICHA.nii"
|
@@ -628,18 +565,10 @@ def test_aicha(tmp_path: Path, version: int) -> None:
|
|
628
565
|
assert_array_equal(img.header["pixdim"][1:4], [2, 2, 2]) # type: ignore
|
629
566
|
|
630
567
|
|
631
|
-
def test_retrieve_aicha_incorrect_version(
|
632
|
-
"""Test retrieve AICHA with incorrect version.
|
633
|
-
|
634
|
-
Parameters
|
635
|
-
----------
|
636
|
-
tmp_path : pathlib.Path
|
637
|
-
The path to the test directory.
|
638
|
-
|
639
|
-
"""
|
568
|
+
def test_retrieve_aicha_incorrect_version() -> None:
|
569
|
+
"""Test retrieve AICHA with incorrect version."""
|
640
570
|
with pytest.raises(ValueError, match="The parameter `version`"):
|
641
571
|
_retrieve_aicha(
|
642
|
-
parcellations_dir=tmp_path,
|
643
572
|
version=100,
|
644
573
|
)
|
645
574
|
|
@@ -659,7 +588,6 @@ def test_retrieve_aicha_incorrect_version(tmp_path: Path) -> None:
|
|
659
588
|
],
|
660
589
|
)
|
661
590
|
def test_shen(
|
662
|
-
tmp_path: Path,
|
663
591
|
resolution: float,
|
664
592
|
year: int,
|
665
593
|
n_rois: int,
|
@@ -670,8 +598,6 @@ def test_shen(
|
|
670
598
|
|
671
599
|
Parameters
|
672
600
|
----------
|
673
|
-
tmp_path : pathlib.Path
|
674
|
-
The path to the test directory.
|
675
601
|
resolution : float
|
676
602
|
The parametrized resolution values.
|
677
603
|
year : int
|
@@ -684,12 +610,11 @@ def test_shen(
|
|
684
610
|
The parametrized partial file names.
|
685
611
|
|
686
612
|
"""
|
687
|
-
|
688
|
-
assert f"Shen_{year}_{n_rois}" in parcellations
|
613
|
+
assert f"Shen_{year}_{n_rois}" in ParcellationRegistry().list
|
689
614
|
# Load parcellation
|
690
|
-
img, label, img_path, space =
|
615
|
+
img, label, img_path, space = ParcellationRegistry().load(
|
691
616
|
name=f"Shen_{year}_{n_rois}",
|
692
|
-
|
617
|
+
target_space="MNI152NLin2009cAsym",
|
693
618
|
resolution=resolution,
|
694
619
|
)
|
695
620
|
assert img is not None
|
@@ -701,34 +626,18 @@ def test_shen(
|
|
701
626
|
)
|
702
627
|
|
703
628
|
|
704
|
-
def test_retrieve_shen_incorrect_year(
|
705
|
-
"""Test retrieve Shen with incorrect year.
|
706
|
-
|
707
|
-
Parameters
|
708
|
-
----------
|
709
|
-
tmp_path : pathlib.Path
|
710
|
-
The path to the test directory.
|
711
|
-
|
712
|
-
"""
|
629
|
+
def test_retrieve_shen_incorrect_year() -> None:
|
630
|
+
"""Test retrieve Shen with incorrect year."""
|
713
631
|
with pytest.raises(ValueError, match="The parameter `year`"):
|
714
632
|
_retrieve_shen(
|
715
|
-
parcellations_dir=tmp_path,
|
716
633
|
year=1969,
|
717
634
|
)
|
718
635
|
|
719
636
|
|
720
|
-
def test_retrieve_shen_incorrect_n_rois(
|
721
|
-
"""Test retrieve Shen with incorrect ROIs.
|
722
|
-
|
723
|
-
Parameters
|
724
|
-
----------
|
725
|
-
tmp_path : pathlib.Path
|
726
|
-
The path to the test directory.
|
727
|
-
|
728
|
-
"""
|
637
|
+
def test_retrieve_shen_incorrect_n_rois() -> None:
|
638
|
+
"""Test retrieve Shen with incorrect ROIs."""
|
729
639
|
with pytest.raises(ValueError, match="The parameter `n_rois`"):
|
730
640
|
_retrieve_shen(
|
731
|
-
parcellations_dir=tmp_path,
|
732
641
|
year=2015,
|
733
642
|
n_rois=10,
|
734
643
|
)
|
@@ -751,7 +660,6 @@ def test_retrieve_shen_incorrect_n_rois(tmp_path: Path) -> None:
|
|
751
660
|
],
|
752
661
|
)
|
753
662
|
def test_retrieve_shen_incorrect_param_combo(
|
754
|
-
tmp_path: Path,
|
755
663
|
resolution: float,
|
756
664
|
year: int,
|
757
665
|
n_rois: int,
|
@@ -772,7 +680,6 @@ def test_retrieve_shen_incorrect_param_combo(
|
|
772
680
|
"""
|
773
681
|
with pytest.raises(ValueError, match="The parameter combination"):
|
774
682
|
_retrieve_shen(
|
775
|
-
parcellations_dir=tmp_path,
|
776
683
|
resolution=resolution,
|
777
684
|
year=year,
|
778
685
|
n_rois=n_rois,
|
@@ -845,7 +752,6 @@ def test_retrieve_shen_incorrect_param_combo(
|
|
845
752
|
],
|
846
753
|
)
|
847
754
|
def test_yan(
|
848
|
-
tmp_path: Path,
|
849
755
|
resolution: float,
|
850
756
|
n_rois: int,
|
851
757
|
yeo_networks: int,
|
@@ -855,8 +761,6 @@ def test_yan(
|
|
855
761
|
|
856
762
|
Parameters
|
857
763
|
----------
|
858
|
-
tmp_path : pathlib.Path
|
859
|
-
The path to the test directory.
|
860
764
|
resolution : float
|
861
765
|
The parametrized resolution values.
|
862
766
|
n_rois : int
|
@@ -867,7 +771,7 @@ def test_yan(
|
|
867
771
|
The parametrized Kong networks values.
|
868
772
|
|
869
773
|
"""
|
870
|
-
parcellations =
|
774
|
+
parcellations = ParcellationRegistry().list
|
871
775
|
if yeo_networks:
|
872
776
|
parcellation_name = f"Yan{n_rois}xYeo{yeo_networks}"
|
873
777
|
assert parcellation_name in parcellations
|
@@ -883,9 +787,9 @@ def test_yan(
|
|
883
787
|
f"{int(resolution)}mm.nii.gz"
|
884
788
|
)
|
885
789
|
# Load parcellation
|
886
|
-
img, label, img_path, space =
|
887
|
-
name=parcellation_name,
|
888
|
-
|
790
|
+
img, label, img_path, space = ParcellationRegistry().load(
|
791
|
+
name=parcellation_name,
|
792
|
+
target_space="MNI152NLin6Asym",
|
889
793
|
resolution=resolution,
|
890
794
|
)
|
891
795
|
assert img is not None
|
@@ -897,20 +801,12 @@ def test_yan(
|
|
897
801
|
)
|
898
802
|
|
899
803
|
|
900
|
-
def test_retrieve_yan_incorrect_networks(
|
901
|
-
"""Test retrieve Yan with incorrect networks.
|
902
|
-
|
903
|
-
Parameters
|
904
|
-
----------
|
905
|
-
tmp_path : pathlib.Path
|
906
|
-
The path to the test directory.
|
907
|
-
|
908
|
-
"""
|
804
|
+
def test_retrieve_yan_incorrect_networks() -> None:
|
805
|
+
"""Test retrieve Yan with incorrect networks."""
|
909
806
|
with pytest.raises(
|
910
807
|
ValueError, match="Either one of `yeo_networks` or `kong_networks`"
|
911
808
|
):
|
912
809
|
_retrieve_yan(
|
913
|
-
parcellations_dir=tmp_path,
|
914
810
|
n_rois=31418,
|
915
811
|
yeo_networks=100,
|
916
812
|
kong_networks=100,
|
@@ -920,59 +816,34 @@ def test_retrieve_yan_incorrect_networks(tmp_path: Path) -> None:
|
|
920
816
|
ValueError, match="Either one of `yeo_networks` or `kong_networks`"
|
921
817
|
):
|
922
818
|
_retrieve_yan(
|
923
|
-
parcellations_dir=tmp_path,
|
924
819
|
n_rois=31418,
|
925
820
|
yeo_networks=None,
|
926
821
|
kong_networks=None,
|
927
822
|
)
|
928
823
|
|
929
824
|
|
930
|
-
def test_retrieve_yan_incorrect_n_rois(
|
931
|
-
"""Test retrieve Yan with incorrect ROIs.
|
932
|
-
|
933
|
-
Parameters
|
934
|
-
----------
|
935
|
-
tmp_path : pathlib.Path
|
936
|
-
The path to the test directory.
|
937
|
-
|
938
|
-
"""
|
825
|
+
def test_retrieve_yan_incorrect_n_rois() -> None:
|
826
|
+
"""Test retrieve Yan with incorrect ROIs."""
|
939
827
|
with pytest.raises(ValueError, match="The parameter `n_rois`"):
|
940
828
|
_retrieve_yan(
|
941
|
-
parcellations_dir=tmp_path,
|
942
829
|
n_rois=31418,
|
943
830
|
yeo_networks=7,
|
944
831
|
)
|
945
832
|
|
946
833
|
|
947
|
-
def test_retrieve_yan_incorrect_yeo_networks(
|
948
|
-
"""Test retrieve Yan with incorrect Yeo networks.
|
949
|
-
|
950
|
-
Parameters
|
951
|
-
----------
|
952
|
-
tmp_path : pathlib.Path
|
953
|
-
The path to the test directory.
|
954
|
-
|
955
|
-
"""
|
834
|
+
def test_retrieve_yan_incorrect_yeo_networks() -> None:
|
835
|
+
"""Test retrieve Yan with incorrect Yeo networks."""
|
956
836
|
with pytest.raises(ValueError, match="The parameter `yeo_networks`"):
|
957
837
|
_retrieve_yan(
|
958
|
-
parcellations_dir=tmp_path,
|
959
838
|
n_rois=100,
|
960
839
|
yeo_networks=27,
|
961
840
|
)
|
962
841
|
|
963
842
|
|
964
|
-
def test_retrieve_yan_incorrect_kong_networks(
|
965
|
-
"""Test retrieve Yan with incorrect Kong networks.
|
966
|
-
|
967
|
-
Parameters
|
968
|
-
----------
|
969
|
-
tmp_path : pathlib.Path
|
970
|
-
The path to the test directory.
|
971
|
-
|
972
|
-
"""
|
843
|
+
def test_retrieve_yan_incorrect_kong_networks() -> None:
|
844
|
+
"""Test retrieve Yan with incorrect Kong networks."""
|
973
845
|
with pytest.raises(ValueError, match="The parameter `kong_networks`"):
|
974
846
|
_retrieve_yan(
|
975
|
-
parcellations_dir=tmp_path,
|
976
847
|
n_rois=100,
|
977
848
|
kong_networks=27,
|
978
849
|
)
|
@@ -993,7 +864,6 @@ def test_retrieve_yan_incorrect_kong_networks(tmp_path: Path) -> None:
|
|
993
864
|
],
|
994
865
|
)
|
995
866
|
def test_brainnetome(
|
996
|
-
tmp_path: Path,
|
997
867
|
resolution: float,
|
998
868
|
threshold: int,
|
999
869
|
) -> None:
|
@@ -1001,15 +871,13 @@ def test_brainnetome(
|
|
1001
871
|
|
1002
872
|
Parameters
|
1003
873
|
----------
|
1004
|
-
tmp_path : pathlib.Path
|
1005
|
-
The path to the test directory.
|
1006
874
|
resolution : float
|
1007
875
|
The parametrized resolution values.
|
1008
876
|
threshold : int
|
1009
877
|
The parametrized threshold values.
|
1010
878
|
|
1011
879
|
"""
|
1012
|
-
parcellations =
|
880
|
+
parcellations = ParcellationRegistry().list
|
1013
881
|
parcellation_name = f"Brainnetome_thr{threshold}"
|
1014
882
|
assert parcellation_name in parcellations
|
1015
883
|
|
@@ -1019,9 +887,9 @@ def test_brainnetome(
|
|
1019
887
|
|
1020
888
|
parcellation_file = f"BNA-maxprob-thr{threshold}-{resolution}mm.nii.gz"
|
1021
889
|
# Load parcellation
|
1022
|
-
img, label, img_path, space =
|
890
|
+
img, label, img_path, space = ParcellationRegistry().load(
|
1023
891
|
name=parcellation_name,
|
1024
|
-
|
892
|
+
target_space="MNI152NLin6Asym",
|
1025
893
|
resolution=resolution,
|
1026
894
|
)
|
1027
895
|
assert img is not None
|
@@ -1033,18 +901,10 @@ def test_brainnetome(
|
|
1033
901
|
)
|
1034
902
|
|
1035
903
|
|
1036
|
-
def test_retrieve_brainnetome_incorrect_threshold(
|
1037
|
-
"""Test retrieve Brainnetome with incorrect threshold.
|
1038
|
-
|
1039
|
-
Parameters
|
1040
|
-
----------
|
1041
|
-
tmp_path : pathlib.Path
|
1042
|
-
The path to the test directory.
|
1043
|
-
|
1044
|
-
"""
|
904
|
+
def test_retrieve_brainnetome_incorrect_threshold() -> None:
|
905
|
+
"""Test retrieve Brainnetome with incorrect threshold."""
|
1045
906
|
with pytest.raises(ValueError, match="The parameter `threshold`"):
|
1046
907
|
_retrieve_brainnetome(
|
1047
|
-
parcellations_dir=tmp_path,
|
1048
908
|
threshold=100,
|
1049
909
|
)
|
1050
910
|
|
@@ -1052,11 +912,12 @@ def test_retrieve_brainnetome_incorrect_threshold(tmp_path: Path) -> None:
|
|
1052
912
|
def test_merge_parcellations() -> None:
|
1053
913
|
"""Test merging parcellations."""
|
1054
914
|
# load some parcellations for testing
|
1055
|
-
schaefer_parcellation, schaefer_labels, _, _ =
|
1056
|
-
"Schaefer100x17"
|
915
|
+
schaefer_parcellation, schaefer_labels, _, _ = ParcellationRegistry().load(
|
916
|
+
"Schaefer100x17", target_space="MNI152NLin2009cAsym"
|
1057
917
|
)
|
1058
|
-
tian_parcellation, tian_labels, _, _ =
|
1059
|
-
"TianxS2x3TxMNInonlinear2009cAsym"
|
918
|
+
tian_parcellation, tian_labels, _, _ = ParcellationRegistry().load(
|
919
|
+
"TianxS2x3TxMNInonlinear2009cAsym",
|
920
|
+
target_space="MNI152NLin2009cAsym",
|
1060
921
|
)
|
1061
922
|
# prepare the list of the actual parcellations
|
1062
923
|
parcellation_list = [schaefer_parcellation, tian_parcellation]
|
@@ -1088,7 +949,9 @@ def test_merge_parcellations_3D_multiple_non_overlapping(
|
|
1088
949
|
|
1089
950
|
"""
|
1090
951
|
# Get the testing parcellation
|
1091
|
-
parcellation, labels, _, _ =
|
952
|
+
parcellation, labels, _, _ = ParcellationRegistry().load(
|
953
|
+
"Schaefer100x7", target_space="MNI152NLin2009cAsym"
|
954
|
+
)
|
1092
955
|
|
1093
956
|
assert parcellation is not None
|
1094
957
|
|
@@ -1123,7 +986,9 @@ def test_merge_parcellations_3D_multiple_overlapping() -> None:
|
|
1123
986
|
"""Test merge_parcellations with multiple overlapping parcellations."""
|
1124
987
|
|
1125
988
|
# Get the testing parcellation
|
1126
|
-
parcellation, labels, _, _ =
|
989
|
+
parcellation, labels, _, _ = ParcellationRegistry().load(
|
990
|
+
"Schaefer100x7", target_space="MNI152NLin2009cAsym"
|
991
|
+
)
|
1127
992
|
|
1128
993
|
assert parcellation is not None
|
1129
994
|
|
@@ -1147,9 +1012,7 @@ def test_merge_parcellations_3D_multiple_overlapping() -> None:
|
|
1147
1012
|
labels_lists = [labels1, labels2]
|
1148
1013
|
|
1149
1014
|
with pytest.warns(RuntimeWarning, match="overlapping voxels"):
|
1150
|
-
|
1151
|
-
parcellation_list, names, labels_lists
|
1152
|
-
)
|
1015
|
+
merge_parcellations(parcellation_list, names, labels_lists)
|
1153
1016
|
|
1154
1017
|
parc_data = parcellation.get_fdata()
|
1155
1018
|
assert len(labels) == 100
|
@@ -1160,7 +1023,9 @@ def test_merge_parcellations_3D_multiple_duplicated_labels() -> None:
|
|
1160
1023
|
"""Test merge_parcellations with duplicated labels."""
|
1161
1024
|
|
1162
1025
|
# Get the testing parcellation
|
1163
|
-
parcellation, labels, _, _ =
|
1026
|
+
parcellation, labels, _, _ = ParcellationRegistry().load(
|
1027
|
+
"Schaefer100x7", target_space="MNI152NLin2009cAsym"
|
1028
|
+
)
|
1164
1029
|
|
1165
1030
|
assert parcellation is not None
|
1166
1031
|
|
@@ -1182,7 +1047,7 @@ def test_merge_parcellations_3D_multiple_duplicated_labels() -> None:
|
|
1182
1047
|
labels_lists = [labels1, labels2]
|
1183
1048
|
|
1184
1049
|
with pytest.warns(RuntimeWarning, match="duplicated labels."):
|
1185
|
-
merged_parc,
|
1050
|
+
merged_parc, _ = merge_parcellations(
|
1186
1051
|
parcellation_list, names, labels_lists
|
1187
1052
|
)
|
1188
1053
|
|
@@ -1192,24 +1057,25 @@ def test_merge_parcellations_3D_multiple_duplicated_labels() -> None:
|
|
1192
1057
|
assert len(np.unique(parc_data)) == 101 # 100 + 1 because background 0
|
1193
1058
|
|
1194
1059
|
|
1195
|
-
def
|
1060
|
+
def test_get_single() -> None:
|
1196
1061
|
"""Test tailored single parcellation fetch."""
|
1197
1062
|
with PartlyCloudyTestingDataGrabber() as dg:
|
1198
1063
|
element_data = DefaultDataReader().fit_transform(dg["sub-01"])
|
1199
1064
|
bold = element_data["BOLD"]
|
1200
1065
|
bold_img = bold["data"]
|
1201
1066
|
# Get tailored parcellation
|
1202
|
-
tailored_parcellation, tailored_labels =
|
1203
|
-
|
1067
|
+
tailored_parcellation, tailored_labels = ParcellationRegistry().get(
|
1068
|
+
parcellations=["Shen_2015_268"],
|
1204
1069
|
target_data=bold,
|
1205
1070
|
)
|
1206
1071
|
# Check shape and affine with original element data
|
1207
1072
|
assert tailored_parcellation.shape == bold_img.shape[:3]
|
1208
1073
|
assert_array_equal(tailored_parcellation.affine, bold_img.affine)
|
1209
1074
|
# Get raw parcellation
|
1210
|
-
raw_parcellation, raw_labels, _, _ =
|
1211
|
-
"
|
1212
|
-
|
1075
|
+
raw_parcellation, raw_labels, _, _ = ParcellationRegistry().load(
|
1076
|
+
name="Shen_2015_268",
|
1077
|
+
target_space="MNI152NLin2009cAsym",
|
1078
|
+
resolution=4,
|
1213
1079
|
)
|
1214
1080
|
resampled_raw_parcellation = resample_to_img(
|
1215
1081
|
source_img=raw_parcellation,
|
@@ -1225,15 +1091,15 @@ def test_get_parcellation_single() -> None:
|
|
1225
1091
|
assert tailored_labels == raw_labels
|
1226
1092
|
|
1227
1093
|
|
1228
|
-
def
|
1094
|
+
def test_get_multi_same_space() -> None:
|
1229
1095
|
"""Test tailored multi parcellation fetch in same space."""
|
1230
1096
|
with PartlyCloudyTestingDataGrabber() as dg:
|
1231
1097
|
element_data = DefaultDataReader().fit_transform(dg["sub-01"])
|
1232
1098
|
bold = element_data["BOLD"]
|
1233
1099
|
bold_img = bold["data"]
|
1234
1100
|
# Get tailored parcellation
|
1235
|
-
tailored_parcellation, tailored_labels =
|
1236
|
-
|
1101
|
+
tailored_parcellation, tailored_labels = ParcellationRegistry().get(
|
1102
|
+
parcellations=[
|
1237
1103
|
"Shen_2015_268",
|
1238
1104
|
"TianxS1x3TxMNInonlinear2009cAsym",
|
1239
1105
|
],
|
@@ -1250,7 +1116,11 @@ def test_get_parcellation_multi_same_space() -> None:
|
|
1250
1116
|
"TianxS1x3TxMNInonlinear2009cAsym",
|
1251
1117
|
]
|
1252
1118
|
for name in parcellations_names:
|
1253
|
-
img, labels, _, _ =
|
1119
|
+
img, labels, _, _ = ParcellationRegistry().load(
|
1120
|
+
name=name,
|
1121
|
+
target_space="MNI152NLin2009cAsym",
|
1122
|
+
resolution=4,
|
1123
|
+
)
|
1254
1124
|
# Resample raw parcellations
|
1255
1125
|
resampled_img = resample_to_img(
|
1256
1126
|
source_img=img,
|
@@ -1277,13 +1147,13 @@ def test_get_parcellation_multi_same_space() -> None:
|
|
1277
1147
|
@pytest.mark.skipif(
|
1278
1148
|
_check_ants() is False, reason="requires ANTs to be in PATH"
|
1279
1149
|
)
|
1280
|
-
def
|
1150
|
+
def test_get_multi_different_space() -> None:
|
1281
1151
|
"""Test tailored multi parcellation fetch in different space."""
|
1282
1152
|
with OasisVBMTestingDataGrabber() as dg:
|
1283
1153
|
element_data = DefaultDataReader().fit_transform(dg["sub-01"])
|
1284
1154
|
# Get tailored parcellation
|
1285
|
-
|
1286
|
-
|
1155
|
+
ParcellationRegistry().get(
|
1156
|
+
parcellations=[
|
1287
1157
|
"Schaefer100x7",
|
1288
1158
|
"TianxS1x3TxMNInonlinear2009cAsym",
|
1289
1159
|
],
|