junifer 0.0.6.dev154__py3-none-any.whl → 0.0.6.dev194__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__.pyi +2 -0
- junifer/_version.py +2 -2
- junifer/api/decorators.py +6 -11
- junifer/api/functions.py +74 -62
- junifer/api/tests/test_functions.py +2 -2
- junifer/data/__init__.pyi +17 -31
- junifer/data/_dispatch.py +251 -0
- junifer/data/coordinates/__init__.py +9 -0
- junifer/data/coordinates/__init__.pyi +5 -0
- junifer/data/coordinates/_ants_coordinates_warper.py +96 -0
- junifer/data/coordinates/_coordinates.py +356 -0
- junifer/data/coordinates/_fsl_coordinates_warper.py +83 -0
- junifer/data/{tests → coordinates/tests}/test_coordinates.py +25 -31
- junifer/data/masks/__init__.py +9 -0
- junifer/data/masks/__init__.pyi +6 -0
- junifer/data/masks/_ants_mask_warper.py +144 -0
- junifer/data/masks/_fsl_mask_warper.py +87 -0
- junifer/data/masks/_masks.py +624 -0
- junifer/data/{tests → masks/tests}/test_masks.py +63 -58
- junifer/data/parcellations/__init__.py +9 -0
- junifer/data/parcellations/__init__.pyi +6 -0
- junifer/data/parcellations/_ants_parcellation_warper.py +154 -0
- junifer/data/parcellations/_fsl_parcellation_warper.py +91 -0
- junifer/data/{parcellations.py → parcellations/_parcellations.py} +450 -473
- junifer/data/{tests → parcellations/tests}/test_parcellations.py +73 -81
- junifer/data/pipeline_data_registry_base.py +74 -0
- junifer/data/utils.py +4 -0
- junifer/datagrabber/aomic/piop2.py +1 -1
- junifer/markers/complexity/hurst_exponent.py +2 -2
- junifer/markers/complexity/multiscale_entropy_auc.py +2 -2
- junifer/markers/complexity/perm_entropy.py +2 -2
- junifer/markers/complexity/range_entropy.py +2 -2
- junifer/markers/complexity/range_entropy_auc.py +2 -2
- junifer/markers/complexity/sample_entropy.py +2 -2
- junifer/markers/complexity/weighted_perm_entropy.py +2 -2
- junifer/markers/ets_rss.py +2 -2
- junifer/markers/falff/falff_parcels.py +2 -2
- junifer/markers/falff/falff_spheres.py +2 -2
- junifer/markers/functional_connectivity/edge_functional_connectivity_parcels.py +1 -1
- junifer/markers/functional_connectivity/edge_functional_connectivity_spheres.py +1 -1
- junifer/markers/functional_connectivity/functional_connectivity_parcels.py +1 -1
- junifer/markers/functional_connectivity/functional_connectivity_spheres.py +1 -1
- junifer/markers/functional_connectivity/tests/test_functional_connectivity_parcels.py +3 -3
- junifer/markers/functional_connectivity/tests/test_functional_connectivity_spheres.py +2 -2
- junifer/markers/parcel_aggregation.py +11 -7
- junifer/markers/reho/reho_parcels.py +2 -2
- junifer/markers/reho/reho_spheres.py +2 -2
- junifer/markers/sphere_aggregation.py +11 -7
- junifer/markers/temporal_snr/temporal_snr_parcels.py +2 -2
- junifer/markers/temporal_snr/temporal_snr_spheres.py +2 -2
- 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/pipeline/__init__.pyi +2 -2
- junifer/pipeline/pipeline_component_registry.py +299 -0
- junifer/pipeline/tests/test_pipeline_component_registry.py +201 -0
- junifer/preprocess/confounds/fmriprep_confound_remover.py +6 -3
- junifer/testing/__init__.pyi +2 -2
- junifer/testing/registry.py +4 -7
- junifer/testing/tests/test_testing_registry.py +9 -17
- {junifer-0.0.6.dev154.dist-info → junifer-0.0.6.dev194.dist-info}/METADATA +1 -1
- {junifer-0.0.6.dev154.dist-info → junifer-0.0.6.dev194.dist-info}/RECORD +86 -72
- {junifer-0.0.6.dev154.dist-info → junifer-0.0.6.dev194.dist-info}/WHEEL +1 -1
- junifer/data/coordinates.py +0 -408
- junifer/data/masks.py +0 -670
- junifer/pipeline/registry.py +0 -245
- junifer/pipeline/tests/test_registry.py +0 -150
- /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.6.dev154.dist-info → junifer-0.0.6.dev194.dist-info}/AUTHORS.rst +0 -0
- {junifer-0.0.6.dev154.dist-info → junifer-0.0.6.dev194.dist-info}/LICENSE.md +0 -0
- {junifer-0.0.6.dev154.dist-info → junifer-0.0.6.dev194.dist-info}/entry_points.txt +0 -0
- {junifer-0.0.6.dev154.dist-info → junifer-0.0.6.dev194.dist-info}/top_level.txt +0 -0
@@ -14,7 +14,9 @@ import pytest
|
|
14
14
|
from nilearn.image import new_img_like, resample_to_img
|
15
15
|
from numpy.testing import assert_array_almost_equal, assert_array_equal
|
16
16
|
|
17
|
-
from junifer.data
|
17
|
+
from junifer.data import ParcellationRegistry
|
18
|
+
from junifer.data.parcellations import merge_parcellations
|
19
|
+
from junifer.data.parcellations._parcellations import (
|
18
20
|
_retrieve_aicha,
|
19
21
|
_retrieve_brainnetome,
|
20
22
|
_retrieve_parcellation,
|
@@ -23,11 +25,6 @@ from junifer.data.parcellations import (
|
|
23
25
|
_retrieve_suit,
|
24
26
|
_retrieve_tian,
|
25
27
|
_retrieve_yan,
|
26
|
-
get_parcellation,
|
27
|
-
list_parcellations,
|
28
|
-
load_parcellation,
|
29
|
-
merge_parcellations,
|
30
|
-
register_parcellation,
|
31
28
|
)
|
32
29
|
from junifer.datareader import DefaultDataReader
|
33
30
|
from junifer.pipeline.utils import _check_ants
|
@@ -37,10 +34,10 @@ from junifer.testing.datagrabbers import (
|
|
37
34
|
)
|
38
35
|
|
39
36
|
|
40
|
-
def
|
37
|
+
def test_register_built_in_check() -> None:
|
41
38
|
"""Test parcellation registration check for built-in parcellations."""
|
42
39
|
with pytest.raises(ValueError, match=r"built-in parcellation"):
|
43
|
-
|
40
|
+
ParcellationRegistry().register(
|
44
41
|
name="SUITxSUIT",
|
45
42
|
parcellation_path="testparc.nii.gz",
|
46
43
|
parcels_labels=["1", "2", "3"],
|
@@ -49,35 +46,34 @@ def test_register_parcellation_built_in_check() -> None:
|
|
49
46
|
)
|
50
47
|
|
51
48
|
|
52
|
-
def
|
49
|
+
def test_list_incorrect() -> None:
|
53
50
|
"""Test incorrect information check for list parcellations."""
|
54
|
-
|
55
|
-
assert "testparc" not in parcellations
|
51
|
+
assert "testparc" not in ParcellationRegistry().list
|
56
52
|
|
57
53
|
|
58
|
-
def
|
54
|
+
def test_register_already_registered() -> None:
|
59
55
|
"""Test parcellation registration check for already registered."""
|
60
56
|
# Register custom parcellation
|
61
|
-
|
57
|
+
ParcellationRegistry().register(
|
62
58
|
name="testparc",
|
63
59
|
parcellation_path="testparc.nii.gz",
|
64
60
|
parcels_labels=["1", "2", "3"],
|
65
61
|
space="MNI152Lin",
|
66
62
|
)
|
67
63
|
assert (
|
68
|
-
|
64
|
+
ParcellationRegistry().load("testparc", path_only=True)[2].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,7 @@ def test_register_parcellation_already_registered() -> None:
|
|
86
82
|
)
|
87
83
|
|
88
84
|
assert (
|
89
|
-
|
85
|
+
ParcellationRegistry().load("testparc", path_only=True)[2].name
|
90
86
|
== "testparc2.nii.gz"
|
91
87
|
)
|
92
88
|
|
@@ -100,24 +96,26 @@ def test_parcellation_wrong_labels_values(tmp_path: Path) -> None:
|
|
100
96
|
The path to the test directory.
|
101
97
|
|
102
98
|
"""
|
103
|
-
schaefer, labels, schaefer_path, _ =
|
99
|
+
schaefer, labels, schaefer_path, _ = ParcellationRegistry().load(
|
100
|
+
"Schaefer100x7"
|
101
|
+
)
|
104
102
|
assert schaefer is not None
|
105
103
|
|
106
104
|
# Test wrong number of labels
|
107
|
-
|
105
|
+
ParcellationRegistry().register(
|
108
106
|
"WrongLabels", schaefer_path, labels[:10], "MNI152Lin"
|
109
107
|
)
|
110
108
|
|
111
109
|
with pytest.raises(ValueError, match=r"has 100 parcels but 10"):
|
112
|
-
|
110
|
+
ParcellationRegistry().load("WrongLabels")
|
113
111
|
|
114
112
|
# Test wrong number of labels
|
115
|
-
|
113
|
+
ParcellationRegistry().register(
|
116
114
|
"WrongLabels2", schaefer_path, [*labels, "wrong"], "MNI152Lin"
|
117
115
|
)
|
118
116
|
|
119
117
|
with pytest.raises(ValueError, match=r"has 100 parcels but 101"):
|
120
|
-
|
118
|
+
ParcellationRegistry().load("WrongLabels2")
|
121
119
|
|
122
120
|
schaefer_data = schaefer.get_fdata().copy()
|
123
121
|
schaefer_data[schaefer_data == 50] = 0
|
@@ -125,11 +123,11 @@ def test_parcellation_wrong_labels_values(tmp_path: Path) -> None:
|
|
125
123
|
new_schaefer_img = new_img_like(schaefer, schaefer_data)
|
126
124
|
nib.save(new_schaefer_img, new_schaefer_path)
|
127
125
|
|
128
|
-
|
126
|
+
ParcellationRegistry().register(
|
129
127
|
"WrongValues", new_schaefer_path, labels[:-1], "MNI152Lin"
|
130
128
|
)
|
131
|
-
with pytest.raises(ValueError, match=r"the
|
132
|
-
|
129
|
+
with pytest.raises(ValueError, match=r"must have all the values in the"):
|
130
|
+
ParcellationRegistry().load("WrongValues")
|
133
131
|
|
134
132
|
schaefer_data = schaefer.get_fdata().copy()
|
135
133
|
schaefer_data[schaefer_data == 50] = 200
|
@@ -137,11 +135,11 @@ def test_parcellation_wrong_labels_values(tmp_path: Path) -> None:
|
|
137
135
|
new_schaefer_img = new_img_like(schaefer, schaefer_data)
|
138
136
|
nib.save(new_schaefer_img, new_schaefer_path)
|
139
137
|
|
140
|
-
|
138
|
+
ParcellationRegistry().register(
|
141
139
|
"WrongValues2", new_schaefer_path, labels, "MNI152Lin"
|
142
140
|
)
|
143
|
-
with pytest.raises(ValueError, match=r"the
|
144
|
-
|
141
|
+
with pytest.raises(ValueError, match=r"must have all the values in the"):
|
142
|
+
ParcellationRegistry().load("WrongValues2")
|
145
143
|
|
146
144
|
|
147
145
|
@pytest.mark.parametrize(
|
@@ -170,7 +168,7 @@ def test_parcellation_wrong_labels_values(tmp_path: Path) -> None:
|
|
170
168
|
),
|
171
169
|
],
|
172
170
|
)
|
173
|
-
def
|
171
|
+
def test_register(
|
174
172
|
name: str,
|
175
173
|
parcellation_path: str,
|
176
174
|
parcels_labels: List[str],
|
@@ -194,7 +192,7 @@ def test_register_parcellation(
|
|
194
192
|
|
195
193
|
"""
|
196
194
|
# Register custom parcellation
|
197
|
-
|
195
|
+
ParcellationRegistry().register(
|
198
196
|
name=name,
|
199
197
|
parcellation_path=parcellation_path,
|
200
198
|
parcels_labels=parcels_labels,
|
@@ -202,10 +200,9 @@ def test_register_parcellation(
|
|
202
200
|
overwrite=overwrite,
|
203
201
|
)
|
204
202
|
# List available parcellation and check registration
|
205
|
-
|
206
|
-
assert name in parcellations
|
203
|
+
assert name in ParcellationRegistry().list
|
207
204
|
# Load registered parcellation
|
208
|
-
_, lbl, fname, parcellation_space =
|
205
|
+
_, lbl, fname, parcellation_space = ParcellationRegistry().load(
|
209
206
|
name=name, path_only=True
|
210
207
|
)
|
211
208
|
# Check values for registered parcellation
|
@@ -228,7 +225,7 @@ def test_register_parcellation(
|
|
228
225
|
"TianxS4x3TxMNInonlinear2009cAsym",
|
229
226
|
],
|
230
227
|
)
|
231
|
-
def
|
228
|
+
def test_list_correct(parcellation_name: str) -> None:
|
232
229
|
"""Test correct information check for list parcellations.
|
233
230
|
|
234
231
|
Parameters
|
@@ -237,14 +234,13 @@ def test_list_parcellations_correct(parcellation_name: str) -> None:
|
|
237
234
|
The parametrized parcellation name.
|
238
235
|
|
239
236
|
"""
|
240
|
-
|
241
|
-
assert parcellation_name in parcellations
|
237
|
+
assert parcellation_name in ParcellationRegistry().list
|
242
238
|
|
243
239
|
|
244
|
-
def
|
240
|
+
def test_load_incorrect() -> None:
|
245
241
|
"""Test loading of invalid parcellations."""
|
246
242
|
with pytest.raises(ValueError, match=r"not found"):
|
247
|
-
|
243
|
+
ParcellationRegistry().load("wrongparcellation")
|
248
244
|
|
249
245
|
|
250
246
|
def test_retrieve_parcellation_incorrect() -> None:
|
@@ -318,16 +314,15 @@ def test_schaefer(
|
|
318
314
|
The parametrized Yeo networks values.
|
319
315
|
|
320
316
|
"""
|
321
|
-
parcellations = list_parcellations()
|
322
317
|
parcellation_name = f"Schaefer{n_rois}x{yeo_networks}"
|
323
|
-
assert parcellation_name in
|
318
|
+
assert parcellation_name in ParcellationRegistry().list
|
324
319
|
|
325
320
|
parcellation_file = (
|
326
321
|
f"Schaefer2018_{n_rois}Parcels_{yeo_networks}Networks_order_FSLMNI152_"
|
327
322
|
f"{int(resolution)}mm.nii.gz"
|
328
323
|
)
|
329
324
|
# Load parcellation
|
330
|
-
img, label, img_path, space =
|
325
|
+
img, label, img_path, space = ParcellationRegistry().load(
|
331
326
|
name=parcellation_name,
|
332
327
|
parcellations_dir=tmp_path,
|
333
328
|
resolution=resolution,
|
@@ -394,10 +389,9 @@ def test_suit(tmp_path: Path, space_key: str, space: str) -> None:
|
|
394
389
|
The parametrized space values.
|
395
390
|
|
396
391
|
"""
|
397
|
-
|
398
|
-
assert f"SUITx{space_key}" in parcellations
|
392
|
+
assert f"SUITx{space_key}" in ParcellationRegistry().list
|
399
393
|
# Load parcellation
|
400
|
-
img, label, img_path, parcellation_space =
|
394
|
+
img, label, img_path, parcellation_space = ParcellationRegistry().load(
|
401
395
|
name=f"SUITx{space_key}",
|
402
396
|
parcellations_dir=tmp_path,
|
403
397
|
)
|
@@ -441,13 +435,13 @@ def test_tian_3T_6thgeneration(
|
|
441
435
|
The parametrized n_label values.
|
442
436
|
|
443
437
|
"""
|
444
|
-
parcellations =
|
438
|
+
parcellations = ParcellationRegistry().list
|
445
439
|
assert "TianxS1x3TxMNI6thgeneration" in parcellations
|
446
440
|
assert "TianxS2x3TxMNI6thgeneration" in parcellations
|
447
441
|
assert "TianxS3x3TxMNI6thgeneration" in parcellations
|
448
442
|
assert "TianxS4x3TxMNI6thgeneration" in parcellations
|
449
443
|
# Load parcellation
|
450
|
-
img, lbl, fname, parcellation_space_1 =
|
444
|
+
img, lbl, fname, parcellation_space_1 = ParcellationRegistry().load(
|
451
445
|
name=f"TianxS{scale}x3TxMNI6thgeneration", parcellations_dir=tmp_path
|
452
446
|
)
|
453
447
|
fname1 = f"Tian_Subcortex_S{scale}_3T_1mm.nii.gz"
|
@@ -457,7 +451,7 @@ def test_tian_3T_6thgeneration(
|
|
457
451
|
assert len(lbl) == n_label
|
458
452
|
assert_array_equal(img.header["pixdim"][1:4], [1, 1, 1]) # type: ignore
|
459
453
|
# Load parcellation
|
460
|
-
img, lbl, fname, parcellation_space_2 =
|
454
|
+
img, lbl, fname, parcellation_space_2 = ParcellationRegistry().load(
|
461
455
|
name=f"TianxS{scale}x3TxMNI6thgeneration",
|
462
456
|
parcellations_dir=tmp_path,
|
463
457
|
resolution=2,
|
@@ -488,13 +482,13 @@ def test_tian_3T_nonlinear2009cAsym(
|
|
488
482
|
The parametrized n_label values.
|
489
483
|
|
490
484
|
"""
|
491
|
-
parcellations =
|
485
|
+
parcellations = ParcellationRegistry().list
|
492
486
|
assert "TianxS1x3TxMNInonlinear2009cAsym" in parcellations
|
493
487
|
assert "TianxS2x3TxMNInonlinear2009cAsym" in parcellations
|
494
488
|
assert "TianxS3x3TxMNInonlinear2009cAsym" in parcellations
|
495
489
|
assert "TianxS4x3TxMNInonlinear2009cAsym" in parcellations
|
496
490
|
# Load parcellation
|
497
|
-
img, lbl, fname, space =
|
491
|
+
img, lbl, fname, space = ParcellationRegistry().load(
|
498
492
|
name=f"TianxS{scale}x3TxMNInonlinear2009cAsym",
|
499
493
|
parcellations_dir=tmp_path,
|
500
494
|
)
|
@@ -524,13 +518,13 @@ def test_tian_7T_6thgeneration(
|
|
524
518
|
The parametrized n_label values.
|
525
519
|
|
526
520
|
"""
|
527
|
-
parcellations =
|
521
|
+
parcellations = ParcellationRegistry().list
|
528
522
|
assert "TianxS1x7TxMNI6thgeneration" in parcellations
|
529
523
|
assert "TianxS2x7TxMNI6thgeneration" in parcellations
|
530
524
|
assert "TianxS3x7TxMNI6thgeneration" in parcellations
|
531
525
|
assert "TianxS4x7TxMNI6thgeneration" in parcellations
|
532
526
|
# Load parcellation
|
533
|
-
img, lbl, fname, space =
|
527
|
+
img, lbl, fname, space = ParcellationRegistry().load(
|
534
528
|
name=f"TianxS{scale}x7TxMNI6thgeneration", parcellations_dir=tmp_path
|
535
529
|
)
|
536
530
|
fname1 = f"Tian_Subcortex_S{scale}_7T.nii.gz"
|
@@ -615,10 +609,9 @@ def test_aicha(tmp_path: Path, version: int) -> None:
|
|
615
609
|
The parametrized version values.
|
616
610
|
|
617
611
|
"""
|
618
|
-
|
619
|
-
assert f"AICHA_v{version}" in parcellations
|
612
|
+
assert f"AICHA_v{version}" in ParcellationRegistry().list
|
620
613
|
# Load parcellation
|
621
|
-
img, label, img_path, space =
|
614
|
+
img, label, img_path, space = ParcellationRegistry().load(
|
622
615
|
name=f"AICHA_v{version}", parcellations_dir=tmp_path
|
623
616
|
)
|
624
617
|
assert img is not None
|
@@ -684,10 +677,9 @@ def test_shen(
|
|
684
677
|
The parametrized partial file names.
|
685
678
|
|
686
679
|
"""
|
687
|
-
|
688
|
-
assert f"Shen_{year}_{n_rois}" in parcellations
|
680
|
+
assert f"Shen_{year}_{n_rois}" in ParcellationRegistry().list
|
689
681
|
# Load parcellation
|
690
|
-
img, label, img_path, space =
|
682
|
+
img, label, img_path, space = ParcellationRegistry().load(
|
691
683
|
name=f"Shen_{year}_{n_rois}",
|
692
684
|
parcellations_dir=tmp_path,
|
693
685
|
resolution=resolution,
|
@@ -867,7 +859,7 @@ def test_yan(
|
|
867
859
|
The parametrized Kong networks values.
|
868
860
|
|
869
861
|
"""
|
870
|
-
parcellations =
|
862
|
+
parcellations = ParcellationRegistry().list
|
871
863
|
if yeo_networks:
|
872
864
|
parcellation_name = f"Yan{n_rois}xYeo{yeo_networks}"
|
873
865
|
assert parcellation_name in parcellations
|
@@ -883,7 +875,7 @@ def test_yan(
|
|
883
875
|
f"{int(resolution)}mm.nii.gz"
|
884
876
|
)
|
885
877
|
# Load parcellation
|
886
|
-
img, label, img_path, space =
|
878
|
+
img, label, img_path, space = ParcellationRegistry().load(
|
887
879
|
name=parcellation_name, # type: ignore
|
888
880
|
parcellations_dir=tmp_path,
|
889
881
|
resolution=resolution,
|
@@ -1009,7 +1001,7 @@ def test_brainnetome(
|
|
1009
1001
|
The parametrized threshold values.
|
1010
1002
|
|
1011
1003
|
"""
|
1012
|
-
parcellations =
|
1004
|
+
parcellations = ParcellationRegistry().list
|
1013
1005
|
parcellation_name = f"Brainnetome_thr{threshold}"
|
1014
1006
|
assert parcellation_name in parcellations
|
1015
1007
|
|
@@ -1019,7 +1011,7 @@ def test_brainnetome(
|
|
1019
1011
|
|
1020
1012
|
parcellation_file = f"BNA-maxprob-thr{threshold}-{resolution}mm.nii.gz"
|
1021
1013
|
# Load parcellation
|
1022
|
-
img, label, img_path, space =
|
1014
|
+
img, label, img_path, space = ParcellationRegistry().load(
|
1023
1015
|
name=parcellation_name,
|
1024
1016
|
parcellations_dir=tmp_path,
|
1025
1017
|
resolution=resolution,
|
@@ -1052,10 +1044,10 @@ def test_retrieve_brainnetome_incorrect_threshold(tmp_path: Path) -> None:
|
|
1052
1044
|
def test_merge_parcellations() -> None:
|
1053
1045
|
"""Test merging parcellations."""
|
1054
1046
|
# load some parcellations for testing
|
1055
|
-
schaefer_parcellation, schaefer_labels, _, _ =
|
1047
|
+
schaefer_parcellation, schaefer_labels, _, _ = ParcellationRegistry().load(
|
1056
1048
|
"Schaefer100x17"
|
1057
1049
|
)
|
1058
|
-
tian_parcellation, tian_labels, _, _ =
|
1050
|
+
tian_parcellation, tian_labels, _, _ = ParcellationRegistry().load(
|
1059
1051
|
"TianxS2x3TxMNInonlinear2009cAsym"
|
1060
1052
|
)
|
1061
1053
|
# prepare the list of the actual parcellations
|
@@ -1088,7 +1080,7 @@ def test_merge_parcellations_3D_multiple_non_overlapping(
|
|
1088
1080
|
|
1089
1081
|
"""
|
1090
1082
|
# Get the testing parcellation
|
1091
|
-
parcellation, labels, _, _ =
|
1083
|
+
parcellation, labels, _, _ = ParcellationRegistry().load("Schaefer100x7")
|
1092
1084
|
|
1093
1085
|
assert parcellation is not None
|
1094
1086
|
|
@@ -1123,7 +1115,7 @@ def test_merge_parcellations_3D_multiple_overlapping() -> None:
|
|
1123
1115
|
"""Test merge_parcellations with multiple overlapping parcellations."""
|
1124
1116
|
|
1125
1117
|
# Get the testing parcellation
|
1126
|
-
parcellation, labels, _, _ =
|
1118
|
+
parcellation, labels, _, _ = ParcellationRegistry().load("Schaefer100x7")
|
1127
1119
|
|
1128
1120
|
assert parcellation is not None
|
1129
1121
|
|
@@ -1147,9 +1139,7 @@ def test_merge_parcellations_3D_multiple_overlapping() -> None:
|
|
1147
1139
|
labels_lists = [labels1, labels2]
|
1148
1140
|
|
1149
1141
|
with pytest.warns(RuntimeWarning, match="overlapping voxels"):
|
1150
|
-
|
1151
|
-
parcellation_list, names, labels_lists
|
1152
|
-
)
|
1142
|
+
merge_parcellations(parcellation_list, names, labels_lists)
|
1153
1143
|
|
1154
1144
|
parc_data = parcellation.get_fdata()
|
1155
1145
|
assert len(labels) == 100
|
@@ -1160,7 +1150,7 @@ def test_merge_parcellations_3D_multiple_duplicated_labels() -> None:
|
|
1160
1150
|
"""Test merge_parcellations with duplicated labels."""
|
1161
1151
|
|
1162
1152
|
# Get the testing parcellation
|
1163
|
-
parcellation, labels, _, _ =
|
1153
|
+
parcellation, labels, _, _ = ParcellationRegistry().load("Schaefer100x7")
|
1164
1154
|
|
1165
1155
|
assert parcellation is not None
|
1166
1156
|
|
@@ -1182,7 +1172,7 @@ def test_merge_parcellations_3D_multiple_duplicated_labels() -> None:
|
|
1182
1172
|
labels_lists = [labels1, labels2]
|
1183
1173
|
|
1184
1174
|
with pytest.warns(RuntimeWarning, match="duplicated labels."):
|
1185
|
-
merged_parc,
|
1175
|
+
merged_parc, _ = merge_parcellations(
|
1186
1176
|
parcellation_list, names, labels_lists
|
1187
1177
|
)
|
1188
1178
|
|
@@ -1192,22 +1182,22 @@ def test_merge_parcellations_3D_multiple_duplicated_labels() -> None:
|
|
1192
1182
|
assert len(np.unique(parc_data)) == 101 # 100 + 1 because background 0
|
1193
1183
|
|
1194
1184
|
|
1195
|
-
def
|
1185
|
+
def test_get_single() -> None:
|
1196
1186
|
"""Test tailored single parcellation fetch."""
|
1197
1187
|
with PartlyCloudyTestingDataGrabber() as dg:
|
1198
1188
|
element_data = DefaultDataReader().fit_transform(dg["sub-01"])
|
1199
1189
|
bold = element_data["BOLD"]
|
1200
1190
|
bold_img = bold["data"]
|
1201
1191
|
# Get tailored parcellation
|
1202
|
-
tailored_parcellation, tailored_labels =
|
1203
|
-
|
1192
|
+
tailored_parcellation, tailored_labels = ParcellationRegistry().get(
|
1193
|
+
parcellations=["TianxS1x3TxMNInonlinear2009cAsym"],
|
1204
1194
|
target_data=bold,
|
1205
1195
|
)
|
1206
1196
|
# Check shape and affine with original element data
|
1207
1197
|
assert tailored_parcellation.shape == bold_img.shape[:3]
|
1208
1198
|
assert_array_equal(tailored_parcellation.affine, bold_img.affine)
|
1209
1199
|
# Get raw parcellation
|
1210
|
-
raw_parcellation, raw_labels, _, _ =
|
1200
|
+
raw_parcellation, raw_labels, _, _ = ParcellationRegistry().load(
|
1211
1201
|
"TianxS1x3TxMNInonlinear2009cAsym",
|
1212
1202
|
resolution=1.5,
|
1213
1203
|
)
|
@@ -1225,15 +1215,15 @@ def test_get_parcellation_single() -> None:
|
|
1225
1215
|
assert tailored_labels == raw_labels
|
1226
1216
|
|
1227
1217
|
|
1228
|
-
def
|
1218
|
+
def test_get_multi_same_space() -> None:
|
1229
1219
|
"""Test tailored multi parcellation fetch in same space."""
|
1230
1220
|
with PartlyCloudyTestingDataGrabber() as dg:
|
1231
1221
|
element_data = DefaultDataReader().fit_transform(dg["sub-01"])
|
1232
1222
|
bold = element_data["BOLD"]
|
1233
1223
|
bold_img = bold["data"]
|
1234
1224
|
# Get tailored parcellation
|
1235
|
-
tailored_parcellation, tailored_labels =
|
1236
|
-
|
1225
|
+
tailored_parcellation, tailored_labels = ParcellationRegistry().get(
|
1226
|
+
parcellations=[
|
1237
1227
|
"Shen_2015_268",
|
1238
1228
|
"TianxS1x3TxMNInonlinear2009cAsym",
|
1239
1229
|
],
|
@@ -1250,7 +1240,9 @@ def test_get_parcellation_multi_same_space() -> None:
|
|
1250
1240
|
"TianxS1x3TxMNInonlinear2009cAsym",
|
1251
1241
|
]
|
1252
1242
|
for name in parcellations_names:
|
1253
|
-
img, labels, _, _ =
|
1243
|
+
img, labels, _, _ = ParcellationRegistry().load(
|
1244
|
+
name=name, resolution=1.5
|
1245
|
+
)
|
1254
1246
|
# Resample raw parcellations
|
1255
1247
|
resampled_img = resample_to_img(
|
1256
1248
|
source_img=img,
|
@@ -1277,13 +1269,13 @@ def test_get_parcellation_multi_same_space() -> None:
|
|
1277
1269
|
@pytest.mark.skipif(
|
1278
1270
|
_check_ants() is False, reason="requires ANTs to be in PATH"
|
1279
1271
|
)
|
1280
|
-
def
|
1272
|
+
def test_get_multi_different_space() -> None:
|
1281
1273
|
"""Test tailored multi parcellation fetch in different space."""
|
1282
1274
|
with OasisVBMTestingDataGrabber() as dg:
|
1283
1275
|
element_data = DefaultDataReader().fit_transform(dg["sub-01"])
|
1284
1276
|
# Get tailored parcellation
|
1285
|
-
|
1286
|
-
|
1277
|
+
ParcellationRegistry().get(
|
1278
|
+
parcellations=[
|
1287
1279
|
"Schaefer100x7",
|
1288
1280
|
"TianxS1x3TxMNInonlinear2009cAsym",
|
1289
1281
|
],
|
@@ -0,0 +1,74 @@
|
|
1
|
+
"""Provide abstract base class for pipeline data registry."""
|
2
|
+
|
3
|
+
# Authors: Synchon Mandal <s.mandal@fz-juelich.de>
|
4
|
+
# License: AGPL
|
5
|
+
|
6
|
+
from abc import ABC, abstractmethod
|
7
|
+
from typing import Any, List, Mapping
|
8
|
+
|
9
|
+
from ..utils import raise_error
|
10
|
+
|
11
|
+
|
12
|
+
__all__ = ["BasePipelineDataRegistry"]
|
13
|
+
|
14
|
+
|
15
|
+
class BasePipelineDataRegistry(ABC):
|
16
|
+
"""Abstract base class for pipeline data registry.
|
17
|
+
|
18
|
+
For every interface that is required, one needs to provide a concrete
|
19
|
+
implementation for this abstract class.
|
20
|
+
|
21
|
+
Attributes
|
22
|
+
----------
|
23
|
+
registry : dict
|
24
|
+
Registry of available pipeline data.
|
25
|
+
list : dict
|
26
|
+
Keys of available pipeline data registry.
|
27
|
+
|
28
|
+
"""
|
29
|
+
|
30
|
+
def __init__(self) -> None:
|
31
|
+
"""Initialize the class."""
|
32
|
+
self._registry: Mapping[str, Any] = {}
|
33
|
+
|
34
|
+
@property
|
35
|
+
def data(self) -> Mapping[str, Any]:
|
36
|
+
"""Get available pipeline data."""
|
37
|
+
return self._registry
|
38
|
+
|
39
|
+
@property
|
40
|
+
def list(self) -> List[str]:
|
41
|
+
"""List available pipeline data keys."""
|
42
|
+
return sorted(self._registry.keys())
|
43
|
+
|
44
|
+
@abstractmethod
|
45
|
+
def register(self) -> None:
|
46
|
+
"""Register data."""
|
47
|
+
raise_error(
|
48
|
+
msg="Concrete classes need to implement register().",
|
49
|
+
klass=NotImplementedError,
|
50
|
+
)
|
51
|
+
|
52
|
+
@abstractmethod
|
53
|
+
def deregister(self) -> None:
|
54
|
+
"""De-register data."""
|
55
|
+
raise_error(
|
56
|
+
msg="Concrete classes need to implement deregister().",
|
57
|
+
klass=NotImplementedError,
|
58
|
+
)
|
59
|
+
|
60
|
+
@abstractmethod
|
61
|
+
def load(self) -> Any:
|
62
|
+
"""Load data."""
|
63
|
+
raise_error(
|
64
|
+
msg="Concrete classes need to implement load().",
|
65
|
+
klass=NotImplementedError,
|
66
|
+
)
|
67
|
+
|
68
|
+
@abstractmethod
|
69
|
+
def get(self) -> Any:
|
70
|
+
"""Get tailored data for a target."""
|
71
|
+
raise_error(
|
72
|
+
msg="Concrete classes need to implement get().",
|
73
|
+
klass=NotImplementedError,
|
74
|
+
)
|
junifer/data/utils.py
CHANGED
@@ -24,8 +24,8 @@ class HurstExponent(ComplexityBase):
|
|
24
24
|
Parameters
|
25
25
|
----------
|
26
26
|
parcellation : str or list of str
|
27
|
-
The name(s) of the parcellation(s)
|
28
|
-
:func
|
27
|
+
The name(s) of the parcellation(s) to use.
|
28
|
+
See :func:`.list_data` for options.
|
29
29
|
agg_method : str, optional
|
30
30
|
The method to perform aggregation using. Check valid options in
|
31
31
|
:func:`junifer.stats.get_aggfunc_by_name` (default "mean").
|
@@ -24,8 +24,8 @@ class MultiscaleEntropyAUC(ComplexityBase):
|
|
24
24
|
Parameters
|
25
25
|
----------
|
26
26
|
parcellation : str or list of str
|
27
|
-
The name(s) of the parcellation(s)
|
28
|
-
:func
|
27
|
+
The name(s) of the parcellation(s) to use.
|
28
|
+
See :func:`.list_data` for options.
|
29
29
|
agg_method : str, optional
|
30
30
|
The method to perform aggregation using. Check valid options in
|
31
31
|
:func:`junifer.stats.get_aggfunc_by_name` (default "mean").
|
@@ -24,8 +24,8 @@ class PermEntropy(ComplexityBase):
|
|
24
24
|
Parameters
|
25
25
|
----------
|
26
26
|
parcellation : str or list of str
|
27
|
-
The name(s) of the parcellation(s)
|
28
|
-
:func
|
27
|
+
The name(s) of the parcellation(s) to use.
|
28
|
+
See :func:`.list_data` for options.
|
29
29
|
agg_method : str, optional
|
30
30
|
The method to perform aggregation using. Check valid options in
|
31
31
|
:func:`junifer.stats.get_aggfunc_by_name` (default "mean").
|
@@ -24,8 +24,8 @@ class RangeEntropy(ComplexityBase):
|
|
24
24
|
Parameters
|
25
25
|
----------
|
26
26
|
parcellation : str or list of str
|
27
|
-
The name(s) of the parcellation(s)
|
28
|
-
:func
|
27
|
+
The name(s) of the parcellation(s) to use.
|
28
|
+
See :func:`.list_data` for options.
|
29
29
|
agg_method : str, optional
|
30
30
|
The method to perform aggregation using. Check valid options in
|
31
31
|
:func:`junifer.stats.get_aggfunc_by_name` (default "mean").
|
@@ -24,8 +24,8 @@ class RangeEntropyAUC(ComplexityBase):
|
|
24
24
|
Parameters
|
25
25
|
----------
|
26
26
|
parcellation : str or list of str
|
27
|
-
The name(s) of the parcellation(s)
|
28
|
-
:func
|
27
|
+
The name(s) of the parcellation(s) to use.
|
28
|
+
See :func:`.list_data` for options.
|
29
29
|
agg_method : str, optional
|
30
30
|
The method to perform aggregation using. Check valid options in
|
31
31
|
:func:`junifer.stats.get_aggfunc_by_name` (default "mean").
|
@@ -24,8 +24,8 @@ class SampleEntropy(ComplexityBase):
|
|
24
24
|
Parameters
|
25
25
|
----------
|
26
26
|
parcellation : str or list of str
|
27
|
-
The name(s) of the parcellation(s)
|
28
|
-
:func
|
27
|
+
The name(s) of the parcellation(s) to use.
|
28
|
+
See :func:`.list_data` for options.
|
29
29
|
agg_method : str, optional
|
30
30
|
The method to perform aggregation using. Check valid options in
|
31
31
|
:func:`junifer.stats.get_aggfunc_by_name` (default "mean").
|
@@ -24,8 +24,8 @@ class WeightedPermEntropy(ComplexityBase):
|
|
24
24
|
Parameters
|
25
25
|
----------
|
26
26
|
parcellation : str or list of str
|
27
|
-
The name(s) of the parcellation(s)
|
28
|
-
:func
|
27
|
+
The name(s) of the parcellation(s) to use.
|
28
|
+
See :func:`.list_data` for options.
|
29
29
|
agg_method : str, optional
|
30
30
|
The method to perform aggregation using. Check valid options in
|
31
31
|
:func:`junifer.stats.get_aggfunc_by_name` (default "mean").
|