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
@@ -6,10 +6,10 @@
6
6
 
7
7
  from pathlib import Path
8
8
 
9
- from nilearn import datasets, image
10
-
9
+ from junifer.datareader import DefaultDataReader
11
10
  from junifer.markers.functional_connectivity import EdgeCentricFCParcels
12
11
  from junifer.storage import SQLiteFeatureStorage
12
+ from junifer.testing.datagrabbers import PartlyCloudyTestingDataGrabber
13
13
 
14
14
 
15
15
  def test_EdgeCentricFCParcels(tmp_path: Path) -> None:
@@ -21,40 +21,35 @@ def test_EdgeCentricFCParcels(tmp_path: Path) -> None:
21
21
  The path to the test directory.
22
22
 
23
23
  """
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
- # Check empirical correlation method parameters
29
- efc = EdgeCentricFCParcels(
30
- parcellation="TianxS1x3TxMNInonlinear2009cAsym",
31
- cor_method_params={"empirical": True},
32
- )
33
- all_out = efc.fit_transform({"BOLD": {"data": fmri_img, "meta": {}}})
34
-
35
- out = all_out["BOLD"]
36
-
37
- # for 16 ROIs we should get (16 * (16 -1) / 2) edges in the ETS
38
- n_edges = int(16 * (16 - 1) / 2)
39
- assert "data" in out
40
- assert "row_names" in out
41
- assert "col_names" in out
42
- assert out["data"].shape[0] == n_edges
43
- assert out["data"].shape[1] == n_edges
44
- assert len(set(out["row_names"])) == n_edges
45
- assert len(set(out["col_names"])) == n_edges
46
-
47
- # check correct output
48
- assert efc.get_output_type("BOLD") == "matrix"
49
-
50
- uri = tmp_path / "test_fc_parcellation.sqlite"
51
- # Single storage, must be the uri
52
- storage = SQLiteFeatureStorage(uri=uri, upsert="ignore")
53
- meta = {"element": {"subject": "test"}, "dependencies": {"numpy"}}
54
- input = {"BOLD": {"data": fmri_img, "meta": meta}}
55
- all_out = efc.fit_transform(input, storage=storage)
56
-
57
- features = storage.list_features()
58
- assert any(
59
- x["name"] == "BOLD_EdgeCentricFCParcels" for x in features.values()
60
- )
24
+ with PartlyCloudyTestingDataGrabber() as dg:
25
+ element_data = DefaultDataReader().fit_transform(dg["sub-01"])
26
+ marker = EdgeCentricFCParcels(
27
+ parcellation="TianxS1x3TxMNInonlinear2009cAsym",
28
+ cor_method_params={"empirical": True},
29
+ )
30
+ # Check correct output
31
+ assert marker.get_output_type("BOLD") == "matrix"
32
+
33
+ # Fit-transform the data
34
+ edge_fc = marker.fit_transform(element_data)
35
+ edge_fc_bold = edge_fc["BOLD"]
36
+
37
+ # For 16 ROIs we should get (16 * (16 -1) / 2) edges in the ETS
38
+ n_edges = int(16 * (16 - 1) / 2)
39
+ assert "data" in edge_fc_bold
40
+ assert "row_names" in edge_fc_bold
41
+ assert "col_names" in edge_fc_bold
42
+ assert edge_fc_bold["data"].shape[0] == n_edges
43
+ assert edge_fc_bold["data"].shape[1] == n_edges
44
+ assert len(set(edge_fc_bold["row_names"])) == n_edges
45
+ assert len(set(edge_fc_bold["col_names"])) == n_edges
46
+
47
+ # Store
48
+ storage = SQLiteFeatureStorage(
49
+ uri=tmp_path / "test_edge_fc_parcels.sqlite", upsert="ignore"
50
+ )
51
+ marker.fit_transform(input=element_data, storage=storage)
52
+ features = storage.list_features()
53
+ assert any(
54
+ x["name"] == "BOLD_EdgeCentricFCParcels" for x in features.values()
55
+ )
@@ -6,10 +6,10 @@
6
6
 
7
7
  from pathlib import Path
8
8
 
9
- from nilearn import datasets, image
10
-
9
+ from junifer.datareader import DefaultDataReader
11
10
  from junifer.markers.functional_connectivity import EdgeCentricFCSpheres
12
11
  from junifer.storage import SQLiteFeatureStorage
12
+ from junifer.testing.datagrabbers import SPMAuditoryTestingDataGrabber
13
13
 
14
14
 
15
15
  def test_EdgeCentricFCSpheres(tmp_path: Path) -> None:
@@ -21,53 +21,41 @@ def test_EdgeCentricFCSpheres(tmp_path: Path) -> None:
21
21
  The path to the test directory.
22
22
 
23
23
  """
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
- efc = EdgeCentricFCSpheres(
29
- coords="DMNBuckner", radius=5.0, cor_method="correlation"
30
- )
31
- all_out = efc.fit_transform({"BOLD": {"data": fmri_img, "meta": {}}})
32
-
33
- out = all_out["BOLD"]
34
-
35
- # There are six DMNBuckner coordinates, so
36
- # for 6 ROIs we should get (6 * (6 -1) / 2) edges in the ETS
37
- n_edges = int(6 * (6 - 1) / 2)
38
- assert "data" in out
39
- assert "row_names" in out
40
- assert "col_names" in out
41
- assert out["data"].shape[0] == n_edges
42
- assert out["data"].shape[1] == n_edges
43
- assert len(set(out["row_names"])) == n_edges
44
- assert len(set(out["col_names"])) == n_edges
45
-
46
- # check correct output
47
- assert efc.get_output_type("BOLD") == "matrix"
48
-
49
- # Check empirical correlation method parameters
50
- efc = EdgeCentricFCSpheres(
51
- coords="DMNBuckner",
52
- radius=5.0,
53
- cor_method="correlation",
54
- cor_method_params={"empirical": True},
55
- )
56
-
57
- meta = {
58
- "element": {"subject": "sub001"},
59
- "dependencies": {"nilearn"},
60
- }
61
- all_out = efc.fit_transform({"BOLD": {"data": fmri_img, "meta": meta}})
62
-
63
- uri = tmp_path / "test_fc_parcellation.sqlite"
64
- # Single storage, must be the uri
65
- storage = SQLiteFeatureStorage(uri=uri, upsert="ignore")
66
- meta = {"element": {"subject": "test"}, "dependencies": {"numpy"}}
67
- input = {"BOLD": {"data": fmri_img, "meta": meta}}
68
- all_out = efc.fit_transform(input, storage=storage)
69
-
70
- features = storage.list_features()
71
- assert any(
72
- x["name"] == "BOLD_EdgeCentricFCSpheres" for x in features.values()
73
- )
24
+ with SPMAuditoryTestingDataGrabber() as dg:
25
+ element_data = DefaultDataReader().fit_transform(dg["sub001"])
26
+ marker = EdgeCentricFCSpheres(
27
+ coords="DMNBuckner", radius=5.0, cor_method="correlation"
28
+ )
29
+ # Check correct output
30
+ assert marker.get_output_type("BOLD") == "matrix"
31
+
32
+ # Fit-transform the data
33
+ edge_fc = marker.fit_transform(element_data)
34
+ edge_fc_bold = edge_fc["BOLD"]
35
+
36
+ # There are six DMNBuckner coordinates, so
37
+ # for 6 ROIs we should get (6 * (6 -1) / 2) edges in the ETS
38
+ n_edges = int(6 * (6 - 1) / 2)
39
+ assert "data" in edge_fc_bold
40
+ assert "row_names" in edge_fc_bold
41
+ assert "col_names" in edge_fc_bold
42
+ assert edge_fc_bold["data"].shape == (n_edges, n_edges)
43
+ assert len(set(edge_fc_bold["row_names"])) == n_edges
44
+ assert len(set(edge_fc_bold["col_names"])) == n_edges
45
+
46
+ # Check empirical correlation method parameters
47
+ marker = EdgeCentricFCSpheres(
48
+ coords="DMNBuckner",
49
+ radius=5.0,
50
+ cor_method="correlation",
51
+ cor_method_params={"empirical": True},
52
+ )
53
+ # Store
54
+ storage = SQLiteFeatureStorage(
55
+ uri=tmp_path / "test_edge_fc_spheres.sqlite", upsert="ignore"
56
+ )
57
+ marker.fit_transform(input=element_data, storage=storage)
58
+ features = storage.list_features()
59
+ assert any(
60
+ x["name"] == "BOLD_EdgeCentricFCSpheres" for x in features.values()
61
+ )
@@ -2,20 +2,22 @@
2
2
 
