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.
Files changed (90) hide show
  1. junifer/__init__.pyi +2 -0
  2. junifer/_version.py +2 -2
  3. junifer/api/decorators.py +6 -11
  4. junifer/api/functions.py +74 -62
  5. junifer/api/tests/test_functions.py +2 -2
  6. junifer/data/__init__.pyi +17 -31
  7. junifer/data/_dispatch.py +251 -0
  8. junifer/data/coordinates/__init__.py +9 -0
  9. junifer/data/coordinates/__init__.pyi +5 -0
  10. junifer/data/coordinates/_ants_coordinates_warper.py +96 -0
  11. junifer/data/coordinates/_coordinates.py +356 -0
  12. junifer/data/coordinates/_fsl_coordinates_warper.py +83 -0
  13. junifer/data/{tests → coordinates/tests}/test_coordinates.py +25 -31
  14. junifer/data/masks/__init__.py +9 -0
  15. junifer/data/masks/__init__.pyi +6 -0
  16. junifer/data/masks/_ants_mask_warper.py +144 -0
  17. junifer/data/masks/_fsl_mask_warper.py +87 -0
  18. junifer/data/masks/_masks.py +624 -0
  19. junifer/data/{tests → masks/tests}/test_masks.py +63 -58
  20. junifer/data/parcellations/__init__.py +9 -0
  21. junifer/data/parcellations/__init__.pyi +6 -0
  22. junifer/data/parcellations/_ants_parcellation_warper.py +154 -0
  23. junifer/data/parcellations/_fsl_parcellation_warper.py +91 -0
  24. junifer/data/{parcellations.py → parcellations/_parcellations.py} +450 -473
  25. junifer/data/{tests → parcellations/tests}/test_parcellations.py +73 -81
  26. junifer/data/pipeline_data_registry_base.py +74 -0
  27. junifer/data/utils.py +4 -0
  28. junifer/datagrabber/aomic/piop2.py +1 -1
  29. junifer/markers/complexity/hurst_exponent.py +2 -2
  30. junifer/markers/complexity/multiscale_entropy_auc.py +2 -2
  31. junifer/markers/complexity/perm_entropy.py +2 -2
  32. junifer/markers/complexity/range_entropy.py +2 -2
  33. junifer/markers/complexity/range_entropy_auc.py +2 -2
  34. junifer/markers/complexity/sample_entropy.py +2 -2
  35. junifer/markers/complexity/weighted_perm_entropy.py +2 -2
  36. junifer/markers/ets_rss.py +2 -2
  37. junifer/markers/falff/falff_parcels.py +2 -2
  38. junifer/markers/falff/falff_spheres.py +2 -2
  39. junifer/markers/functional_connectivity/edge_functional_connectivity_parcels.py +1 -1
  40. junifer/markers/functional_connectivity/edge_functional_connectivity_spheres.py +1 -1
  41. junifer/markers/functional_connectivity/functional_connectivity_parcels.py +1 -1
  42. junifer/markers/functional_connectivity/functional_connectivity_spheres.py +1 -1
  43. junifer/markers/functional_connectivity/tests/test_functional_connectivity_parcels.py +3 -3
  44. junifer/markers/functional_connectivity/tests/test_functional_connectivity_spheres.py +2 -2
  45. junifer/markers/parcel_aggregation.py +11 -7
  46. junifer/markers/reho/reho_parcels.py +2 -2
  47. junifer/markers/reho/reho_spheres.py +2 -2
  48. junifer/markers/sphere_aggregation.py +11 -7
  49. junifer/markers/temporal_snr/temporal_snr_parcels.py +2 -2
  50. junifer/markers/temporal_snr/temporal_snr_spheres.py +2 -2
  51. junifer/markers/tests/test_ets_rss.py +3 -3
  52. junifer/markers/tests/test_parcel_aggregation.py +24 -24
  53. junifer/markers/tests/test_sphere_aggregation.py +6 -6
  54. junifer/pipeline/__init__.pyi +2 -2
  55. junifer/pipeline/pipeline_component_registry.py +299 -0
  56. junifer/pipeline/tests/test_pipeline_component_registry.py +201 -0
  57. junifer/preprocess/confounds/fmriprep_confound_remover.py +6 -3
  58. junifer/testing/__init__.pyi +2 -2
  59. junifer/testing/registry.py +4 -7
  60. junifer/testing/tests/test_testing_registry.py +9 -17
  61. {junifer-0.0.6.dev154.dist-info → junifer-0.0.6.dev194.dist-info}/METADATA +1 -1
  62. {junifer-0.0.6.dev154.dist-info → junifer-0.0.6.dev194.dist-info}/RECORD +86 -72
  63. {junifer-0.0.6.dev154.dist-info → junifer-0.0.6.dev194.dist-info}/WHEEL +1 -1
  64. junifer/data/coordinates.py +0 -408
  65. junifer/data/masks.py +0 -670
  66. junifer/pipeline/registry.py +0 -245
  67. junifer/pipeline/tests/test_registry.py +0 -150
  68. /junifer/data/{VOIs → coordinates/VOIs}/meta/AutobiographicalMemory_VOIs.txt +0 -0
  69. /junifer/data/{VOIs → coordinates/VOIs}/meta/CogAC_VOIs.txt +0 -0
  70. /junifer/data/{VOIs → coordinates/VOIs}/meta/CogAR_VOIs.txt +0 -0
  71. /junifer/data/{VOIs → coordinates/VOIs}/meta/DMNBuckner_VOIs.txt +0 -0
  72. /junifer/data/{VOIs → coordinates/VOIs}/meta/Dosenbach2010_MNI_VOIs.txt +0 -0
  73. /junifer/data/{VOIs → coordinates/VOIs}/meta/Empathy_VOIs.txt +0 -0
  74. /junifer/data/{VOIs → coordinates/VOIs}/meta/Motor_VOIs.txt +0 -0
  75. /junifer/data/{VOIs → coordinates/VOIs}/meta/MultiTask_VOIs.txt +0 -0
  76. /junifer/data/{VOIs → coordinates/VOIs}/meta/PhysioStress_VOIs.txt +0 -0
  77. /junifer/data/{VOIs → coordinates/VOIs}/meta/Power2011_MNI_VOIs.txt +0 -0
  78. /junifer/data/{VOIs → coordinates/VOIs}/meta/Power2013_MNI_VOIs.tsv +0 -0
  79. /junifer/data/{VOIs → coordinates/VOIs}/meta/Rew_VOIs.txt +0 -0
  80. /junifer/data/{VOIs → coordinates/VOIs}/meta/Somatosensory_VOIs.txt +0 -0
  81. /junifer/data/{VOIs → coordinates/VOIs}/meta/ToM_VOIs.txt +0 -0
  82. /junifer/data/{VOIs → coordinates/VOIs}/meta/VigAtt_VOIs.txt +0 -0
  83. /junifer/data/{VOIs → coordinates/VOIs}/meta/WM_VOIs.txt +0 -0
  84. /junifer/data/{VOIs → coordinates/VOIs}/meta/eMDN_VOIs.txt +0 -0
  85. /junifer/data/{VOIs → coordinates/VOIs}/meta/eSAD_VOIs.txt +0 -0
  86. /junifer/data/{VOIs → coordinates/VOIs}/meta/extDMN_VOIs.txt +0 -0
  87. {junifer-0.0.6.dev154.dist-info → junifer-0.0.6.dev194.dist-info}/AUTHORS.rst +0 -0
  88. {junifer-0.0.6.dev154.dist-info → junifer-0.0.6.dev194.dist-info}/LICENSE.md +0 -0
  89. {junifer-0.0.6.dev154.dist-info → junifer-0.0.6.dev194.dist-info}/entry_points.txt +0 -0
  90. {junifer-0.0.6.dev154.dist-info → junifer-0.0.6.dev194.dist-info}/top_level.txt +0 -0
