junifer 0.0.3.dev186__py3-none-any.whl → 0.0.4__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 (178) hide show
  1. junifer/_version.py +14 -2
  2. junifer/api/cli.py +162 -17
  3. junifer/api/functions.py +87 -419
  4. junifer/api/parser.py +24 -0
  5. junifer/api/queue_context/__init__.py +8 -0
  6. junifer/api/queue_context/gnu_parallel_local_adapter.py +258 -0
  7. junifer/api/queue_context/htcondor_adapter.py +365 -0
  8. junifer/api/queue_context/queue_context_adapter.py +60 -0
  9. junifer/api/queue_context/tests/test_gnu_parallel_local_adapter.py +192 -0
  10. junifer/api/queue_context/tests/test_htcondor_adapter.py +257 -0
  11. junifer/api/res/afni/run_afni_docker.sh +6 -6
  12. junifer/api/res/ants/ResampleImage +3 -0
  13. junifer/api/res/ants/antsApplyTransforms +3 -0
  14. junifer/api/res/ants/antsApplyTransformsToPoints +3 -0
  15. junifer/api/res/ants/run_ants_docker.sh +39 -0
  16. junifer/api/res/fsl/applywarp +3 -0
  17. junifer/api/res/fsl/flirt +3 -0
  18. junifer/api/res/fsl/img2imgcoord +3 -0
  19. junifer/api/res/fsl/run_fsl_docker.sh +39 -0
  20. junifer/api/res/fsl/std2imgcoord +3 -0
  21. junifer/api/res/run_conda.sh +4 -4
  22. junifer/api/res/run_venv.sh +22 -0
  23. junifer/api/tests/data/partly_cloudy_agg_mean_tian.yml +16 -0
  24. junifer/api/tests/test_api_utils.py +21 -3
  25. junifer/api/tests/test_cli.py +232 -9
  26. junifer/api/tests/test_functions.py +211 -439
  27. junifer/api/tests/test_parser.py +1 -1
  28. junifer/configs/juseless/datagrabbers/aomic_id1000_vbm.py +6 -1
  29. junifer/configs/juseless/datagrabbers/camcan_vbm.py +6 -1
  30. junifer/configs/juseless/datagrabbers/ixi_vbm.py +6 -1
  31. junifer/configs/juseless/datagrabbers/tests/test_ucla.py +8 -8
  32. junifer/configs/juseless/datagrabbers/ucla.py +44 -26
  33. junifer/configs/juseless/datagrabbers/ukb_vbm.py +6 -1
  34. junifer/data/VOIs/meta/AutobiographicalMemory_VOIs.txt +23 -0
  35. junifer/data/VOIs/meta/Power2013_MNI_VOIs.tsv +264 -0
  36. junifer/data/__init__.py +4 -0
  37. junifer/data/coordinates.py +298 -31
  38. junifer/data/masks.py +360 -28
  39. junifer/data/parcellations.py +621 -188
  40. junifer/data/template_spaces.py +190 -0
  41. junifer/data/tests/test_coordinates.py +34 -3
  42. junifer/data/tests/test_data_utils.py +1 -0
  43. junifer/data/tests/test_masks.py +202 -86
  44. junifer/data/tests/test_parcellations.py +266 -55
  45. junifer/data/tests/test_template_spaces.py +104 -0
  46. junifer/data/utils.py +4 -2
  47. junifer/datagrabber/__init__.py +1 -0
  48. junifer/datagrabber/aomic/id1000.py +111 -70
  49. junifer/datagrabber/aomic/piop1.py +116 -53
  50. junifer/datagrabber/aomic/piop2.py +116 -53
  51. junifer/datagrabber/aomic/tests/test_id1000.py +27 -27
  52. junifer/datagrabber/aomic/tests/test_piop1.py +27 -27
  53. junifer/datagrabber/aomic/tests/test_piop2.py +27 -27
  54. junifer/datagrabber/base.py +62 -10
  55. junifer/datagrabber/datalad_base.py +0 -2
  56. junifer/datagrabber/dmcc13_benchmark.py +372 -0
  57. junifer/datagrabber/hcp1200/datalad_hcp1200.py +5 -0
  58. junifer/datagrabber/hcp1200/hcp1200.py +30 -13
  59. junifer/datagrabber/pattern.py +133 -27
  60. junifer/datagrabber/pattern_datalad.py +111 -13
  61. junifer/datagrabber/tests/test_base.py +57 -6
  62. junifer/datagrabber/tests/test_datagrabber_utils.py +204 -76
  63. junifer/datagrabber/tests/test_datalad_base.py +0 -6
  64. junifer/datagrabber/tests/test_dmcc13_benchmark.py +256 -0
  65. junifer/datagrabber/tests/test_multiple.py +43 -10
  66. junifer/datagrabber/tests/test_pattern.py +125 -178
  67. junifer/datagrabber/tests/test_pattern_datalad.py +44 -25
  68. junifer/datagrabber/utils.py +151 -16
  69. junifer/datareader/default.py +36 -10
  70. junifer/external/nilearn/junifer_nifti_spheres_masker.py +6 -0
  71. junifer/markers/base.py +25 -16
  72. junifer/markers/collection.py +35 -16
  73. junifer/markers/complexity/__init__.py +27 -0
  74. junifer/markers/complexity/complexity_base.py +149 -0
  75. junifer/markers/complexity/hurst_exponent.py +136 -0
  76. junifer/markers/complexity/multiscale_entropy_auc.py +140 -0
  77. junifer/markers/complexity/perm_entropy.py +132 -0
  78. junifer/markers/complexity/range_entropy.py +136 -0
  79. junifer/markers/complexity/range_entropy_auc.py +145 -0
  80. junifer/markers/complexity/sample_entropy.py +134 -0
  81. junifer/markers/complexity/tests/test_complexity_base.py +19 -0
  82. junifer/markers/complexity/tests/test_hurst_exponent.py +69 -0
  83. junifer/markers/complexity/tests/test_multiscale_entropy_auc.py +68 -0
  84. junifer/markers/complexity/tests/test_perm_entropy.py +68 -0
  85. junifer/markers/complexity/tests/test_range_entropy.py +69 -0
  86. junifer/markers/complexity/tests/test_range_entropy_auc.py +69 -0
  87. junifer/markers/complexity/tests/test_sample_entropy.py +68 -0
  88. junifer/markers/complexity/tests/test_weighted_perm_entropy.py +68 -0
  89. junifer/markers/complexity/weighted_perm_entropy.py +133 -0
  90. junifer/markers/falff/_afni_falff.py +153 -0
  91. junifer/markers/falff/_junifer_falff.py +142 -0
  92. junifer/markers/falff/falff_base.py +91 -84
  93. junifer/markers/falff/falff_parcels.py +61 -45
  94. junifer/markers/falff/falff_spheres.py +64 -48
  95. junifer/markers/falff/tests/test_falff_parcels.py +89 -121
  96. junifer/markers/falff/tests/test_falff_spheres.py +92 -127
  97. junifer/markers/functional_connectivity/crossparcellation_functional_connectivity.py +1 -0
  98. junifer/markers/functional_connectivity/edge_functional_connectivity_parcels.py +1 -0
  99. junifer/markers/functional_connectivity/functional_connectivity_base.py +1 -0
  100. junifer/markers/functional_connectivity/tests/test_crossparcellation_functional_connectivity.py +46 -44
  101. junifer/markers/functional_connectivity/tests/test_edge_functional_connectivity_parcels.py +34 -39
  102. junifer/markers/functional_connectivity/tests/test_edge_functional_connectivity_spheres.py +40 -52
  103. junifer/markers/functional_connectivity/tests/test_functional_connectivity_parcels.py +62 -70
  104. junifer/markers/functional_connectivity/tests/test_functional_connectivity_spheres.py +99 -85
  105. junifer/markers/parcel_aggregation.py +60 -38
  106. junifer/markers/reho/_afni_reho.py +192 -0
  107. junifer/markers/reho/_junifer_reho.py +281 -0
  108. junifer/markers/reho/reho_base.py +69 -34
  109. junifer/markers/reho/reho_parcels.py +26 -16
  110. junifer/markers/reho/reho_spheres.py +23 -9
  111. junifer/markers/reho/tests/test_reho_parcels.py +93 -92
  112. junifer/markers/reho/tests/test_reho_spheres.py +88 -86
  113. junifer/markers/sphere_aggregation.py +54 -9
  114. junifer/markers/temporal_snr/temporal_snr_base.py +1 -0
  115. junifer/markers/temporal_snr/tests/test_temporal_snr_parcels.py +38 -37
  116. junifer/markers/temporal_snr/tests/test_temporal_snr_spheres.py +34 -38
  117. junifer/markers/tests/test_collection.py +43 -42
  118. junifer/markers/tests/test_ets_rss.py +29 -37
  119. junifer/markers/tests/test_parcel_aggregation.py +587 -468
  120. junifer/markers/tests/test_sphere_aggregation.py +209 -157
  121. junifer/markers/utils.py +2 -40
  122. junifer/onthefly/read_transform.py +13 -6
  123. junifer/pipeline/__init__.py +1 -0
  124. junifer/pipeline/pipeline_step_mixin.py +105 -41
  125. junifer/pipeline/registry.py +17 -0
  126. junifer/pipeline/singleton.py +45 -0
  127. junifer/pipeline/tests/test_pipeline_step_mixin.py +139 -51
  128. junifer/pipeline/tests/test_update_meta_mixin.py +1 -0
  129. junifer/pipeline/tests/test_workdir_manager.py +104 -0
  130. junifer/pipeline/update_meta_mixin.py +8 -2
  131. junifer/pipeline/utils.py +154 -15
  132. junifer/pipeline/workdir_manager.py +246 -0
  133. junifer/preprocess/__init__.py +3 -0
  134. junifer/preprocess/ants/__init__.py +4 -0
  135. junifer/preprocess/ants/ants_apply_transforms_warper.py +185 -0
  136. junifer/preprocess/ants/tests/test_ants_apply_transforms_warper.py +56 -0
  137. junifer/preprocess/base.py +96 -69
  138. junifer/preprocess/bold_warper.py +265 -0
  139. junifer/preprocess/confounds/fmriprep_confound_remover.py +91 -134
  140. junifer/preprocess/confounds/tests/test_fmriprep_confound_remover.py +106 -111
  141. junifer/preprocess/fsl/__init__.py +4 -0
  142. junifer/preprocess/fsl/apply_warper.py +179 -0
  143. junifer/preprocess/fsl/tests/test_apply_warper.py +45 -0
  144. junifer/preprocess/tests/test_bold_warper.py +159 -0
  145. junifer/preprocess/tests/test_preprocess_base.py +6 -6
  146. junifer/preprocess/warping/__init__.py +6 -0
  147. junifer/preprocess/warping/_ants_warper.py +167 -0
  148. junifer/preprocess/warping/_fsl_warper.py +109 -0
  149. junifer/preprocess/warping/space_warper.py +213 -0
  150. junifer/preprocess/warping/tests/test_space_warper.py +198 -0
  151. junifer/stats.py +18 -4
  152. junifer/storage/base.py +9 -1
  153. junifer/storage/hdf5.py +8 -3
  154. junifer/storage/pandas_base.py +2 -1
  155. junifer/storage/sqlite.py +1 -0
  156. junifer/storage/tests/test_hdf5.py +2 -1
  157. junifer/storage/tests/test_sqlite.py +8 -8
  158. junifer/storage/tests/test_utils.py +6 -6
  159. junifer/storage/utils.py +1 -0
  160. junifer/testing/datagrabbers.py +11 -7
  161. junifer/testing/utils.py +1 -0
  162. junifer/tests/test_stats.py +2 -0
  163. junifer/utils/__init__.py +1 -0
  164. junifer/utils/helpers.py +53 -0
  165. junifer/utils/logging.py +14 -3
  166. junifer/utils/tests/test_helpers.py +35 -0
  167. {junifer-0.0.3.dev186.dist-info → junifer-0.0.4.dist-info}/METADATA +59 -28
  168. junifer-0.0.4.dist-info/RECORD +257 -0
  169. {junifer-0.0.3.dev186.dist-info → junifer-0.0.4.dist-info}/WHEEL +1 -1
  170. junifer/markers/falff/falff_estimator.py +0 -334
  171. junifer/markers/falff/tests/test_falff_estimator.py +0 -238
  172. junifer/markers/reho/reho_estimator.py +0 -515
  173. junifer/markers/reho/tests/test_reho_estimator.py +0 -260
  174. junifer-0.0.3.dev186.dist-info/RECORD +0 -199
  175. {junifer-0.0.3.dev186.dist-info → junifer-0.0.4.dist-info}/AUTHORS.rst +0 -0
  176. {junifer-0.0.3.dev186.dist-info → junifer-0.0.4.dist-info}/LICENSE.md +0 -0
  177. {junifer-0.0.3.dev186.dist-info → junifer-0.0.4.dist-info}/entry_points.txt +0 -0
  178. {junifer-0.0.3.dev186.dist-info → junifer-0.0.4.dist-info}/top_level.txt +0 -0