3
3
  # Authors: Amir Omidvarnia <a.omidvarnia@fz-juelich.de>
4
4
  # Kaustubh R. Patil <k.patil@fz-juelich.de>
5
+ # Synchon Mandal <s.mandal@fz-juelich.de>
5
6
  # License: AGPL
6
7
 
7
8
  from pathlib import Path
8
9
 
9
- from nilearn import datasets, image
10
10
  from nilearn.connectome import ConnectivityMeasure
11
11
  from nilearn.maskers import NiftiLabelsMasker
12
- from numpy.testing import assert_array_almost_equal, assert_array_equal
12
+ from numpy.testing import assert_array_almost_equal
13
13
 
14
+ from junifer.data import get_parcellation
15
+ from junifer.datareader import DefaultDataReader
14
16
  from junifer.markers.functional_connectivity import (
15
17
  FunctionalConnectivityParcels,
16
18
  )
17
- from junifer.markers.parcel_aggregation import ParcelAggregation
18
19
  from junifer.storage import SQLiteFeatureStorage
20
+ from junifer.testing.datagrabbers import PartlyCloudyTestingDataGrabber
19
21
 
20
22
 
21
23
  def test_FunctionalConnectivityParcels(tmp_path: Path) -> None:
@@ -27,70 +29,60 @@ def test_FunctionalConnectivityParcels(tmp_path: Path) -> None:
27
29
  The path to the test directory.