junifer/__init__.pyi CHANGED
@@ -12,6 +12,7 @@ __all__ = [
12
12
  "utils",
13
13
  "external",
14
14
  "onthefly",
15
+ "testing",
15
16
  "__version__",
16
17
  ]
17
18
 
@@ -28,6 +29,7 @@ from . import (
28
29
  storage,
29
30
  utils,
30
31
  external,
32
+ testing,
31
33
  onthefly,
32
34
  )
33
35
  from ._version import __version__
junifer/_version.py CHANGED
@@ -12,5 +12,5 @@ __version__: str
12
12
  __version_tuple__: VERSION_TUPLE
13
13
  version_tuple: VERSION_TUPLE
14
14
 
15
- __version__ = version = '0.0.6.dev154'
16
- __version_tuple__ = version_tuple = (0, 0, 6, 'dev154')
15
+ __version__ = version = '0.0.6.dev194'
16
+ __version_tuple__ = version_tuple = (0, 0, 6, 'dev194')
junifer/api/decorators.py CHANGED
@@ -7,7 +7,7 @@
7
7
 
8
8
  from typing import Type
9
9
 
10
- from ..pipeline.registry import register
10
+ from ..pipeline import PipelineComponentRegistry
11
11
 
12
12
 
13
13
  __all__ = [
@@ -39,9 +39,8 @@ def register_datagrabber(klass: Type) -> Type:
39
39
  It should only be used as a decorator.
40
40
 
41
41
  """
42
- register(
42
+ PipelineComponentRegistry().register(
43
43
  step="datagrabber",
44
- name=klass.__name__,
45
44
  klass=klass,
46
45
  )
47
46
  return klass
@@ -67,9 +66,8 @@ def register_datareader(klass: Type) -> Type:
67
66
  It should only be used as a decorator.
68
67
 
69
68
  """
70
- register(
69
+ PipelineComponentRegistry().register(
71
70
  step="datareader",
72
- name=klass.__name__,
73
71
  klass=klass,
74
72
  )
75
73
  return klass
@@ -91,9 +89,8 @@ def register_preprocessor(klass: Type) -> Type:
91
89
  The unmodified input class.
92
90
 
93
91
  """
94
- register(
92
+ PipelineComponentRegistry().register(
95
93
  step="preprocessing",
96
- name=klass.__name__,
97
94
  klass=klass,
98
95
  )
99
96
  return klass
@@ -115,9 +112,8 @@ def register_marker(klass: Type) -> Type:
115
112
  The unmodified input class.
116
113
 
117
114
  """
118
- register(
115
+ PipelineComponentRegistry().register(
119
116
  step="marker",
120
- name=klass.__name__,
121
117
  klass=klass,
122
118
  )
123
119
  return klass
@@ -139,9 +135,8 @@ def register_storage(klass: Type) -> Type:
139
135
  The unmodified input class.
140
136
 
141
137
  """
142
- register(
138
+ PipelineComponentRegistry().register(
143
139
  step="storage",
144
- name=klass.__name__,
145
140
  klass=klass,
146
141
  )
147
142
  return klass
junifer/api/functions.py CHANGED
@@ -7,15 +7,17 @@
7
7
 
8
8
  import os
9
9
  import shutil
10
- import typing
11
10
  from pathlib import Path
12
11
  from typing import Dict, List, Optional, Tuple, Union
13
12
 
14
13
  from ..api.queue_context import GnuParallelLocalAdapter, HTCondorAdapter
15
14
  from ..datagrabber.base import BaseDataGrabber
16
15
  from ..markers.base import BaseMarker
17
- from ..pipeline import MarkerCollection, WorkDirManager
18
- from ..pipeline.registry import build
16
+ from ..pipeline import (
17
+ MarkerCollection,
18
+ PipelineComponentRegistry,
19
+ WorkDirManager,
20
+ )
19
21
  from ..preprocess.base import BasePreprocessor
20
22
  from ..storage.base import BaseFeatureStorage
21
23
  from ..utils import logger, raise_error, yaml
@@ -38,42 +40,78 @@ def _get_datagrabber(datagrabber_config: Dict) -> BaseDataGrabber:
38
40
  The DataGrabber.
39
41
 
40
42
  """
41
- datagrabber_params = datagrabber_config.copy()
42
- datagrabber_kind = datagrabber_params.pop("kind")
43
- datagrabber = build(
43
+ return PipelineComponentRegistry().build_component_instance(
44
44
  step="datagrabber",
45
- name=datagrabber_kind,
45
+ name=datagrabber_config.pop("kind"),
46
46
  baseclass=BaseDataGrabber,
47
- init_params=datagrabber_params,
47
+ init_params=datagrabber_config,
48
48
  )
49
- datagrabber = typing.cast(BaseDataGrabber, datagrabber)
50
- return datagrabber
51
49
 
52
50
 
53
51
  def _get_preprocessor(preprocessing_config: Dict) -> BasePreprocessor:
54
- """Get preprocessor.
52
+ """Get Preprocessor.
55
53
 
56
54
  Parameters
57
55
  ----------
58
56
  preprocessing_config : dict
59
- The config to get the preprocessor using.
57
+ The config to get the Preprocessor using.
60
58
 
61
59
  Returns
62
60
  -------
63
61
  dict
64
- The preprocessor.
62
+ The Preprocessor.
65
63
 
66
64
  """
67
- preprocessor_params = preprocessing_config.copy()
68
- preprocessor_kind = preprocessor_params.pop("kind")
69
- preprocessor = build(
65
+ return PipelineComponentRegistry().build_component_instance(
70
66
  step="preprocessing",
71
- name=preprocessor_kind,
67
+ name=preprocessing_config.pop("kind"),
72
68
  baseclass=BasePreprocessor,
73
- init_params=preprocessor_params,
69
+ init_params=preprocessing_config,
70
+ )
71
+
72
+
73
+ def _get_marker(marker_config: Dict) -> BaseMarker:
74
+ """Get Marker.
75
+
76
+ Parameters
77
+ ----------
78
+ marker_config : dict
79
+ The config to get the Marker using.
80
+
81
+ Returns
82
+ -------
83
+ object
84
+ The Marker.
85
+
86
+ """
87
+ return PipelineComponentRegistry().build_component_instance(
88
+ step="marker",
89
+ name=marker_config.pop("kind"),
90
+ baseclass=BaseMarker,
91
+ init_params=marker_config,
92
+ )
93
+
94
+
95
+ def _get_storage(storage_config: Dict) -> BaseFeatureStorage:
96
+ """Get Storage.
97
+
98
+ Parameters
99
+ ----------
100
+ storage_config : dict
101
+ The config to get the Storage using.
102
+
103
+ Returns
104
+ -------
105
+ dict
106
+ The Storage.
107
+
108
+ """
109
+ return PipelineComponentRegistry().build_component_instance(
110
+ step="storage",
111
+ name=storage_config.pop("kind"),
112
+ baseclass=BaseFeatureStorage,
113
+ init_params=storage_config,
74
114
  )
75
- preprocessor = typing.cast(BasePreprocessor, preprocessor)
76
- return preprocessor
77
115
 
78
116
 
79
117
  def run(
@@ -123,41 +161,22 @@ def run(
123
161
  elements = [elements]
124
162
 
125
163
  # Get datagrabber to use
126
- datagrabber_object = _get_datagrabber(datagrabber)
164
+ datagrabber_object = _get_datagrabber(datagrabber.copy())
127
165
 
128
- # Copy to avoid changing the original dict
129
- _markers = [x.copy() for x in markers]
130
- built_markers = []
131
- for t_marker in _markers:
132
- kind = t_marker.pop("kind")
133
- t_m = build(
134
- step="marker",
135
- name=kind,
136
- baseclass=BaseMarker,
137
- init_params=t_marker,
138
- )
139
- built_markers.append(t_m)
166
+ # Get markers to use
167
+ built_markers = [_get_marker(marker) for marker in markers.copy()]
140
168
 
141
169
  # Get storage engine to use
142
- storage_params = storage.copy()
143
- storage_kind = storage_params.pop("kind")
144
- if "single_output" not in storage_params:
145
- storage_params["single_output"] = False
146
- storage_object = build(
147
- step="storage",
148
- name=storage_kind,
149
- baseclass=BaseFeatureStorage,
150
- init_params=storage_params,
151
- )
152
- storage_object = typing.cast(BaseFeatureStorage, storage_object)
170
+ if "single_output" not in storage:
171
+ storage["single_output"] = False
172
+ storage_object = _get_storage(storage.copy())
153
173
 
154
174
  # Get preprocessor to use (if provided)
155
175
  if preprocessors is not None:
156
- _preprocessors = [x.copy() for x in preprocessors]
157
- built_preprocessors = []
158
- for preprocessor in _preprocessors:
159
- preprocessor_object = _get_preprocessor(preprocessor)
160
- built_preprocessors.append(preprocessor_object)
176
+ built_preprocessors = [
177
+ _get_preprocessor(preprocessor)
178
+ for preprocessor in preprocessors.copy()
179
+ ]
161
180
  else:
162
181
  built_preprocessors = None
163
182
 
@@ -167,6 +186,7 @@ def run(
167
186
  preprocessors=built_preprocessors,
168
187
  storage=storage_object,
169
188
  )
189
+ # Validate the marker collection for the datagrabber
170
190
  mc.validate(datagrabber_object)
171
191
 
172
192
  # Fit elements
@@ -192,19 +212,11 @@ def collect(storage: Dict) -> None:
192
212
  constructor.
193
213
 
194
214
  """
195
- storage_params = storage.copy()
196
- storage_kind = storage_params.pop("kind")
197
- logger.info(f"Collecting data using {storage_kind}")
198
- logger.debug(f"\tStorage params: {storage_params}")
199
- if "single_output" not in storage_params:
200
- storage_params["single_output"] = False
201
- storage_object = build(
202
- step="storage",
203
- name=storage_kind,
204
- baseclass=BaseFeatureStorage,
205
- init_params=storage_params,
206
- )
207
- storage_object = typing.cast(BaseFeatureStorage, storage_object)
215
+ logger.info(f"Collecting data using {storage['kind']}")
216
+ logger.debug(f"\tStorage params: {storage}")
217
+ if "single_output" not in storage:
218
+ storage["single_output"] = False
219
+ storage_object = _get_storage(storage.copy())
208
220
  logger.debug("Running storage.collect()")
209
221
  storage_object.collect()
210
222
  logger.info("Collect done")
@@ -15,7 +15,7 @@ from ruamel.yaml import YAML
15
15
  import junifer.testing.registry # noqa: F401
16
16
  from junifer.api import collect, list_elements, queue, reset, run
17
17
  from junifer.datagrabber.base import BaseDataGrabber
18
- from junifer.pipeline.registry import build
18
+ from junifer.pipeline import PipelineComponentRegistry
19
19
 
20
20
 
21
21
  # Configure YAML class
@@ -240,7 +240,7 @@ def test_run_and_collect(
240
240
  storage=storage,
241
241
  )
242
242
  # Get datagrabber
243
- dg = build(
243
+ dg = PipelineComponentRegistry().build_component_instance(
244
244
  step="datagrabber", name=datagrabber["kind"], baseclass=BaseDataGrabber
245
245
  )
246
246
  elements = dg.get_elements() # type: ignore
junifer/data/__init__.pyi CHANGED
@@ -1,41 +1,27 @@
1
1
  __all__ = [
2
- "list_coordinates",
3
- "load_coordinates",
4
- "register_coordinates",
5
- "get_coordinates",
6
- "list_parcellations",
7
- "load_parcellation",
8
- "register_parcellation",
9
- "merge_parcellations",
10
- "get_parcellation",
11
- "list_masks",
12
- "load_mask",
13
- "register_mask",
14
- "get_mask",
2
+ "CoordinatesRegistry",
3
+ "ParcellationRegistry",
4
+ "MaskRegistry",
5
+ "get_data",
6
+ "list_data",
7
+ "load_data",
8
+ "register_data",
9
+ "deregister_data",
15
10
  "get_template",
16
11
  "get_xfm",
17
12
  "utils",
18
13
  ]
19
14
 
20
- from .coordinates import (
21
- list_coordinates,
22
- load_coordinates,
23
- register_coordinates,
24
- get_coordinates,
25
- )
26
- from .parcellations import (
27
- list_parcellations,
28
- load_parcellation,
29
- register_parcellation,
30
- merge_parcellations,
31
- get_parcellation,
32
- )
15
+ from .coordinates import CoordinatesRegistry
16
+ from .parcellations import ParcellationRegistry
17
+ from .masks import MaskRegistry
33
18
 
34
- from .masks import (
35
- list_masks,
36
- load_mask,
37
- register_mask,
38
- get_mask,
19
+ from ._dispatch import (
20
+ get_data,
21
+ list_data,
22
+ load_data,
23
+ register_data,
24
+ deregister_data,
39
25
  )
40
26
 
41
27
  from .template_spaces import get_template, get_xfm
@@ -0,0 +1,251 @@
1
+ """Provide dispatch functions for pipeline data registries."""
2
+
3
+ # Authors: Synchon Mandal <s.mandal@fz-juelich.de>
4
+ # License: AGPL
5
+
6
+ from pathlib import Path
7
+ from typing import (
8
+ TYPE_CHECKING,
9
+ Any,
10
+ Callable,
11
+ Dict,
12
+ List,
13
+ Optional,
14
+ Tuple,
15
+ Union,
16
+ )
17
+
18
+ from numpy.typing import ArrayLike
19
+
20
+ from ..utils import raise_error
21
+ from .coordinates import CoordinatesRegistry
22
+ from .masks import MaskRegistry
23
+ from .parcellations import ParcellationRegistry
24
+
25
+
26
+ if TYPE_CHECKING:
27
+ from nibabel.nifti1 import Nifti1Image
28
+
29
+
30
+ __all__ = [
31
+ "get_data",
32
+ "list_data",
33
+ "load_data",
34
+ "register_data",
35
+ "deregister_data",
36
+ ]
37
+
38
+
39
+ def get_data(
40
+ kind: str,
41
+ names: Union[
42
+ str, # coordinates, parcellation, mask
43
+ List[str], # parcellation, mask
44
+ Dict, # mask
45
+ List[Dict], # mask
46
+ ],
47
+ target_data: Dict[str, Any],
48
+ extra_input: Optional[Dict[str, Any]] = None,
49
+ ) -> Union[
50
+ Tuple[ArrayLike, List[str]], # coordinates
51
+ Tuple["Nifti1Image", List[str]], # parcellation
52
+ "Nifti1Image", # mask
53
+ ]:
54
+ """Get tailored ``kind`` for ``target_data``.
55
+
56
+ Parameters
57
+ ----------
58
+ kind : {"coordinates", "parcellation", "mask"}
59
+ Kind of data to fetch and apply.
60
+ names : str or dict or list of str / dict
61
+ The registered name(s) of the data.
62
+ target_data : dict
63
+ The corresponding item of the data object to which the data
64
+ will be applied.
65
+ extra_input : dict, optional
66
+ The other fields in the data object. Useful for accessing other
67
+ data types that need to be used in the computation of data
68
+ (default None).
69
+
70
+ Returns
71
+ -------
72
+ tuple of numpy.ndarray, list of str; \
73
+ tuple of nibabel.nifti1.Nifti1Image, list of str; \
74
+ nibabel.nifti1.Nifti1Image
75
+
76
+ Raises
77
+ ------
78
+ ValueError
79
+ If ``kind`` is invalid value.
80
+
81
+ """
82
+
83
+ if kind == "coordinates":
84
+ return CoordinatesRegistry().get(
85
+ coords=names,
86
+ target_data=target_data,
87
+ extra_input=extra_input,
88
+ )
89
+ elif kind == "parcellation":
90
+ return ParcellationRegistry().get(
91
+ parcellations=names,
92
+ target_data=target_data,
93
+ extra_input=extra_input,
94
+ )
95
+ elif kind == "mask":
96
+ return MaskRegistry().get(
97
+ masks=names,
98
+ target_data=target_data,
99
+ extra_input=extra_input,
100
+ )
101
+ else:
102
+ raise_error(f"Unknown data kind: {kind}")
103
+
104
+
105
+ def list_data(kind: str) -> List[str]:
106
+ """List available data for ``kind``.
107
+
108
+ Parameters
109
+ ----------
110
+ kind : {"coordinates", "parcellation", "mask"}
111
+ Kind of data registry to list.
112
+
113
+ Returns
114
+ -------
115
+ list of str
116
+ Available data for the registry.
117
+
118
+ Raises
119
+ ------
120
+ ValueError
121
+ If ``kind`` is invalid value.
122
+
123
+ """
124
+
125
+ if kind == "coordinates":
126
+ return CoordinatesRegistry().list
127
+ elif kind == "parcellation":
128
+ return ParcellationRegistry().list
129
+ elif kind == "mask":
130
+ return MaskRegistry().list
131
+ else:
132
+ raise_error(f"Unknown data kind: {kind}")
133
+
134
+
135
+ def load_data(
136
+ kind: str,
137
+ name: str,
138
+ **kwargs,
139
+ ) -> Union[
140
+ Tuple[ArrayLike, List[str], str], # coordinates
141
+ Tuple[Optional["Nifti1Image"], List[str], Path, str], # parcellation
142
+ Tuple[
143
+ Optional[Union["Nifti1Image", Callable]], Optional[Path], str
144
+ ], # mask
145
+ ]:
146
+ """Load ``kind`` named ``name``.
147
+
148
+ Parameters
149
+ ----------
150
+ kind : {"coordinates", "parcellation", "mask"}
151
+ Kind of data to load.
152
+ name : str
153
+ The registered name of the data.
154
+ **kwargs
155
+ Keyword arguments are passed to respective registry class method.
156
+
157
+ Returns
158
+ -------
159
+ tuple of numpy.ndarray, list of str, str; \
160
+ tuple of nibabel.nifti1.Nifti1Image or None, \
161
+ list of str, pathlib.Path, str; \
162
+ tuple of nibabel.nifti1.Nifti1Image or callable or None, \
163
+ pathlib.Path or None, str
164
+
165
+ Raises
166
+ ------
167
+ ValueError
168
+ If ``kind`` is invalid value.
169
+
170
+ """
171
+
172
+ if kind == "coordinates":
173
+ return CoordinatesRegistry().load(name=name)
174
+ elif kind == "parcellation":
175
+ return ParcellationRegistry().load(name=name, **kwargs)
176
+ elif kind == "mask":
177
+ return MaskRegistry().load(name=name, **kwargs)
178
+ else:
179
+ raise_error(f"Unknown data kind: {kind}")
180
+
181
+
182
+ def register_data(
183
+ kind: str,
184
+ name: str,
185
+ space: str,
186
+ overwrite: bool = False,
187
+ **kwargs,
188
+ ) -> None:
189
+ """Register ``name`` under ``kind``.
190
+
191
+ Parameters
192
+ ----------
193
+ kind : {"coordinates", "parcellation", "mask"}
194
+ Kind of data to register.
195
+ name : str
196
+ The name to register.
197
+ space : str
198
+ The template space of the data.
199
+ overwrite : bool, optional
200
+ If True, overwrite an existing data with the same name.
201
+ **kwargs
202
+ Keyword arguments are passed to respective registry class method.
203
+
204
+ Raises
205
+ ------
206
+ ValueError
207
+ If ``kind`` is invalid value.
208
+
209
+ """
210
+
211
+ if kind == "coordinates":
212
+ return CoordinatesRegistry().register(
213
+ name=name, space=space, overwrite=overwrite, **kwargs
214
+ )
215
+ elif kind == "parcellation":
216
+ return ParcellationRegistry().register(
217
+ name=name, space=space, overwrite=overwrite, **kwargs
218
+ )
219
+ elif kind == "mask":
220
+ return MaskRegistry().load(
221
+ name=name, space=space, overwrite=overwrite, **kwargs
222
+ )
223
+ else:
224
+ raise_error(f"Unknown data kind: {kind}")
225
+
226
+
227
+ def deregister_data(kind: str, name: str) -> None:
228
+ """De-register ``name`` from ``kind``.
229
+
230
+ Parameters
231
+ ----------
232
+ kind : {"coordinates", "parcellation", "mask"}
233
+ Kind of data to register.
234
+ name : str
235
+ The name to de-register.
236
+
237
+ Raises
238
+ ------
239
+ ValueError
240
+ If ``kind`` is invalid value.
241
+
242
+ """
243
+
244
+ if kind == "coordinates":
245
+ return CoordinatesRegistry().deregister(name=name)
246
+ elif kind == "parcellation":
247
+ return ParcellationRegistry().register(name=name)
248
+ elif kind == "mask":
249
+ return MaskRegistry().load(name=name)
250
+ else:
251
+ raise_error(f"Unknown data kind: {kind}")
@@ -0,0 +1,9 @@
1
+ """Coordinates."""
2
+
3
+ # Authors: Synchon Mandal <s.mandal@fz-juelich.de>
4
+ # License: AGPL
5
+
6
+ import lazy_loader as lazy
7
+
8
+
9
+ __getattr__, __dir__, __all__ = lazy.attach_stub(__name__, __file__)
@@ -0,0 +1,5 @@
1
+ __all__ = [
2
+ "CoordinatesRegistry",
3
+ ]
4
+
5
+ from ._coordinates import CoordinatesRegistry