@@ -1,118 +1,120 @@
1
- """Provide tests for ReHo on spheres."""
1
+ """Provide tests for ReHoSpheres."""
2
2
 
3
3
  # Authors: Synchon Mandal <s.mandal@fz-juelich.de>
4
4
  # License: AGPL
5
5
 
6
+ import logging
6
7
  from pathlib import Path
7
8
 
8
9
  import pytest
9
- from nilearn import image as nimg
10
- from scipy.stats import pearsonr
10
+ import scipy as sp
11
11
 
12
- from junifer.markers.reho.reho_spheres import ReHoSpheres
12
+ from junifer.datareader import DefaultDataReader
13
+ from junifer.markers import ReHoSpheres
14
+ from junifer.pipeline import WorkDirManager
13
15
  from junifer.pipeline.utils import _check_afni
14
- from junifer.storage.sqlite import SQLiteFeatureStorage
16
+ from junifer.storage import SQLiteFeatureStorage
15
17
  from junifer.testing.datagrabbers import SPMAuditoryTestingDataGrabber
16
18
 
17
19
 
18
20
  COORDINATES = "DMNBuckner"
19
21
 
20
22
 
21
- def test_reho_spheres_computation() -> None:
22
- """Test ReHoSpheres fit-transform."""
23
- with SPMAuditoryTestingDataGrabber() as dg:
24
- # Use first subject
25
- subject_data = dg["sub001"]
26
- # Load image to memory
27
- fmri_img = nimg.load_img(subject_data["BOLD"]["path"])
28
- # Initialize marker
29
- reho_spheres_marker = ReHoSpheres(coords=COORDINATES, radius=10.0)
30
- # Fit transform marker on data
31
- reho_spheres_output = reho_spheres_marker.fit_transform(
32
- {"BOLD": {"path": "/tmp", "data": fmri_img, "meta": {}}}
33
- )
34
- # Get BOLD output
35
- reho_spheres_output_bold = reho_spheres_output["BOLD"]
36
- # Assert BOLD output keys
37
- assert "data" in reho_spheres_output_bold
38
- assert "col_names" in reho_spheres_output_bold
23
+ def test_ReHoSpheres(caplog: pytest.LogCaptureFixture, tmp_path: Path) -> None:
24
+ """Test ReHoSpheres.
25
+
26
+ Parameters
27
+ ----------
28
+ caplog : pytest.LogCaptureFixture
29
+ The pytest.LogCaptureFixture object.
30
+ tmp_path : pathlib.Path
31
+ The path to the test directory.
39
32
 
40
- reho_spheres_output_bold_data = reho_spheres_output_bold["data"]
41
- # Assert BOLD output data dimension
42
- assert reho_spheres_output_bold_data.ndim == 2
43
- # Assert BOLD output data is normalized
44
- assert (reho_spheres_output_bold_data > 0).all() and (
45
- reho_spheres_output_bold_data < 1
46
- ).all()
33
+ """
34
+ with caplog.at_level(logging.DEBUG):
35
+ with SPMAuditoryTestingDataGrabber() as dg:
36
+ element_data = DefaultDataReader().fit_transform(dg["sub001"])
37
+ # Update workdir to current test's tmp_path
38
+ WorkDirManager().workdir = tmp_path
39
+ # Initialize marker
40
+ marker = ReHoSpheres(
41
+ coords=COORDINATES, using="junifer", radius=10.0
42
+ )
43
+ # Fit transform marker on data
44
+ output = marker.fit_transform(element_data)
45
+
46
+ assert "Creating cache" in caplog.text
47
+
48
+ # Get BOLD output
49
+ assert "BOLD" in output
50
+ output_bold = output["BOLD"]
51
+ # Assert BOLD output keys
52
+ assert "data" in output_bold
53
+ assert "col_names" in output_bold
54
+
55
+ output_bold_data = output_bold["data"]
56
+ # Assert BOLD output data dimension
57
+ assert output_bold_data.ndim == 2
58
+ # Assert BOLD output data is normalized
59
+ assert (output_bold_data > 0).all() and (
60
+ output_bold_data < 1
61
+ ).all()
62
+
63
+ # Reset log capture
64
+ caplog.clear()
65
+ # Initialize storage
66
+ storage = SQLiteFeatureStorage(tmp_path / "reho_spheres.sqlite")
67
+ # Fit transform marker on data with storage
68
+ marker.fit_transform(
69
+ input=element_data,
70
+ storage=storage,
71
+ )
72
+ # Cache working correctly
73
+ assert "Creating cache" not in caplog.text
47
74
 