28
30
 
29
31
  """
30
- # get a dataset
31
- ni_data = datasets.fetch_spm_auditory(subject_id="sub001")
32
- fmri_img = image.concat_imgs(ni_data.func) # type: ignore
33
-
34
- fc = FunctionalConnectivityParcels(parcellation="Schaefer100x7")
35
- all_out = fc.fit_transform({"BOLD": {"data": fmri_img, "meta": {}}})
36
-
37
- out = all_out["BOLD"]
38
-
39
- assert "data" in out
40
- assert "row_names" in out
41
- assert "col_names" in out
42
- assert out["data"].shape[0] == 100
43
- assert out["data"].shape[1] == 100
44
- assert len(set(out["row_names"])) == 100
45
- assert len(set(out["col_names"])) == 100
46
-
47
- # get the timeseries using pa
48
- pa = ParcelAggregation(
49
- parcellation="Schaefer100x7", method="mean", on="BOLD"
50
- )
51
- meta = {
52
- "element": {"subject": "sub001"},
53
- "dependencies": {"nilearn"},
54
- }
55
- ts = pa.compute({"data": fmri_img, "meta": meta})
56
-
57
- # compare with nilearn
58
- # Get the testing parcellation (for nilearn)
59
- parcellation = datasets.fetch_atlas_schaefer_2018(
60
- n_rois=100, yeo_networks=7, resolution_mm=2
61
- )
62
- masker = NiftiLabelsMasker(
63
- labels_img=parcellation["maps"], standardize=False
64
- )
65
- ts_ni = masker.fit_transform(fmri_img)
66
-
67
- # check the TS are almost equal
68
- assert_array_equal(ts_ni, ts["data"])
69
-
70
- # Check that FC are almost equal
71
- cm = ConnectivityMeasure(kind="covariance")
72
- out_ni = cm.fit_transform([ts_ni])[0]
73
- assert_array_almost_equal(out_ni, out["data"], decimal=3)
74
-
75
- # check correct output
76
- assert fc.get_output_type("BOLD") == "matrix"
77
-
78
- # Check empirical correlation method parameters
79
- fc = FunctionalConnectivityParcels(
80
- parcellation="Schaefer100x7", cor_method_params={"empirical": True}
81
- )
82
-
83
- all_out = fc.fit_transform({"BOLD": {"data": fmri_img, "meta": meta}})
84
-
85
- uri = tmp_path / "test_fc_parcellation.sqlite"
86
- # Single storage, must be the uri
87
- storage = SQLiteFeatureStorage(uri=uri, upsert="ignore")
88
- meta = {"element": {"subject": "test"}, "dependencies": {"numpy"}}
89
- input = {"BOLD": {"data": fmri_img, "meta": meta}}
90
- all_out = fc.fit_transform(input, storage=storage)
91
-
92
- features = storage.list_features()
93
- assert any(
94
- x["name"] == "BOLD_FunctionalConnectivityParcels"
95
- for x in features.values()
96
- )
32
+ with PartlyCloudyTestingDataGrabber() as dg:
33
+ element_data = DefaultDataReader().fit_transform(dg["sub-01"])
34
+ marker = FunctionalConnectivityParcels(
35
+ parcellation="TianxS1x3TxMNInonlinear2009cAsym"
36
+ )
37
+ # Check correct output
38
+ assert marker.get_output_type("BOLD") == "matrix"
39
+
40
+ # Fit-transform the data
41
+ fc = marker.fit_transform(element_data)
42
+ fc_bold = fc["BOLD"]
43
+
44
+ assert "data" in fc_bold
45
+ assert "row_names" in fc_bold
46
+ assert "col_names" in fc_bold
47
+ assert fc_bold["data"].shape == (16, 16)
48
+ assert len(set(fc_bold["row_names"])) == 16
49
+ assert len(set(fc_bold["col_names"])) == 16
50
+
51
+ # Compare with nilearn
52
+ # Load testing parcellation for the target data
53
+ testing_parcellation, _ = get_parcellation(
54
+ parcellation=["TianxS1x3TxMNInonlinear2009cAsym"],
55
+ target_data=element_data["BOLD"],
56
+ )
57
+ # Extract timeseries
58
+ nifti_labels_masker = NiftiLabelsMasker(
59
+ labels_img=testing_parcellation, standardize=False
60
+ )
61
+ extracted_timeseries = nifti_labels_masker.fit_transform(
62
+ element_data["BOLD"]["data"]
63
+ )
64
+ # Compute the connectivity measure
65
+ connectivity_measure = ConnectivityMeasure(
66
+ kind="covariance"
67
+ ).fit_transform([extracted_timeseries])[0]
68
+
69
+ # Check that FC are almost equal
70
+ assert_array_almost_equal(
71
+ connectivity_measure, fc_bold["data"], decimal=3
72
+ )
73
+
74
+ # Check empirical correlation method parameters
75
+ marker = FunctionalConnectivityParcels(
76
+ parcellation="TianxS1x3TxMNInonlinear2009cAsym",
77
+ cor_method_params={"empirical": True},
78
+ )
79
+ # Store
80
+ storage = SQLiteFeatureStorage(
81
+ uri=tmp_path / "test_fc_parcels.sqlite", upsert="ignore"
82
+ )
83
+ marker.fit_transform(input=element_data, storage=storage)
84
+ features = storage.list_features()
85
+ assert any(
86
+ x["name"] == "BOLD_FunctionalConnectivityParcels"
87
+ for x in features.values()
88
+ )
@@ -3,21 +3,24 @@
3
3
  # Authors: Amir Omidvarnia <a.omidvarnia@fz-juelich.de>
4
4
  # Kaustubh R. Patil <k.patil@fz-juelich.de>
5
5
  # Federico Raimondo <f.raimondo@fz-juelich.de>
6
+ # Synchon Mandal <s.mandal@fz-juelich.de>
6
7
  # License: AGPL
7
8
 
8
9
  from pathlib import Path
9
10
 
10
11
  import pytest
11
- from nilearn import datasets, image
12
12
  from nilearn.connectome import ConnectivityMeasure
13
+ from nilearn.maskers import NiftiSpheresMasker
13
14
  from numpy.testing import assert_array_almost_equal
14
15
  from sklearn.covariance import EmpiricalCovariance
15
16
 
17
+ from junifer.data import get_coordinates
18
+ from junifer.datareader import DefaultDataReader
16
19
  from junifer.markers.functional_connectivity import (
17
20
  FunctionalConnectivitySpheres,
18
21
  )
19
- from junifer.markers.sphere_aggregation import SphereAggregation
20
22
  from junifer.storage import SQLiteFeatureStorage
23
+ from junifer.testing.datagrabbers import SPMAuditoryTestingDataGrabber
21
24
 
22
25
 
23
26
  def test_FunctionalConnectivitySpheres(tmp_path: Path) -> None:
@@ -29,54 +32,57 @@ def test_FunctionalConnectivitySpheres(tmp_path: Path) -> None:
29
32
  The path to the test directory.
30
33
 
31
34
  """
