junifer 0.0.3.dev188__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.
- junifer/_version.py +14 -2
- junifer/api/cli.py +162 -17
- junifer/api/functions.py +87 -419
- junifer/api/parser.py +24 -0
- junifer/api/queue_context/__init__.py +8 -0
- junifer/api/queue_context/gnu_parallel_local_adapter.py +258 -0
- junifer/api/queue_context/htcondor_adapter.py +365 -0
- junifer/api/queue_context/queue_context_adapter.py +60 -0
- junifer/api/queue_context/tests/test_gnu_parallel_local_adapter.py +192 -0
- junifer/api/queue_context/tests/test_htcondor_adapter.py +257 -0
- junifer/api/res/afni/run_afni_docker.sh +6 -6
- junifer/api/res/ants/ResampleImage +3 -0
- junifer/api/res/ants/antsApplyTransforms +3 -0
- junifer/api/res/ants/antsApplyTransformsToPoints +3 -0
- junifer/api/res/ants/run_ants_docker.sh +39 -0
- junifer/api/res/fsl/applywarp +3 -0
- junifer/api/res/fsl/flirt +3 -0
- junifer/api/res/fsl/img2imgcoord +3 -0
- junifer/api/res/fsl/run_fsl_docker.sh +39 -0
- junifer/api/res/fsl/std2imgcoord +3 -0
- junifer/api/res/run_conda.sh +4 -4
- junifer/api/res/run_venv.sh +22 -0
- junifer/api/tests/data/partly_cloudy_agg_mean_tian.yml +16 -0
- junifer/api/tests/test_api_utils.py +21 -3
- junifer/api/tests/test_cli.py +232 -9
- junifer/api/tests/test_functions.py +211 -439
- junifer/api/tests/test_parser.py +1 -1
- junifer/configs/juseless/datagrabbers/aomic_id1000_vbm.py +6 -1
- junifer/configs/juseless/datagrabbers/camcan_vbm.py +6 -1
- junifer/configs/juseless/datagrabbers/ixi_vbm.py +6 -1
- junifer/configs/juseless/datagrabbers/tests/test_ucla.py +8 -8
- junifer/configs/juseless/datagrabbers/ucla.py +44 -26
- junifer/configs/juseless/datagrabbers/ukb_vbm.py +6 -1
- junifer/data/VOIs/meta/AutobiographicalMemory_VOIs.txt +23 -0
- junifer/data/VOIs/meta/Power2013_MNI_VOIs.tsv +264 -0
- junifer/data/__init__.py +4 -0
- junifer/data/coordinates.py +298 -31
- junifer/data/masks.py +360 -28
- junifer/data/parcellations.py +621 -188
- junifer/data/template_spaces.py +190 -0
- junifer/data/tests/test_coordinates.py +34 -3
- junifer/data/tests/test_data_utils.py +1 -0
- junifer/data/tests/test_masks.py +202 -86
- junifer/data/tests/test_parcellations.py +266 -55
- junifer/data/tests/test_template_spaces.py +104 -0
- junifer/data/utils.py +4 -2
- junifer/datagrabber/__init__.py +1 -0
- junifer/datagrabber/aomic/id1000.py +111 -70
- junifer/datagrabber/aomic/piop1.py +116 -53
- junifer/datagrabber/aomic/piop2.py +116 -53
- junifer/datagrabber/aomic/tests/test_id1000.py +27 -27
- junifer/datagrabber/aomic/tests/test_piop1.py +27 -27
- junifer/datagrabber/aomic/tests/test_piop2.py +27 -27
- junifer/datagrabber/base.py +62 -10
- junifer/datagrabber/datalad_base.py +0 -2
- junifer/datagrabber/dmcc13_benchmark.py +372 -0
- junifer/datagrabber/hcp1200/datalad_hcp1200.py +5 -0
- junifer/datagrabber/hcp1200/hcp1200.py +30 -13
- junifer/datagrabber/pattern.py +133 -27
- junifer/datagrabber/pattern_datalad.py +111 -13
- junifer/datagrabber/tests/test_base.py +57 -6
- junifer/datagrabber/tests/test_datagrabber_utils.py +204 -76
- junifer/datagrabber/tests/test_datalad_base.py +0 -6
- junifer/datagrabber/tests/test_dmcc13_benchmark.py +256 -0
- junifer/datagrabber/tests/test_multiple.py +43 -10
- junifer/datagrabber/tests/test_pattern.py +125 -178
- junifer/datagrabber/tests/test_pattern_datalad.py +44 -25
- junifer/datagrabber/utils.py +151 -16
- junifer/datareader/default.py +36 -10
- junifer/external/nilearn/junifer_nifti_spheres_masker.py +6 -0
- junifer/markers/base.py +25 -16
- junifer/markers/collection.py +35 -16
- junifer/markers/complexity/__init__.py +27 -0
- junifer/markers/complexity/complexity_base.py +149 -0
- junifer/markers/complexity/hurst_exponent.py +136 -0
- junifer/markers/complexity/multiscale_entropy_auc.py +140 -0
- junifer/markers/complexity/perm_entropy.py +132 -0
- junifer/markers/complexity/range_entropy.py +136 -0
- junifer/markers/complexity/range_entropy_auc.py +145 -0
- junifer/markers/complexity/sample_entropy.py +134 -0
- junifer/markers/complexity/tests/test_complexity_base.py +19 -0
- junifer/markers/complexity/tests/test_hurst_exponent.py +69 -0
- junifer/markers/complexity/tests/test_multiscale_entropy_auc.py +68 -0
- junifer/markers/complexity/tests/test_perm_entropy.py +68 -0
- junifer/markers/complexity/tests/test_range_entropy.py +69 -0
- junifer/markers/complexity/tests/test_range_entropy_auc.py +69 -0
- junifer/markers/complexity/tests/test_sample_entropy.py +68 -0
- junifer/markers/complexity/tests/test_weighted_perm_entropy.py +68 -0
- junifer/markers/complexity/weighted_perm_entropy.py +133 -0
- junifer/markers/falff/_afni_falff.py +153 -0
- junifer/markers/falff/_junifer_falff.py +142 -0
- junifer/markers/falff/falff_base.py +91 -84
- junifer/markers/falff/falff_parcels.py +61 -45
- junifer/markers/falff/falff_spheres.py +64 -48
- junifer/markers/falff/tests/test_falff_parcels.py +89 -121
- junifer/markers/falff/tests/test_falff_spheres.py +92 -127
- junifer/markers/functional_connectivity/crossparcellation_functional_connectivity.py +1 -0
- junifer/markers/functional_connectivity/edge_functional_connectivity_parcels.py +1 -0
- junifer/markers/functional_connectivity/functional_connectivity_base.py +1 -0
- junifer/markers/functional_connectivity/tests/test_crossparcellation_functional_connectivity.py +46 -44
- junifer/markers/functional_connectivity/tests/test_edge_functional_connectivity_parcels.py +34 -39
- junifer/markers/functional_connectivity/tests/test_edge_functional_connectivity_spheres.py +40 -52
- junifer/markers/functional_connectivity/tests/test_functional_connectivity_parcels.py +62 -70
- junifer/markers/functional_connectivity/tests/test_functional_connectivity_spheres.py +99 -85
- junifer/markers/parcel_aggregation.py +60 -38
- junifer/markers/reho/_afni_reho.py +192 -0
- junifer/markers/reho/_junifer_reho.py +281 -0
- junifer/markers/reho/reho_base.py +69 -34
- junifer/markers/reho/reho_parcels.py +26 -16
- junifer/markers/reho/reho_spheres.py +23 -9
- junifer/markers/reho/tests/test_reho_parcels.py +93 -92
- junifer/markers/reho/tests/test_reho_spheres.py +88 -86
- junifer/markers/sphere_aggregation.py +54 -9
- junifer/markers/temporal_snr/temporal_snr_base.py +1 -0
- junifer/markers/temporal_snr/tests/test_temporal_snr_parcels.py +38 -37
- junifer/markers/temporal_snr/tests/test_temporal_snr_spheres.py +34 -38
- junifer/markers/tests/test_collection.py +43 -42
- junifer/markers/tests/test_ets_rss.py +29 -37
- junifer/markers/tests/test_parcel_aggregation.py +587 -468
- junifer/markers/tests/test_sphere_aggregation.py +209 -157
- junifer/markers/utils.py +2 -40
- junifer/onthefly/read_transform.py +13 -6
- junifer/pipeline/__init__.py +1 -0
- junifer/pipeline/pipeline_step_mixin.py +105 -41
- junifer/pipeline/registry.py +17 -0
- junifer/pipeline/singleton.py +45 -0
- junifer/pipeline/tests/test_pipeline_step_mixin.py +139 -51
- junifer/pipeline/tests/test_update_meta_mixin.py +1 -0
- junifer/pipeline/tests/test_workdir_manager.py +104 -0
- junifer/pipeline/update_meta_mixin.py +8 -2
- junifer/pipeline/utils.py +154 -15
- junifer/pipeline/workdir_manager.py +246 -0
- junifer/preprocess/__init__.py +3 -0
- junifer/preprocess/ants/__init__.py +4 -0
- junifer/preprocess/ants/ants_apply_transforms_warper.py +185 -0
- junifer/preprocess/ants/tests/test_ants_apply_transforms_warper.py +56 -0
- junifer/preprocess/base.py +96 -69
- junifer/preprocess/bold_warper.py +265 -0
- junifer/preprocess/confounds/fmriprep_confound_remover.py +91 -134
- junifer/preprocess/confounds/tests/test_fmriprep_confound_remover.py +106 -111
- junifer/preprocess/fsl/__init__.py +4 -0
- junifer/preprocess/fsl/apply_warper.py +179 -0
- junifer/preprocess/fsl/tests/test_apply_warper.py +45 -0
- junifer/preprocess/tests/test_bold_warper.py +159 -0
- junifer/preprocess/tests/test_preprocess_base.py +6 -6
- junifer/preprocess/warping/__init__.py +6 -0
- junifer/preprocess/warping/_ants_warper.py +167 -0
- junifer/preprocess/warping/_fsl_warper.py +109 -0
- junifer/preprocess/warping/space_warper.py +213 -0
- junifer/preprocess/warping/tests/test_space_warper.py +198 -0
- junifer/stats.py +18 -4
- junifer/storage/base.py +9 -1
- junifer/storage/hdf5.py +8 -3
- junifer/storage/pandas_base.py +2 -1
- junifer/storage/sqlite.py +1 -0
- junifer/storage/tests/test_hdf5.py +2 -1
- junifer/storage/tests/test_sqlite.py +8 -8
- junifer/storage/tests/test_utils.py +6 -6
- junifer/storage/utils.py +1 -0
- junifer/testing/datagrabbers.py +11 -7
- junifer/testing/utils.py +1 -0
- junifer/tests/test_stats.py +2 -0
- junifer/utils/__init__.py +1 -0
- junifer/utils/helpers.py +53 -0
- junifer/utils/logging.py +14 -3
- junifer/utils/tests/test_helpers.py +35 -0
- {junifer-0.0.3.dev188.dist-info → junifer-0.0.4.dist-info}/METADATA +59 -28
- junifer-0.0.4.dist-info/RECORD +257 -0
- {junifer-0.0.3.dev188.dist-info → junifer-0.0.4.dist-info}/WHEEL +1 -1
- junifer/markers/falff/falff_estimator.py +0 -334
- junifer/markers/falff/tests/test_falff_estimator.py +0 -238
- junifer/markers/reho/reho_estimator.py +0 -515
- junifer/markers/reho/tests/test_reho_estimator.py +0 -260
- junifer-0.0.3.dev188.dist-info/RECORD +0 -199
- {junifer-0.0.3.dev188.dist-info → junifer-0.0.4.dist-info}/AUTHORS.rst +0 -0
- {junifer-0.0.3.dev188.dist-info → junifer-0.0.4.dist-info}/LICENSE.md +0 -0
- {junifer-0.0.3.dev188.dist-info → junifer-0.0.4.dist-info}/entry_points.txt +0 -0
- {junifer-0.0.3.dev188.dist-info → junifer-0.0.4.dist-info}/top_level.txt +0 -0
@@ -1,118 +1,120 @@
|
|
1
|
-
"""Provide tests for
|
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
|
-
|
10
|
-
from scipy.stats import pearsonr
|
10
|
+
import scipy as sp
|
11
11
|
|
12
|
-
from junifer.
|
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
|
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
|
22
|
-
"""Test ReHoSpheres
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
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
|
77
|
+
_check_afni() is False, reason="requires AFNI to be in PATH"
|
51
78
|
)
|
52
|
-
def
|
53
|
-
"""Test ReHoSpheres
|
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
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
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
|
-
|
66
|
-
{"BOLD": {"path": "/tmp", "data": fmri_img, "meta": {}}}
|
67
|
-
)
|
100
|
+
junifer_output = junifer_marker.fit_transform(element_data)
|
68
101
|
# Get BOLD output
|
69
|
-
|
102
|
+
junifer_output_bold = junifer_output["BOLD"]
|
70
103
|
|
71
|
-
# Initialize marker
|
72
|
-
|
73
|
-
coords=COORDINATES,
|
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
|
-
|
77
|
-
{"BOLD": {"path": "/tmp", "data": fmri_img, "meta": {}}}
|
78
|
-
)
|
111
|
+
afni_output = afni_marker.fit_transform(element_data)
|
79
112
|
# Get BOLD output
|
80
|
-
|
113
|
+
afni_output_bold = afni_output["BOLD"]
|
81
114
|
|
82
115
|
# Check for Pearson correlation coefficient
|
83
|
-
r, _ = pearsonr(
|
84
|
-
|
85
|
-
|
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
|
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", "
|
51
|
-
|
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 [
|
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 [
|
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
|
-
|
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
|
-
|
173
|
-
|
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":
|
241
|
+
out = {"data": out_values, "col_names": labels}
|
197
242
|
return out
|
@@ -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
|
9
|
-
|
9
|
+
from junifer.datareader import DefaultDataReader
|
10
10
|
from junifer.markers.temporal_snr import TemporalSNRParcels
|
11
|
-
from junifer.storage import
|
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
|
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
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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
|
13
|
+
from junifer.storage import HDF5FeatureStorage
|
14
|
+
from junifer.testing.datagrabbers import SPMAuditoryTestingDataGrabber
|
13
15
|
|
14
16
|
|
15
|
-
def
|
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
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
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:
|