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
@@ -1,245 +0,0 @@
1
- """Provide functions for registry."""
2
-
3
- # Authors: Federico Raimondo <f.raimondo@fz-juelich.de>
4
- # Leonard Sasse <l.sasse@fz-juelich.de>
5
- # Synchon Mandal <s.mandal@fz-juelich.de>
6
- # License: AGPL
7
-
8
- import importlib
9
- from typing import TYPE_CHECKING, Dict, List, Optional, Union
10
-
11
- from ..utils.logging import logger, raise_error
12
-
13
-
14
- if TYPE_CHECKING:
15
- from ..datagrabber import BaseDataGrabber
16
- from ..storage import BaseFeatureStorage
17
- from .pipeline_step_mixin import PipelineStepMixin
18
-
19
-
20
- __all__ = ["register", "get_step_names", "get_class", "build"]
21
-
22
-
23
- # Define valid steps for operation
24
- _VALID_STEPS: List[str] = [
25
- "datagrabber",
26
- "datareader",
27
- "preprocessing",
28
- "marker",
29
- "storage",
30
- ]
31
-
32
- # Step to sub-package mapping
33
- _STEP_TO_SUBPKG_MAPPINGS = {
34
- "datagrabber": "datagrabber",
35
- "datareader": "datareader",
36
- "preprocessing": "preprocess",
37
- "marker": "markers",
38
- "storage": "storage",
39
- }
40
-
41
- # Define registry for valid steps
42
- _REGISTRY: Dict[str, Dict[str, Union[str, type]]] = {
43
- "datagrabber": {
44
- "HCP1200": "HCP1200",
45
- "BaseDataGrabber": "BaseDataGrabber",
46
- "DataladAOMICID1000": "DataladAOMICID1000",
47
- "DataladAOMICPIOP1": "DataladAOMICPIOP1",
48
- "DataladAOMICPIOP2": "DataladAOMICPIOP2",
49
- "DataladDataGrabber": "DataladDataGrabber",
50
- "DataladHCP1200": "DataladHCP1200",
51
- "DMCC13Benchmark": "DMCC13Benchmark",
52
- "MultipleDataGrabber": "MultipleDataGrabber",
53
- "PatternDataGrabber": "PatternDataGrabber",
54
- "PatternDataladDataGrabber": "PatternDataladDataGrabber",
55
- },
56
- "datareader": {
57
- "DefaultDataReader": "DefaultDataReader",
58
- },
59
- "preprocessing": {
60
- "BasePreprocessor": "BasePreprocessor",
61
- "Smoothing": "Smoothing",
62
- "SpaceWarper": "SpaceWarper",
63
- "fMRIPrepConfoundRemover": "fMRIPrepConfoundRemover",
64
- },
65
- "marker": {
66
- "ALFFParcels": "ALFFParcels",
67
- "ALFFSpheres": "ALFFSpheres",
68
- "BaseMarker": "BaseMarker",
69
- "BrainPrint": "BrainPrint",
70
- "CrossParcellationFC": "CrossParcellationFC",
71
- "EdgeCentricFCParcels": "EdgeCentricFCParcels",
72
- "EdgeCentricFCSpheres": "EdgeCentricFCSpheres",
73
- "FunctionalConnectivityParcels": "FunctionalConnectivityParcels",
74
- "FunctionalConnectivitySpheres": "FunctionalConnectivitySpheres",
75
- "ParcelAggregation": "ParcelAggregation",
76
- "ReHoParcels": "ReHoParcels",
77
- "ReHoSpheres": "ReHoSpheres",
78
- "RSSETSMarker": "RSSETSMarker",
79
- "SphereAggregation": "SphereAggregation",
80
- "TemporalSNRParcels": "TemporalSNRParcels",
81
- "TemporalSNRSpheres": "TemporalSNRSpheres",
82
- },
83
- "storage": {
84
- "BaseFeatureStorage": "BaseFeatureStorage",
85
- "HDF5FeatureStorage": "HDF5FeatureStorage",
86
- "PandasBaseFeatureStorage": "PandasBaseFeatureStorage",
87
- "SQLiteFeatureStorage": "SQLiteFeatureStorage",
88
- },
89
- }
90
-
91
-
92
- def register(step: str, name: str, klass: type) -> None:
93
- """Register a function to be used in a pipeline step.
94
-
95
- Parameters
96
- ----------
97
- step : str
98
- Name of the step.
99
- name : str
100
- Name of the function.
101
- klass : class
102
- Class to be registered.
103
-
104
- Raises
105
- ------
106
- ValueError
107
- If the ``step`` is invalid.
108
-
109
- """
110
- # Verify step
111
- if step not in _VALID_STEPS:
112
- raise_error(msg=f"Invalid step: {step}", klass=ValueError)
113
-
114
- logger.info(f"Registering {name} in {step}")
115
- _REGISTRY[step][name] = klass
116
-
117
-
118
- def get_step_names(step: str) -> List[str]:
119
- """Get the names of the registered functions for a given step.
120
-
121
- Parameters
122
- ----------
123
- step : str
124
- Name of the step.
125
-
126
- Returns
127
- -------
128
- list
129
- List of registered function names.
130
-
131
- Raises
132
- ------
133
- ValueError
134
- If the ``step`` is invalid.
135
-
136
- """
137
- # Verify step
138
- if step not in _VALID_STEPS:
139
- raise_error(msg=f"Invalid step: {step}", klass=ValueError)
140
-
141
- return list(_REGISTRY[step].keys())
142
-
143
-
144
- def get_class(step: str, name: str) -> type:
145
- """Get the class of the registered function for a given step.
146
-
147
- Parameters
148
- ----------
149
- step : str
150
- Name of the step.
151
- name : str
152
- Name of the function.
153
-
154
- Returns
155
- -------
156
- class
157
- Registered function class.
158
-
159
- Raises
160
- ------
161
- ValueError
162
- If the ``step`` or ``name`` is invalid.
163
-
164
- """
165
- # Verify step
166
- if step not in _VALID_STEPS:
167
- raise_error(msg=f"Invalid step: {step}", klass=ValueError)
168
- # Verify step name
169
- if name not in _REGISTRY[step]:
170
- raise_error(msg=f"Invalid name: {name}", klass=ValueError)
171
-
172
- # Check if first-time import, then import it
173
- if isinstance(_REGISTRY[step][name], str):
174
- klass = getattr(
175
- importlib.import_module(
176
- f"junifer.{_STEP_TO_SUBPKG_MAPPINGS[step]}"
177
- ),
178
- name,
179
- )
180
- else:
181
- klass = _REGISTRY[step][name]
182
-
183
- return klass
184
-
185
-
186
- def build(
187
- step: str,
188
- name: str,
189
- baseclass: type,
190
- init_params: Optional[Dict] = None,
191
- ) -> Union["BaseDataGrabber", "PipelineStepMixin", "BaseFeatureStorage"]:
192
- """Ensure that the given object is an instance of the given class.
193
-
194
- Parameters
195
- ----------
196
- step : str
197
- Name of the step.
198
- name : str
199
- Name of the function.
200
- baseclass : class
201
- Class to be checked against.
202
- init_params : dict or None, optional
203
- Parameters to pass to the base class constructor (default None).
204
-
205
- Returns
206
- -------
207
- object
208
- An instance of the given base class.
209
-
210
- Raises
211
- ------
212
- RuntimeError
213
- If there is a problem creating the instance.
214
- ValueError
215
- If the created object with the given name is not an instance of the
216
- base class.
217
-
218
- """
219
- # Set default init parameters
220
- if init_params is None:
221
- init_params = {}
222
- # Get class of the registered function
223
- logger.debug(f"Building {step}/{name}")
224
- klass = get_class(step=step, name=name)
225
- logger.debug(f"\tClass: {klass.__name__}")
226
- logger.debug(f"\tInit params: {init_params}")
227
- try:
228
- # Create instance of the class
229
- object_ = klass(**init_params)
230
- except (ValueError, TypeError) as e:
231
- raise_error(
232
- msg=f"Failed to create {step} ({name}). Error: {e}",
233
- klass=RuntimeError,
234
- exception=e,
235
- )
236
- # Verify created instance belongs to the base class
237
- if not isinstance(object_, baseclass):
238
- raise_error(
239
- msg=(
240
- f"Invalid {step} ({object_.__class__.__name__}). "
241
- f"Must inherit from {baseclass.__name__}"
242
- ),
243
- klass=ValueError,
244
- )
245
- return object_
@@ -1,150 +0,0 @@
1
- """Provide tests for registry."""
2
-
3
- # Authors: Federico Raimondo <f.raimondo@fz-juelich.de>
4
- # Leonard Sasse <l.sasse@fz-juelich.de>
5
- # Synchon Mandal <s.mandal@fz-juelich.de>
6
- # License: AGPL
7
- import logging
8
- from abc import ABC
9
- from typing import Type
10
-
11
- import pytest
12
-
13
- from junifer.datagrabber import PatternDataGrabber
14
- from junifer.pipeline.registry import (
15
- build,
16
- get_class,
17
- get_step_names,
18
- register,
19
- )
20
- from junifer.storage import SQLiteFeatureStorage
21
-
22
-
23
- def test_register_invalid_step():
24
- """Test register invalid step name."""
25
- with pytest.raises(ValueError, match="Invalid step:"):
26
- register(step="foo", name="bar", klass=str)
27
-
28
-
29
- # TODO: improve parametrization
30
- @pytest.mark.parametrize(
31
- "step, name, klass",
32
- [
33
- ("datagrabber", "pattern-dg", PatternDataGrabber),
34
- ("storage", "sqlite-storage", SQLiteFeatureStorage),
35
- ],
36
- )
37
- def test_register(
38
- caplog: pytest.LogCaptureFixture, step: str, name: str, klass: Type
39
- ) -> None:
40
- """Test register.
41
-
42
- Parameters
43
- ----------
44
- caplog : pytest.LogCaptureFixture
45
- The pytest.LogCaptureFixture object.
46
- step : str
47
- The parametrized name of the step.
48
- name : str
49
- The parametrized name of the function.
50
- klass : str
51
- The parametrized name of the base class.
52
-
53
- """
54
- with caplog.at_level(logging.INFO):
55
- # Register
56
- register(step=step, name=name, klass=klass)
57
- # Check logging message
58
- assert "Registering" in caplog.text
59
-
60
-
61
- def test_get_step_names_invalid_step() -> None:
62
- """Test get step name invalid step name."""
63
- with pytest.raises(ValueError, match="Invalid step:"):
64
- get_step_names(step="foo")
65
-
66
-
67
- def test_get_step_names_absent() -> None:
68
- """Test get step names for absent name."""
69
- # Get step names for datagrabber
70
- datagrabbers = get_step_names(step="datagrabber")
71
- # Check for datagrabber step name
72
- assert "bar" not in datagrabbers
73
-
74
-
75
- def test_get_step_names() -> None:
76
- """Test get step names."""
77
- # Register datagrabber
78
- register(step="datagrabber", name="bar", klass=str)
79
- # Get step names for datagrabber
80
- datagrabbers = get_step_names(step="datagrabber")
81
- # Check for datagrabber step name
82
- assert "bar" in datagrabbers
83
-
84
-
85
- def test_get_class_invalid_step() -> None:
86
- """Test get class invalid step name."""
87
- with pytest.raises(ValueError, match="Invalid step:"):
88
- get_class(step="foo", name="bar")
89
-
90
-
91
- def test_get_class_invalid_name() -> None:
92
- """Test get class invalid function name."""
93
- with pytest.raises(ValueError, match="Invalid name:"):
94
- get_class(step="datagrabber", name="foo")
95
-
96
-
97
- # TODO: enable parametrization
98
- def test_get_class():
99
- """Test get class."""
100
- # Register datagrabber
101
- register(step="datagrabber", name="bar", klass=str)
102
- # Get class
103
- obj = get_class(step="datagrabber", name="bar")
104
- assert isinstance(obj, type(str))
105
-
106
-
107
- # TODO: possible parametrization?
108
- def test_build():
109
- """Test building objects from names."""
110
- import numpy as np
111
-
112
- # Define abstract base class
113
- class SuperClass(ABC):
114
- pass
115
-
116
- # Define concrete class
117
- class ConcreteClass(SuperClass):
118
- def __init__(self, value=1):
119
- self.value = value
120
-
121
- # Register
122
- register(step="datagrabber", name="concrete", klass=ConcreteClass)
123
-
124
- # Build
125
- obj = build(step="datagrabber", name="concrete", baseclass=SuperClass)
126
- assert isinstance(obj, ConcreteClass)
127
- assert obj.value == 1
128
-
129
- # Build
130
- obj = build(
131
- step="datagrabber",
132
- name="concrete",
133
- baseclass=SuperClass,
134
- init_params={"value": 2},
135
- )
136
- assert isinstance(obj, ConcreteClass)
137
- assert obj.value == 2
138
-
139
- # Check error
140
- with pytest.raises(ValueError, match="Must inherit"):
141
- build(step="datagrabber", name="concrete", baseclass=np.ndarray)
142
-
143
- # Check error
144
- with pytest.raises(RuntimeError, match="Failed to create"):
145
- build(
146
- step="datagrabber",
147
- name="concrete",
148
- baseclass=SuperClass,
149
- init_params={"wrong": 2},
150
- )