32
- # get a dataset
33
- ni_data = datasets.fetch_spm_auditory(subject_id="sub001")
34
- fmri_img = image.concat_imgs(ni_data.func) # type: ignore
35
-
36
- fc = FunctionalConnectivitySpheres(
37
- coords="DMNBuckner", radius=5.0, cor_method="correlation"
38
- )
39
- all_out = fc.fit_transform({"BOLD": {"data": fmri_img, "meta": {}}})
40
-
41
- out = all_out["BOLD"]
42
-
43
- assert "data" in out
44
- assert "row_names" in out
45
- assert "col_names" in out
46
- assert out["data"].shape[0] == 6
47
- assert out["data"].shape[1] == 6
48
- assert len(set(out["row_names"])) == 6
49
- assert len(set(out["col_names"])) == 6
50
-
51
- # get the timeseries using sa
52
- sa = SphereAggregation(
53
- coords="DMNBuckner", radius=5.0, method="mean", on="BOLD"
54
- )
55
- ts = sa.compute({"data": fmri_img, "meta": {}})
56
-
57
- # Check that FC are almost equal when using nileran
58
- cm = ConnectivityMeasure(kind="correlation")
59
- out_ni = cm.fit_transform([ts["data"]])[0]
60
- assert_array_almost_equal(out_ni, out["data"], decimal=3)
61
-
62
- # check correct output
63
- assert fc.get_output_type("BOLD") == "matrix"
64
-
65
- uri = tmp_path / "test_fc_parcel.sqlite"
66
- # Single storage, must be the uri
67
- storage = SQLiteFeatureStorage(uri=uri, upsert="ignore")
68
- meta = {
69
- "element": {"subject": "test"},
70
- "dependencies": {"numpy", "nilearn"},
71
- }
72
- input = {"BOLD": {"data": fmri_img, "meta": meta}}
73
- all_out = fc.fit_transform(input, storage=storage)
74
-
75
- features = storage.list_features()
76
- assert any(
77
- x["name"] == "BOLD_FunctionalConnectivitySpheres"
78
- for x in features.values()
79
- )
35
+ with SPMAuditoryTestingDataGrabber() as dg:
36
+ element_data = DefaultDataReader().fit_transform(dg["sub001"])
37
+ marker = FunctionalConnectivitySpheres(
38
+ coords="DMNBuckner", radius=5.0, cor_method="correlation"
39
+ )
40
+ # Check correct output
41
+ assert marker.get_output_type("BOLD") == "matrix"
42
+
43
+ # Fit-transform the data
44
+ fc = marker.fit_transform(element_data)
45
+ fc_bold = fc["BOLD"]
46
+
47
+ assert "data" in fc_bold
48
+ assert "row_names" in fc_bold
49
+ assert "col_names" in fc_bold
50
+ assert fc_bold["data"].shape == (6, 6)
51
+ assert len(set(fc_bold["row_names"])) == 6
52
+ assert len(set(fc_bold["col_names"])) == 6
53
+
54
+ # Compare with nilearn
55
+ # Load testing coordinates for the target data
56
+ testing_coords, _ = get_coordinates(
57
+ coords="DMNBuckner", target_data=element_data["BOLD"]
58
+ )
59
+ # Extract timeseries
60
+ nifti_spheres_masker = NiftiSpheresMasker(
61
+ seeds=testing_coords, radius=5.0
62
+ )
63
+ extracted_timeseries = nifti_spheres_masker.fit_transform(
64
+ element_data["BOLD"]["data"]
65
+ )
66
+ # Compute the connectivity measure
67
+ connectivity_measure = ConnectivityMeasure(
68
+ kind="correlation"
69
+ ).fit_transform([extracted_timeseries])[0]
70
+
71
+ # Check that FC are almost equal
72
+ assert_array_almost_equal(
73
+ connectivity_measure, fc_bold["data"], decimal=3
74
+ )
75
+
76
+ # Store
77
+ storage = SQLiteFeatureStorage(
78
+ uri=tmp_path / "test_fc_spheres.sqlite", upsert="ignore"
79
+ )
80
+ marker.fit_transform(input=element_data, storage=storage)
81
+ features = storage.list_features()
82
+ assert any(
83
+ x["name"] == "BOLD_FunctionalConnectivitySpheres"
84
+ for x in features.values()
85
+ )
80
86
 
81
87
 
82
88
  def test_FunctionalConnectivitySpheres_empirical(tmp_path: Path) -> None:
@@ -88,41 +94,49 @@ def test_FunctionalConnectivitySpheres_empirical(tmp_path: Path) -> None:
88
94
  The path to the test directory.
89
95
 
90
96
  """
91
-
92
- # get a dataset
93
- ni_data = datasets.fetch_spm_auditory(subject_id="sub001")
94
- fmri_img = image.concat_imgs(ni_data.func) # type: ignore
95
-
96
- fc = FunctionalConnectivitySpheres(
97
- coords="DMNBuckner",
98
- radius=5.0,
99
- cor_method="correlation",
100
- cor_method_params={"empirical": True},
101
- )
102
- all_out = fc.fit_transform({"BOLD": {"data": fmri_img, "meta": {}}})
103
-
104
- out = all_out["BOLD"]
105
-
106
- assert "data" in out
107
- assert "row_names" in out
108
- assert "col_names" in out
109
- assert out["data"].shape[0] == 6
110
- assert out["data"].shape[1] == 6
111
- assert len(set(out["row_names"])) == 6
112
- assert len(set(out["col_names"])) == 6
113
-
114
- # get the timeseries using sa
115
- sa = SphereAggregation(
116
- coords="DMNBuckner", radius=5.0, method="mean", on="BOLD"
117
- )
118
- ts = sa.compute({"data": fmri_img})
119
-
120
- # Check that FC are almost equal when using nileran
121
- cm = ConnectivityMeasure(
122
- cov_estimator=EmpiricalCovariance(), kind="correlation" # type: ignore
123
- )
124
- out_ni = cm.fit_transform([ts["data"]])[0]
125
- assert_array_almost_equal(out_ni, out["data"], decimal=3)
97
+ with SPMAuditoryTestingDataGrabber() as dg:
98
+ element_data = DefaultDataReader().fit_transform(dg["sub001"])
99
+ marker = FunctionalConnectivitySpheres(
100
+ coords="DMNBuckner",
101
+ radius=5.0,
102
+ cor_method="correlation",
103
+ cor_method_params={"empirical": True},
104
+ )
105
+ # Check correct output
106
+ assert marker.get_output_type("BOLD") == "matrix"
107
+
108
+ # Fit-transform the data
109
+ fc = marker.fit_transform(element_data)
110
+ fc_bold = fc["BOLD"]
111
+
112
+ assert "data" in fc_bold
113
+ assert "row_names" in fc_bold
114
+ assert "col_names" in fc_bold
115
+ assert fc_bold["data"].shape == (6, 6)
116
+ assert len(set(fc_bold["row_names"])) == 6
117
+ assert len(set(fc_bold["col_names"])) == 6
118
+
119
+ # Compare with nilearn
120
+ # Load testing coordinates for the target data
121
+ testing_coords, _ = get_coordinates(
122
+ coords="DMNBuckner", target_data=element_data["BOLD"]
123
+ )
124
+ # Extract timeseries
125
+ nifti_spheres_masker = NiftiSpheresMasker(
126
+ seeds=testing_coords, radius=5.0
127
+ )
128
+ extracted_timeseries = nifti_spheres_masker.fit_transform(
129
+ element_data["BOLD"]["data"]
130
+ )
131
+ # Compute the connectivity measure
132
+ connectivity_measure = ConnectivityMeasure(
133
+ cov_estimator=EmpiricalCovariance(), kind="correlation" # type: ignore
134
+ ).fit_transform([extracted_timeseries])[0]
135
+
136
+ # Check that FC are almost equal
137
+ assert_array_almost_equal(
138
+ connectivity_measure, fc_bold["data"], decimal=3
139
+ )
126
140
 
127
141
 
128
142
  def test_FunctionalConnectivitySpheres_error() -> None: