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.
Files changed (279) hide show
  1. junifer/__init__.py +2 -31
  2. junifer/__init__.pyi +37 -0
  3. junifer/_version.py +9 -4
  4. junifer/api/__init__.py +3 -5
  5. junifer/api/__init__.pyi +4 -0
  6. junifer/api/decorators.py +14 -19
  7. junifer/api/functions.py +165 -109
  8. junifer/api/py.typed +0 -0
  9. junifer/api/queue_context/__init__.py +2 -4
  10. junifer/api/queue_context/__init__.pyi +5 -0
  11. junifer/api/queue_context/gnu_parallel_local_adapter.py +22 -6
  12. junifer/api/queue_context/htcondor_adapter.py +23 -6
  13. junifer/api/queue_context/py.typed +0 -0
  14. junifer/api/queue_context/tests/test_gnu_parallel_local_adapter.py +3 -3
  15. junifer/api/queue_context/tests/test_htcondor_adapter.py +3 -3
  16. junifer/api/tests/test_functions.py +168 -74
  17. junifer/cli/__init__.py +24 -0
  18. junifer/cli/__init__.pyi +3 -0
  19. junifer/{api → cli}/cli.py +141 -125
  20. junifer/cli/parser.py +235 -0
  21. junifer/cli/py.typed +0 -0
  22. junifer/{api → cli}/tests/test_cli.py +8 -8
  23. junifer/{api/tests/test_api_utils.py → cli/tests/test_cli_utils.py} +5 -4
  24. junifer/{api → cli}/tests/test_parser.py +2 -2
  25. junifer/{api → cli}/utils.py +6 -16
  26. junifer/configs/juseless/__init__.py +2 -2
  27. junifer/configs/juseless/__init__.pyi +3 -0
  28. junifer/configs/juseless/datagrabbers/__init__.py +2 -12
  29. junifer/configs/juseless/datagrabbers/__init__.pyi +13 -0
  30. junifer/configs/juseless/datagrabbers/ixi_vbm.py +2 -2
  31. junifer/configs/juseless/datagrabbers/py.typed +0 -0
  32. junifer/configs/juseless/datagrabbers/tests/test_ucla.py +2 -2
  33. junifer/configs/juseless/datagrabbers/ucla.py +4 -4
  34. junifer/configs/juseless/py.typed +0 -0
  35. junifer/conftest.py +25 -0
  36. junifer/data/__init__.py +2 -42
  37. junifer/data/__init__.pyi +29 -0
  38. junifer/data/_dispatch.py +248 -0
  39. junifer/data/coordinates/__init__.py +9 -0
  40. junifer/data/coordinates/__init__.pyi +5 -0
  41. junifer/data/coordinates/_ants_coordinates_warper.py +104 -0
  42. junifer/data/coordinates/_coordinates.py +385 -0
  43. junifer/data/coordinates/_fsl_coordinates_warper.py +81 -0
  44. junifer/data/{tests → coordinates/tests}/test_coordinates.py +26 -33
  45. junifer/data/masks/__init__.py +9 -0
  46. junifer/data/masks/__init__.pyi +6 -0
  47. junifer/data/masks/_ants_mask_warper.py +177 -0
  48. junifer/data/masks/_fsl_mask_warper.py +106 -0
  49. junifer/data/masks/_masks.py +802 -0
  50. junifer/data/{tests → masks/tests}/test_masks.py +67 -63
  51. junifer/data/parcellations/__init__.py +9 -0
  52. junifer/data/parcellations/__init__.pyi +6 -0
  53. junifer/data/parcellations/_ants_parcellation_warper.py +166 -0
  54. junifer/data/parcellations/_fsl_parcellation_warper.py +89 -0
  55. junifer/data/parcellations/_parcellations.py +1388 -0
  56. junifer/data/{tests → parcellations/tests}/test_parcellations.py +165 -295
  57. junifer/data/pipeline_data_registry_base.py +76 -0
  58. junifer/data/py.typed +0 -0
  59. junifer/data/template_spaces.py +44 -79
  60. junifer/data/tests/test_data_utils.py +1 -2
  61. junifer/data/tests/test_template_spaces.py +8 -4
  62. junifer/data/utils.py +109 -4
  63. junifer/datagrabber/__init__.py +2 -26
  64. junifer/datagrabber/__init__.pyi +27 -0
  65. junifer/datagrabber/aomic/__init__.py +2 -4
  66. junifer/datagrabber/aomic/__init__.pyi +5 -0
  67. junifer/datagrabber/aomic/id1000.py +81 -52
  68. junifer/datagrabber/aomic/piop1.py +83 -55
  69. junifer/datagrabber/aomic/piop2.py +85 -56
  70. junifer/datagrabber/aomic/py.typed +0 -0
  71. junifer/datagrabber/aomic/tests/test_id1000.py +19 -12
  72. junifer/datagrabber/aomic/tests/test_piop1.py +52 -18
  73. junifer/datagrabber/aomic/tests/test_piop2.py +50 -17
  74. junifer/datagrabber/base.py +22 -18
  75. junifer/datagrabber/datalad_base.py +71 -34
  76. junifer/datagrabber/dmcc13_benchmark.py +31 -18
  77. junifer/datagrabber/hcp1200/__init__.py +2 -3
  78. junifer/datagrabber/hcp1200/__init__.pyi +4 -0
  79. junifer/datagrabber/hcp1200/datalad_hcp1200.py +3 -3
  80. junifer/datagrabber/hcp1200/hcp1200.py +26 -15
  81. junifer/datagrabber/hcp1200/py.typed +0 -0
  82. junifer/datagrabber/hcp1200/tests/test_hcp1200.py +8 -2
  83. junifer/datagrabber/multiple.py +14 -9
  84. junifer/datagrabber/pattern.py +132 -96
  85. junifer/datagrabber/pattern_validation_mixin.py +206 -94
  86. junifer/datagrabber/py.typed +0 -0
  87. junifer/datagrabber/tests/test_datalad_base.py +27 -12
  88. junifer/datagrabber/tests/test_dmcc13_benchmark.py +28 -11
  89. junifer/datagrabber/tests/test_multiple.py +48 -2
  90. junifer/datagrabber/tests/test_pattern_datalad.py +1 -1
  91. junifer/datagrabber/tests/test_pattern_validation_mixin.py +6 -6
  92. junifer/datareader/__init__.py +2 -2
  93. junifer/datareader/__init__.pyi +3 -0
  94. junifer/datareader/default.py +6 -6
  95. junifer/datareader/py.typed +0 -0
  96. junifer/external/nilearn/__init__.py +2 -3
  97. junifer/external/nilearn/__init__.pyi +4 -0
  98. junifer/external/nilearn/junifer_connectivity_measure.py +25 -17
  99. junifer/external/nilearn/junifer_nifti_spheres_masker.py +4 -4
  100. junifer/external/nilearn/py.typed +0 -0
  101. junifer/external/nilearn/tests/test_junifer_connectivity_measure.py +17 -16
  102. junifer/external/nilearn/tests/test_junifer_nifti_spheres_masker.py +2 -3
  103. junifer/markers/__init__.py +2 -38
  104. junifer/markers/__init__.pyi +37 -0
  105. junifer/markers/base.py +11 -14
  106. junifer/markers/brainprint.py +12 -14
  107. junifer/markers/complexity/__init__.py +2 -18
  108. junifer/markers/complexity/__init__.pyi +17 -0
  109. junifer/markers/complexity/complexity_base.py +9 -11
  110. junifer/markers/complexity/hurst_exponent.py +7 -7
  111. junifer/markers/complexity/multiscale_entropy_auc.py +7 -7
  112. junifer/markers/complexity/perm_entropy.py +7 -7
  113. junifer/markers/complexity/py.typed +0 -0
  114. junifer/markers/complexity/range_entropy.py +7 -7
  115. junifer/markers/complexity/range_entropy_auc.py +7 -7
  116. junifer/markers/complexity/sample_entropy.py +7 -7
  117. junifer/markers/complexity/tests/test_complexity_base.py +1 -1
  118. junifer/markers/complexity/tests/test_hurst_exponent.py +5 -5
  119. junifer/markers/complexity/tests/test_multiscale_entropy_auc.py +5 -5
  120. junifer/markers/complexity/tests/test_perm_entropy.py +5 -5
  121. junifer/markers/complexity/tests/test_range_entropy.py +5 -5
  122. junifer/markers/complexity/tests/test_range_entropy_auc.py +5 -5
  123. junifer/markers/complexity/tests/test_sample_entropy.py +5 -5
  124. junifer/markers/complexity/tests/test_weighted_perm_entropy.py +5 -5
  125. junifer/markers/complexity/weighted_perm_entropy.py +7 -7
  126. junifer/markers/ets_rss.py +12 -11
  127. junifer/markers/falff/__init__.py +2 -3
  128. junifer/markers/falff/__init__.pyi +4 -0
  129. junifer/markers/falff/_afni_falff.py +38 -45
  130. junifer/markers/falff/_junifer_falff.py +16 -19
  131. junifer/markers/falff/falff_base.py +7 -11
  132. junifer/markers/falff/falff_parcels.py +9 -9
  133. junifer/markers/falff/falff_spheres.py +8 -8
  134. junifer/markers/falff/py.typed +0 -0
  135. junifer/markers/falff/tests/test_falff_spheres.py +3 -1
  136. junifer/markers/functional_connectivity/__init__.py +2 -12
  137. junifer/markers/functional_connectivity/__init__.pyi +13 -0
  138. junifer/markers/functional_connectivity/crossparcellation_functional_connectivity.py +9 -8
  139. junifer/markers/functional_connectivity/edge_functional_connectivity_parcels.py +8 -8
  140. junifer/markers/functional_connectivity/edge_functional_connectivity_spheres.py +7 -7
  141. junifer/markers/functional_connectivity/functional_connectivity_base.py +13 -12
  142. junifer/markers/functional_connectivity/functional_connectivity_parcels.py +8 -8
  143. junifer/markers/functional_connectivity/functional_connectivity_spheres.py +7 -7
  144. junifer/markers/functional_connectivity/py.typed +0 -0
  145. junifer/markers/functional_connectivity/tests/test_edge_functional_connectivity_parcels.py +1 -2
  146. junifer/markers/functional_connectivity/tests/test_edge_functional_connectivity_spheres.py +1 -2
  147. junifer/markers/functional_connectivity/tests/test_functional_connectivity_parcels.py +6 -6
  148. junifer/markers/functional_connectivity/tests/test_functional_connectivity_spheres.py +5 -5
  149. junifer/markers/parcel_aggregation.py +22 -17
  150. junifer/markers/py.typed +0 -0
  151. junifer/markers/reho/__init__.py +2 -3
  152. junifer/markers/reho/__init__.pyi +4 -0
  153. junifer/markers/reho/_afni_reho.py +29 -35
  154. junifer/markers/reho/_junifer_reho.py +13 -14
  155. junifer/markers/reho/py.typed +0 -0
  156. junifer/markers/reho/reho_base.py +7 -11
  157. junifer/markers/reho/reho_parcels.py +10 -10
  158. junifer/markers/reho/reho_spheres.py +9 -9
  159. junifer/markers/sphere_aggregation.py +22 -17
  160. junifer/markers/temporal_snr/__init__.py +2 -3
  161. junifer/markers/temporal_snr/__init__.pyi +4 -0
  162. junifer/markers/temporal_snr/py.typed +0 -0
  163. junifer/markers/temporal_snr/temporal_snr_base.py +11 -10
  164. junifer/markers/temporal_snr/temporal_snr_parcels.py +8 -8
  165. junifer/markers/temporal_snr/temporal_snr_spheres.py +7 -7
  166. junifer/markers/tests/test_ets_rss.py +3 -3
  167. junifer/markers/tests/test_parcel_aggregation.py +24 -24
  168. junifer/markers/tests/test_sphere_aggregation.py +6 -6
  169. junifer/markers/utils.py +3 -3
  170. junifer/onthefly/__init__.py +2 -1
  171. junifer/onthefly/_brainprint.py +138 -0
  172. junifer/onthefly/read_transform.py +5 -8
  173. junifer/pipeline/__init__.py +2 -10
  174. junifer/pipeline/__init__.pyi +13 -0
  175. junifer/{markers/collection.py → pipeline/marker_collection.py} +8 -14
  176. junifer/pipeline/pipeline_component_registry.py +294 -0
  177. junifer/pipeline/pipeline_step_mixin.py +15 -11
  178. junifer/pipeline/py.typed +0 -0
  179. junifer/{markers/tests/test_collection.py → pipeline/tests/test_marker_collection.py} +2 -3
  180. junifer/pipeline/tests/test_pipeline_component_registry.py +200 -0
  181. junifer/pipeline/tests/test_pipeline_step_mixin.py +36 -37
  182. junifer/pipeline/tests/test_update_meta_mixin.py +4 -4
  183. junifer/pipeline/tests/test_workdir_manager.py +43 -0
  184. junifer/pipeline/update_meta_mixin.py +21 -17
  185. junifer/pipeline/utils.py +6 -6
  186. junifer/pipeline/workdir_manager.py +19 -5
  187. junifer/preprocess/__init__.py +2 -10
  188. junifer/preprocess/__init__.pyi +11 -0
  189. junifer/preprocess/base.py +10 -10
  190. junifer/preprocess/confounds/__init__.py +2 -2
  191. junifer/preprocess/confounds/__init__.pyi +3 -0
  192. junifer/preprocess/confounds/fmriprep_confound_remover.py +243 -64
  193. junifer/preprocess/confounds/py.typed +0 -0
  194. junifer/preprocess/confounds/tests/test_fmriprep_confound_remover.py +121 -14
  195. junifer/preprocess/py.typed +0 -0
  196. junifer/preprocess/smoothing/__init__.py +2 -2
  197. junifer/preprocess/smoothing/__init__.pyi +3 -0
  198. junifer/preprocess/smoothing/_afni_smoothing.py +40 -40
  199. junifer/preprocess/smoothing/_fsl_smoothing.py +22 -32
  200. junifer/preprocess/smoothing/_nilearn_smoothing.py +35 -14
  201. junifer/preprocess/smoothing/py.typed +0 -0
  202. junifer/preprocess/smoothing/smoothing.py +11 -13
  203. junifer/preprocess/warping/__init__.py +2 -2
  204. junifer/preprocess/warping/__init__.pyi +3 -0
  205. junifer/preprocess/warping/_ants_warper.py +136 -32
  206. junifer/preprocess/warping/_fsl_warper.py +73 -22
  207. junifer/preprocess/warping/py.typed +0 -0
  208. junifer/preprocess/warping/space_warper.py +39 -11
  209. junifer/preprocess/warping/tests/test_space_warper.py +5 -9
  210. junifer/py.typed +0 -0
  211. junifer/stats.py +5 -5
  212. junifer/storage/__init__.py +2 -10
  213. junifer/storage/__init__.pyi +11 -0
  214. junifer/storage/base.py +47 -13
  215. junifer/storage/hdf5.py +95 -33
  216. junifer/storage/pandas_base.py +12 -11
  217. junifer/storage/py.typed +0 -0
  218. junifer/storage/sqlite.py +11 -11
  219. junifer/storage/tests/test_hdf5.py +86 -4
  220. junifer/storage/tests/test_sqlite.py +2 -2
  221. junifer/storage/tests/test_storage_base.py +5 -2
  222. junifer/storage/tests/test_utils.py +33 -7
  223. junifer/storage/utils.py +95 -9
  224. junifer/testing/__init__.py +2 -3
  225. junifer/testing/__init__.pyi +4 -0
  226. junifer/testing/datagrabbers.py +10 -11
  227. junifer/testing/py.typed +0 -0
  228. junifer/testing/registry.py +4 -7
  229. junifer/testing/tests/test_testing_registry.py +9 -17
  230. junifer/tests/test_stats.py +2 -2
  231. junifer/typing/__init__.py +9 -0
  232. junifer/typing/__init__.pyi +31 -0
  233. junifer/typing/_typing.py +68 -0
  234. junifer/utils/__init__.py +2 -12
  235. junifer/utils/__init__.pyi +18 -0
  236. junifer/utils/_config.py +110 -0
  237. junifer/utils/_yaml.py +16 -0
  238. junifer/utils/helpers.py +6 -6
  239. junifer/utils/logging.py +117 -8
  240. junifer/utils/py.typed +0 -0
  241. junifer/{pipeline → utils}/singleton.py +19 -14
  242. junifer/utils/tests/test_config.py +59 -0
  243. {junifer-0.0.5.dev240.dist-info → junifer-0.0.6.dist-info}/METADATA +43 -38
  244. junifer-0.0.6.dist-info/RECORD +350 -0
  245. {junifer-0.0.5.dev240.dist-info → junifer-0.0.6.dist-info}/WHEEL +1 -1
  246. junifer-0.0.6.dist-info/entry_points.txt +2 -0
  247. junifer/api/parser.py +0 -118
  248. junifer/data/coordinates.py +0 -408
  249. junifer/data/masks.py +0 -670
  250. junifer/data/parcellations.py +0 -1828
  251. junifer/pipeline/registry.py +0 -177
  252. junifer/pipeline/tests/test_registry.py +0 -150
  253. junifer-0.0.5.dev240.dist-info/RECORD +0 -275
  254. junifer-0.0.5.dev240.dist-info/entry_points.txt +0 -2
  255. /junifer/{api → cli}/tests/data/gmd_mean.yaml +0 -0
  256. /junifer/{api → cli}/tests/data/gmd_mean_htcondor.yaml +0 -0
  257. /junifer/{api → cli}/tests/data/partly_cloudy_agg_mean_tian.yml +0 -0
  258. /junifer/data/{VOIs → coordinates/VOIs}/meta/AutobiographicalMemory_VOIs.txt +0 -0
  259. /junifer/data/{VOIs → coordinates/VOIs}/meta/CogAC_VOIs.txt +0 -0
  260. /junifer/data/{VOIs → coordinates/VOIs}/meta/CogAR_VOIs.txt +0 -0
  261. /junifer/data/{VOIs → coordinates/VOIs}/meta/DMNBuckner_VOIs.txt +0 -0
  262. /junifer/data/{VOIs → coordinates/VOIs}/meta/Dosenbach2010_MNI_VOIs.txt +0 -0
  263. /junifer/data/{VOIs → coordinates/VOIs}/meta/Empathy_VOIs.txt +0 -0
  264. /junifer/data/{VOIs → coordinates/VOIs}/meta/Motor_VOIs.txt +0 -0
  265. /junifer/data/{VOIs → coordinates/VOIs}/meta/MultiTask_VOIs.txt +0 -0
  266. /junifer/data/{VOIs → coordinates/VOIs}/meta/PhysioStress_VOIs.txt +0 -0
  267. /junifer/data/{VOIs → coordinates/VOIs}/meta/Power2011_MNI_VOIs.txt +0 -0
  268. /junifer/data/{VOIs → coordinates/VOIs}/meta/Power2013_MNI_VOIs.tsv +0 -0
  269. /junifer/data/{VOIs → coordinates/VOIs}/meta/Rew_VOIs.txt +0 -0
  270. /junifer/data/{VOIs → coordinates/VOIs}/meta/Somatosensory_VOIs.txt +0 -0
  271. /junifer/data/{VOIs → coordinates/VOIs}/meta/ToM_VOIs.txt +0 -0
  272. /junifer/data/{VOIs → coordinates/VOIs}/meta/VigAtt_VOIs.txt +0 -0
  273. /junifer/data/{VOIs → coordinates/VOIs}/meta/WM_VOIs.txt +0 -0
  274. /junifer/data/{VOIs → coordinates/VOIs}/meta/eMDN_VOIs.txt +0 -0
  275. /junifer/data/{VOIs → coordinates/VOIs}/meta/eSAD_VOIs.txt +0 -0
  276. /junifer/data/{VOIs → coordinates/VOIs}/meta/extDMN_VOIs.txt +0 -0
  277. {junifer-0.0.5.dev240.dist-info → junifer-0.0.6.dist-info/licenses}/AUTHORS.rst +0 -0
  278. {junifer-0.0.5.dev240.dist-info → junifer-0.0.6.dist-info/licenses}/LICENSE.md +0 -0
  279. {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.parcellations import (
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 test_register_parcellation_built_in_check() -> None:
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
- register_parcellation(
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 test_list_parcellations_incorrect() -> None:
47
+ def test_list_incorrect() -> None:
53
48
  """Test incorrect information check for list parcellations."""
54
- parcellations = list_parcellations()
55
- assert "testparc" not in parcellations
49
+ assert "testparc" not in ParcellationRegistry().list
56
50
 
57
51
 
58
- def test_register_parcellation_already_registered() -> None:
52
+ def test_register_already_registered() -> None:
59
53
  """Test parcellation registration check for already registered."""
60
54
  # Register custom parcellation
61
- register_parcellation(
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
- load_parcellation("testparc", path_only=True)[2].name
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
- register_parcellation(
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
- register_parcellation(
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
- load_parcellation("testparc", path_only=True)[2].name
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, _ = load_parcellation("Schaefer100x7")
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
- register_parcellation(
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
- load_parcellation("WrongLabels")
113
+ ParcellationRegistry().load("WrongLabels", "MNI152NLin6Asym")
113
114
 
114
115
  # Test wrong number of labels
115
- register_parcellation(
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
- load_parcellation("WrongLabels2")
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
- register_parcellation(
129
+ ParcellationRegistry().register(
129
130
  "WrongValues", new_schaefer_path, labels[:-1], "MNI152Lin"
130
131
  )
131
- with pytest.raises(ValueError, match=r"the range [0, 99]"):
132
- load_parcellation("WrongValues")
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
- register_parcellation(
141
+ ParcellationRegistry().register(
141
142
  "WrongValues2", new_schaefer_path, labels, "MNI152Lin"
142
143
  )
143
- with pytest.raises(ValueError, match=r"the range [0, 100]"):
144
- load_parcellation("WrongValues2")
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 test_register_parcellation(
174
+ def test_register(
174
175
  name: str,
175
176
  parcellation_path: str,
176
- parcels_labels: List[str],
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
- register_parcellation(
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
- parcellations = list_parcellations()
206
- assert name in parcellations
206
+ assert name in ParcellationRegistry().list
207
207
  # Load registered parcellation
208
- _, lbl, fname, parcellation_space = load_parcellation(
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 test_list_parcellations_correct(parcellation_name: str) -> None:
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
- parcellations = list_parcellations()
241
- assert parcellation_name in parcellations
240
+ assert parcellation_name in ParcellationRegistry().list
242
241
 
243
242
 
244
- def test_load_parcellation_incorrect() -> None:
243
+ def test_load_incorrect() -> None:
245
244
  """Test loading of invalid parcellations."""
246
245
  with pytest.raises(ValueError, match=r"not found"):
247
- load_parcellation("wrongparcellation")
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 parcellations
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 = load_parcellation(
319
+ img, label, img_path, space = ParcellationRegistry().load(
331
320
  name=parcellation_name,
332
- parcellations_dir=tmp_path,
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(tmp_path: Path) -> None:
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(tmp_path: Path) -> None:
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(tmp_path: Path, space_key: str, space: str) -> None:
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
- parcellations = list_parcellations()
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 = load_parcellation(
370
+ img, label, img_path, parcellation_space = ParcellationRegistry().load(
401
371
  name=f"SUITx{space_key}",
402
- parcellations_dir=tmp_path,
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(tmp_path: Path) -> None:
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 = list_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, parcellation_space_1 = load_parcellation(
451
- name=f"TianxS{scale}x3TxMNI6thgeneration", parcellations_dir=tmp_path
407
+ img, lbl, fname, space = ParcellationRegistry().load(
408
+ name=f"TianxS{scale}x3TxMNI6thgeneration",
409
+ target_space="MNI152NLin2009cAsym", # force highest resolution
452
410
  )
453
- fname1 = f"Tian_Subcortex_S{scale}_3T_1mm.nii.gz"
411
+ expected_fname = f"Tian_Subcortex_S{scale}_3T_1mm.nii.gz"
454
412
  assert img is not None
455
- assert fname.name == fname1
456
- assert parcellation_space_1 == "MNI152NLin6Asym"
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]) # type: ignore
416
+ assert_array_equal(img.header["pixdim"][1:4], [1, 1, 1])
459
417
  # Load parcellation
460
- img, lbl, fname, parcellation_space_2 = load_parcellation(
418
+ img, lbl, fname, space = ParcellationRegistry().load(
461
419
  name=f"TianxS{scale}x3TxMNI6thgeneration",
462
- parcellations_dir=tmp_path,
420
+ target_space="MNI152NLin6Asym",
463
421
  resolution=2,
464
422
  )
465
- fname1 = f"Tian_Subcortex_S{scale}_3T.nii.gz"
423
+ expected_fname = f"Tian_Subcortex_S{scale}_3T.nii.gz"
466
424
  assert img is not None
467
- assert fname.name == fname1
468
- assert parcellation_space_2 == "MNI152NLin6Asym"
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]) # type: ignore
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 = list_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 = load_parcellation(
451
+ img, lbl, fname, space = ParcellationRegistry().load(
498
452
  name=f"TianxS{scale}x3TxMNInonlinear2009cAsym",
499
- parcellations_dir=tmp_path,
453
+ target_space="MNI152NLin6Asym", # force highest resolution
500
454
  )
501
- fname1 = f"Tian_Subcortex_S{scale}_3T_2009cAsym.nii.gz"
455
+ expected_fname = f"Tian_Subcortex_S{scale}_3T_2009cAsym_1mm.nii.gz"
502
456
  assert img is not None
503
- assert fname.name == fname1
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], [2, 2, 2]) # type: ignore
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 = list_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 = load_parcellation(
534
- name=f"TianxS{scale}x7TxMNI6thgeneration", parcellations_dir=tmp_path
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(tmp_path: Path) -> None:
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(tmp_path: Path) -> None:
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(tmp_path: Path, version: int) -> None:
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
- parcellations = list_parcellations()
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 = load_parcellation(
622
- name=f"AICHA_v{version}", parcellations_dir=tmp_path
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(tmp_path: Path) -> None:
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
- parcellations = list_parcellations()
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 = load_parcellation(
615
+ img, label, img_path, space = ParcellationRegistry().load(
691
616
  name=f"Shen_{year}_{n_rois}",
692
- parcellations_dir=tmp_path,
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(tmp_path: Path) -> None:
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(tmp_path: Path) -> None:
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 = list_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 = load_parcellation(
887
- name=parcellation_name, # type: ignore
888
- parcellations_dir=tmp_path,
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(tmp_path: Path) -> None:
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(tmp_path: Path) -> None:
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(tmp_path: Path) -> None:
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(tmp_path: Path) -> None:
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 = list_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 = load_parcellation(
890
+ img, label, img_path, space = ParcellationRegistry().load(
1023
891
  name=parcellation_name,
1024
- parcellations_dir=tmp_path,
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(tmp_path: Path) -> None:
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, _, _ = load_parcellation(
1056
- "Schaefer100x17"
915
+ schaefer_parcellation, schaefer_labels, _, _ = ParcellationRegistry().load(
916
+ "Schaefer100x17", target_space="MNI152NLin2009cAsym"
1057
917
  )
1058
- tian_parcellation, tian_labels, _, _ = load_parcellation(
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, _, _ = load_parcellation("Schaefer100x7")
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, _, _ = load_parcellation("Schaefer100x7")
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
- merged_parc, merged_labels = merge_parcellations(
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, _, _ = load_parcellation("Schaefer100x7")
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, merged_labels = merge_parcellations(
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 test_get_parcellation_single() -> None:
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 = get_parcellation(
1203
- parcellation=["TianxS1x3TxMNInonlinear2009cAsym"],
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, _, _ = load_parcellation(
1211
- "TianxS1x3TxMNInonlinear2009cAsym",
1212
- resolution=1.5,
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 test_get_parcellation_multi_same_space() -> None:
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 = get_parcellation(
1236
- parcellation=[
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, _, _ = load_parcellation(name=name, resolution=1.5)
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 test_get_parcellation_multi_different_space() -> None:
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
- get_parcellation(
1286
- parcellation=[
1155
+ ParcellationRegistry().get(
1156
+ parcellations=[
1287
1157
  "Schaefer100x7",
1288
1158
  "TianxS1x3TxMNInonlinear2009cAsym",
1289
1159
  ],