48
75
 
49
76
  @pytest.mark.skipif(
50
- _check_afni() is False, reason="requires afni to be in PATH"
77
+ _check_afni() is False, reason="requires AFNI to be in PATH"
51
78
  )
52
- def test_reho_spheres_computation_comparison() -> None:
53
- """Test ReHoSpheres fit-transform implementation comparison.."""
79
+ def test_ReHoSpheres_comparison(tmp_path: Path) -> None:
80
+ """Test ReHoSpheres implementation comparison.
81
+
82
+ Parameters
83
+ ----------
84
+ tmp_path : pathlib.Path
85
+ The path to the test directory.
86
+
87
+ """
54
88
  with SPMAuditoryTestingDataGrabber() as dg:
55
- # Use first subject
56
- subject_data = dg["sub001"]
57
- # Load image to memory
58
- fmri_img = nimg.load_img(subject_data["BOLD"]["path"])
59
-
60
- # Initialize marker with use_afni=False
61
- reho_spheres_marker_python = ReHoSpheres(
62
- coords=COORDINATES, radius=10.0, use_afni=False
89
+ element_data = DefaultDataReader().fit_transform(dg["sub001"])
90
+ # Update workdir to current test's tmp_path
91
+ WorkDirManager().workdir = tmp_path
92
+
93
+ # Initialize marker
94
+ junifer_marker = ReHoSpheres(
95
+ coords=COORDINATES,
96
+ using="junifer",
97
+ radius=10.0,
63
98
  )
64
99
  # Fit transform marker on data
65
- reho_spheres_output_python = reho_spheres_marker_python.fit_transform(
66
- {"BOLD": {"path": "/tmp", "data": fmri_img, "meta": {}}}
67
- )
100
+ junifer_output = junifer_marker.fit_transform(element_data)
68
101
  # Get BOLD output
69
- reho_spheres_output_bold_python = reho_spheres_output_python["BOLD"]
102
+ junifer_output_bold = junifer_output["BOLD"]
70
103
 
71
- # Initialize marker with use_afni=True
72
- reho_spheres_marker_afni = ReHoSpheres(
73
- coords=COORDINATES, radius=10.0, use_afni=True
104
+ # Initialize marker
105
+ afni_marker = ReHoSpheres(
106
+ coords=COORDINATES,
107
+ using="afni",
108
+ radius=10.0,
74
109
  )
75
110
  # Fit transform marker on data
76
- reho_spheres_output_afni = reho_spheres_marker_afni.fit_transform(
77
- {"BOLD": {"path": "/tmp", "data": fmri_img, "meta": {}}}
78
- )
111
+ afni_output = afni_marker.fit_transform(element_data)
79
112
  # Get BOLD output
80
- reho_spheres_output_bold_afni = reho_spheres_output_afni["BOLD"]
113
+ afni_output_bold = afni_output["BOLD"]
81
114
 
82
115
  # Check for Pearson correlation coefficient
83
- r, _ = pearsonr(
84
- reho_spheres_output_bold_python["data"].flatten(),
85
- reho_spheres_output_bold_afni["data"].flatten(),
116
+ r, _ = sp.stats.pearsonr(
117
+ junifer_output_bold["data"].flatten(),
118
+ afni_output_bold["data"].flatten(),
86
119
  )
87
120
  assert r >= 0.8 # 0.8 is a loose threshold
88
-
89
-
90
- def test_reho_spheres_storage(tmp_path: Path) -> None:
91
- """Test ReHoSpheres storage.
92
-
93
- Parameters
94
- ----------
95
- tmp_path : pathlib.Path
96
- The path to the test directory.
97
-
98
- """
99
- with SPMAuditoryTestingDataGrabber() as dg:
100
- # Use first subject
101
- subject_data = dg["sub001"]
102
- # Load image to memory
103
- fmri_img = nimg.load_img(subject_data["BOLD"]["path"])
104
- # Initialize marker
105
- reho_spheres_marker = ReHoSpheres(coords=COORDINATES, radius=10.0)
106
- # Initialize storage
107
- reho_spheres_storage = SQLiteFeatureStorage(
108
- tmp_path / "reho_spheres.sqlite"
109
- )
110
- # Generate meta
111
- meta = {
112
- "element": {"subject": "sub001"}
113
- } # only requires element key for storing
114
- # Fit transform marker on data with storage
115
- reho_spheres_marker.fit_transform(
116
- input={"BOLD": {"path": "/tmp", "data": fmri_img, "meta": meta}},
117
- storage=reho_spheres_storage,
118
- )
@@ -7,7 +7,7 @@
7
7
  from typing import Any, ClassVar, Dict, List, Optional, Set, Union
8
8
 
9
9
  from ..api.decorators import register_marker
10
- from ..data import get_mask, load_coordinates
10
+ from ..data import get_coordinates, get_mask
11
11
  from ..external.nilearn import JuniferNiftiSpheresMasker
12
12
  from ..stats import get_aggfunc_by_name
13
13
  from ..utils import logger, raise_error, warn_with_log
@@ -47,14 +47,20 @@ class SphereAggregation(BaseMarker):
47
47
  The specification of the masks to apply to regions before extracting
48
48
  signals. Check :ref:`Using Masks <using_masks>` for more details.
49
49
  If None, will not apply any mask (default None).
50
- on : {"T1w", "BOLD", "VBM_GM", "VBM_WM", "fALFF", "GCOR", "LCOR"} or \
51
- list of the options, optional
50
+ on : {"T1w", "T2w", "BOLD", "VBM_GM", "VBM_WM", "VBM_CSF", "fALFF", \
51
+ "GCOR", "LCOR"} or list of the options, optional
52
52
  The data types to apply the marker to. If None, will work on all
53
53
  available data (default None).
54
54
  name : str, optional
55
55
  The name of the marker. By default, it will use KIND_SphereAggregation
56
56
  where KIND is the kind of data it was applied to (default None).
57
57
 
58
+ Raises
59
+ ------
60
+ ValueError
61
+ If ``time_method`` is specified for non-BOLD data or if
62
+ ``time_method_params`` is not None when ``time_method`` is None.
63
+
58
64
  """
59
65
 
60
66
  _DEPENDENCIES: ClassVar[Set[str]] = {"nilearn", "numpy"}
@@ -103,7 +109,17 @@ class SphereAggregation(BaseMarker):
103
109
  The list of data types that can be used as input for this marker.
104
110
 
105
111
  """
106
- return ["T1w", "BOLD", "VBM_GM", "VBM_WM", "fALFF", "GCOR", "LCOR"]
112
+ return [
113
+ "T1w",
114
+ "T2w",
115
+ "BOLD",
116
+ "VBM_GM",
117
+ "VBM_WM",
118
+ "VBM_CSF",
119
+ "fALFF",
120
+ "GCOR",
121
+ "LCOR",
122
+ ]
107
123
 
108
124
  def get_output_type(self, input_type: str) -> str:
109
125
  """Get output type.
@@ -118,14 +134,26 @@ class SphereAggregation(BaseMarker):
118
134
  str
119
135
  The storage type output by the marker.
120
136
 
137
+ Raises
138
+ ------
139
+ ValueError
140
+ If the ``input_type`` is invalid.
141
+
121
142
  """
122
143
 
123
- if input_type in ["VBM_GM", "VBM_WM", "fALFF", "GCOR", "LCOR"]:
144
+ if input_type in [
145
+ "VBM_GM",
146
+ "VBM_WM",
147
+ "VBM_CSF",
148
+ "fALFF",
149
+ "GCOR",
150
+ "LCOR",
151
+ ]:
124
152
  return "vector"
125
153
  elif input_type == "BOLD":
126
154
  return "timeseries"
127
155
  else:
128
- raise ValueError(f"Unknown input kind for {input_type}")
156
+ raise_error(f"Unknown input kind for {input_type}")
129
157
 
130
158
  def compute(
131
159
  self,
@@ -155,6 +183,11 @@ class SphereAggregation(BaseMarker):
155
183
  * ``data`` : the actual computed values as a numpy.ndarray
156
184
  * ``col_names`` : the column labels for the computed values as list
157
185
 
186
+ Warns
187
+ -----
188
+ RuntimeWarning
189
+ If time aggregation is required but only time point is available.
190
+
158
191
  """
159
192
  t_input_img = input["data"]
160
193
  logger.debug(f"Sphere aggregation using {self.method}")
@@ -162,15 +195,25 @@ class SphereAggregation(BaseMarker):
162
195
  agg_func = get_aggfunc_by_name(
163
196
  self.method, func_params=self.method_params
164
197
  )
198
+
199
+ # Get seeds and labels tailored to target image
200
+ coords, labels = get_coordinates(
201
+ coords=self.coords,
202
+ target_data=input,
203
+ extra_input=extra_input,
204
+ )
205
+
165
206
  # Load mask
166
207
  mask_img = None
167
208
  if self.masks is not None:
168
209
  logger.debug(f"Masking with {self.masks}")
210
+ # Get tailored mask
169
211
  mask_img = get_mask(
170
212
  masks=self.masks, target_data=input, extra_input=extra_input
171
213
  )
172
- # Get seeds and labels
173
- coords, out_labels = load_coordinates(name=self.coords)
214
+
215
+ # Initialize masker
216
+ logger.debug("Masking")
174
217
  masker = JuniferNiftiSpheresMasker(
175
218
  seeds=coords,
176
219
  radius=self.radius,
@@ -180,6 +223,8 @@ class SphereAggregation(BaseMarker):
180
223
  )
181
224
  # Fit and transform the marker on the data
182
225
  out_values = masker.fit_transform(t_input_img)
226
+
227
+ # Apply time dimension aggregation if required
183
228
  if self.time_method is not None:
184
229
  if out_values.shape[0] > 1:
185
230
  logger.debug("Aggregating time dimension")
@@ -193,5 +238,5 @@ class SphereAggregation(BaseMarker):
193
238
  "available."
194
239
  )
195
240
  # Format the output
196
- out = {"data": out_values, "col_names": out_labels}
241
+ out = {"data": out_values, "col_names": labels}
197
242
  return out
@@ -65,6 +65,7 @@ class TemporalSNRBase(BaseMarker):
65
65
  -------
66
66
  list of str
67
67
  The list of data types that can be used as input for this marker.
68
+
68
69
  """
69
70
  return ["BOLD"]
70
71
 
@@ -1,18 +1,39 @@
1
1
  """Provide tests for temporal signal-to-noise ratio using parcellation."""
2
2
 
3
3
  # Authors: Leonard Sasse <l.sasse@fz-juelich.de>
4
+ # Synchon Mandal <s.mandal@fz-juelich.de>
4
5
  # License: AGPL
5
6
 
6
7
  from pathlib import Path
7
8
 
8
- from nilearn import datasets, image
9
-
9
+ from junifer.datareader import DefaultDataReader
10
10
  from junifer.markers.temporal_snr import TemporalSNRParcels
11
- from junifer.storage import SQLiteFeatureStorage
11
+ from junifer.storage import HDF5FeatureStorage
12
+ from junifer.testing.datagrabbers import PartlyCloudyTestingDataGrabber
13
+
14
+
15
+ def test_TemporalSNRParcels_computation() -> None:
16
+ """Test TemporalSNRParcels fit-transform."""
17
+ with PartlyCloudyTestingDataGrabber() as dg:
18
+ element_data = DefaultDataReader().fit_transform(dg["sub-01"])
19
+ marker = TemporalSNRParcels(
20
+ parcellation="TianxS1x3TxMNInonlinear2009cAsym"
21
+ )
22
+ # Check correct output
23
+ assert marker.get_output_type("BOLD") == "vector"
24
+
25
+ # Fit-transform the data
26
+ tsnr_parcels = marker.fit_transform(element_data)
27
+ tsnr_parcels_bold = tsnr_parcels["BOLD"]
28
+
29
+ assert "data" in tsnr_parcels_bold
30
+ assert "col_names" in tsnr_parcels_bold
31
+ assert tsnr_parcels_bold["data"].shape == (1, 16)
32
+ assert len(set(tsnr_parcels_bold["col_names"])) == 16
12
33
 
13
34
 
14
- def test_TemporalSNRParcels(tmp_path: Path) -> None:
15
- """Test TemporalSNRParcels.
35
+ def test_TemporalSNRParcels_storage(tmp_path: Path) -> None:
36
+ """Test TemporalSNRParcels store.
16
37
 
17
38
  Parameters
18
39
  ----------
@@ -20,35 +41,15 @@ def test_TemporalSNRParcels(tmp_path: Path) -> None:
20
41
  The path to the test directory.
21
42
 
22
43
  """
23
- # get a dataset
24
- ni_data = datasets.fetch_spm_auditory(subject_id="sub001")
25
- fmri_img = image.concat_imgs(ni_data.func) # type: ignore
26
-
27
- tsnr_parcels = TemporalSNRParcels(parcellation="Schaefer100x7")
28
- all_out = tsnr_parcels.fit_transform(
29
- {"BOLD": {"data": fmri_img, "meta": {}}}
30
- )
31
-
32
- out = all_out["BOLD"]
33
-
34
- assert "data" in out
35
- assert "col_names" in out
36
-
37
- assert out["data"].shape[0] == 1
38
- assert out["data"].shape[1] == 100
39
- assert len(set(out["col_names"])) == 100
40
-
41
- # check correct output
42
- assert tsnr_parcels.get_output_type("BOLD") == "vector"
43
-
44
- uri = tmp_path / "test_tsnr_parcellation.sqlite"
45
- # Single storage, must be the uri
46
- storage = SQLiteFeatureStorage(uri=uri, upsert="ignore")
47
- meta = {"element": {"subject": "test"}, "dependencies": {"numpy"}}
48
- input = {"BOLD": {"data": fmri_img, "meta": meta}}
49
- all_out = tsnr_parcels.fit_transform(input, storage=storage)
50
-
51
- features = storage.list_features()
52
- assert any(
53
- x["name"] == "BOLD_TemporalSNRParcels" for x in features.values()
54
- )
44
+ with PartlyCloudyTestingDataGrabber() as dg:
45
+ element_data = DefaultDataReader().fit_transform(dg["sub-01"])
46
+ marker = TemporalSNRParcels(
47
+ parcellation="TianxS1x3TxMNInonlinear2009cAsym"
48
+ )
49
+ # Store
50
+ storage = HDF5FeatureStorage(tmp_path / "test_tsnr_parcels.hdf5")
51
+ marker.fit_transform(input=element_data, storage=storage)
52
+ features = storage.list_features()
53
+ assert any(
54
+ x["name"] == "BOLD_TemporalSNRParcels" for x in features.values()
55
+ )
@@ -1,19 +1,39 @@
1
1
  """Provide tests for temporal signal-to-noise spheres."""
2
2
 
3
3
  # Authors: Leonard Sasse <l.sasse@fz-juelich.de>
4
+ # Synchon Mandal <s.mandal@fz-juelich.de>
4
5
  # License: AGPL
5
6
 
6
7
  from pathlib import Path
7
8
 
8
9
  import pytest
9
- from nilearn import datasets, image
10
10
 
11
+ from junifer.datareader import DefaultDataReader
11
12
  from junifer.markers.temporal_snr import TemporalSNRSpheres
12
- from junifer.storage import SQLiteFeatureStorage
13
+ from junifer.storage import HDF5FeatureStorage
14
+ from junifer.testing.datagrabbers import SPMAuditoryTestingDataGrabber
13
15
 
14
16
 
15
- def test_TemporalSNRSpheres(tmp_path: Path) -> None:
16
- """Test TemporalSNRSpheres.
17
+ def test_TemporalSNRSpheres_computation() -> None:
18
+ """Test TemporalSNRSpheres fit-transform."""
19
+ with SPMAuditoryTestingDataGrabber() as dg:
20
+ element_data = DefaultDataReader().fit_transform(dg["sub001"])
21
+ marker = TemporalSNRSpheres(coords="DMNBuckner", radius=5.0)
22
+ # Check correct output
23
+ assert marker.get_output_type("BOLD") == "vector"
24
+
25
+ # Fit-transform the data
26
+ tsnr_spheres = marker.fit_transform(element_data)
27
+ tsnr_spheres_bold = tsnr_spheres["BOLD"]
28
+
29
+ assert "data" in tsnr_spheres_bold
30
+ assert "col_names" in tsnr_spheres_bold
31
+ assert tsnr_spheres_bold["data"].shape == (1, 6)
32
+ assert len(set(tsnr_spheres_bold["col_names"])) == 6
33
+
34
+
35
+ def test_TemporalSNRSpheres_storage(tmp_path: Path) -> None:
36
+ """Test TemporalSNRSpheres store.
17
37
 
18
38
  Parameters
19
39
  ----------
@@ -21,40 +41,16 @@ def test_TemporalSNRSpheres(tmp_path: Path) -> None:
21
41
  The path to the test directory.
22
42
 
23
43
  """
24
- # get a dataset
25
- ni_data = datasets.fetch_spm_auditory(subject_id="sub001")
26
- fmri_img = image.concat_imgs(ni_data.func) # type: ignore
27
-
28
- tsnr_spheres = TemporalSNRSpheres(coords="DMNBuckner", radius=5.0)
29
- all_out = tsnr_spheres.fit_transform(
30
- {"BOLD": {"data": fmri_img, "meta": {}}}
31
- )
32
-
33
- out = all_out["BOLD"]
34
-
35
- assert "data" in out
36
- assert "col_names" in out
37
- assert out["data"].shape[0] == 1
38
- assert out["data"].shape[1] == 6
39
- assert len(set(out["col_names"])) == 6
40
-
41
- # check correct output
42
- assert tsnr_spheres.get_output_type("BOLD") == "vector"
43
-
44
- uri = tmp_path / "test_tsnr_coords.sqlite"
45
- # Single storage, must be the uri
46
- storage = SQLiteFeatureStorage(uri=uri, upsert="ignore")
47
- meta = {
48
- "element": {"subject": "test"},
49
- "dependencies": {"numpy", "nilearn"},
50
- }
51
- input = {"BOLD": {"data": fmri_img, "meta": meta}}
52
- all_out = tsnr_spheres.fit_transform(input, storage=storage)
53
-
54
- features = storage.list_features()
55
- assert any(
56
- x["name"] == "BOLD_TemporalSNRSpheres" for x in features.values()
57
- )
44
+ with SPMAuditoryTestingDataGrabber() as dg:
45
+ element_data = DefaultDataReader().fit_transform(dg["sub001"])
46
+ marker = TemporalSNRSpheres(coords="DMNBuckner", radius=5.0)
47
+ # Store
48
+ storage = HDF5FeatureStorage(tmp_path / "test_tsnr_spheres.hdf5")
49
+ marker.fit_transform(input=element_data, storage=storage)
50
+ features = storage.list_features()
51
+ assert any(
52
+ x["name"] == "BOLD_TemporalSNRSpheres" for x in features.values()
53
+ )
58
54
 
59
55
 
60
56
  def test_TemporalSNRSpheres_error() -> None: