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.
- 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.dev186.dist-info → junifer-0.0.4.dist-info}/METADATA +59 -28
- junifer-0.0.4.dist-info/RECORD +257 -0
- {junifer-0.0.3.dev186.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.dev186.dist-info/RECORD +0 -199
- {junifer-0.0.3.dev186.dist-info → junifer-0.0.4.dist-info}/AUTHORS.rst +0 -0
- {junifer-0.0.3.dev186.dist-info → junifer-0.0.4.dist-info}/LICENSE.md +0 -0
- {junifer-0.0.3.dev186.dist-info → junifer-0.0.4.dist-info}/entry_points.txt +0 -0
- {junifer-0.0.3.dev186.dist-info → junifer-0.0.4.dist-info}/top_level.txt +0 -0
@@ -6,7 +6,6 @@
|
|
6
6
|
# License: AGPL
|
7
7
|
|
8
8
|
from typing import (
|
9
|
-
TYPE_CHECKING,
|
10
9
|
Any,
|
11
10
|
ClassVar,
|
12
11
|
Dict,
|
@@ -19,8 +18,8 @@ from typing import (
|
|
19
18
|
|
20
19
|
import numpy as np
|
21
20
|
import pandas as pd
|
21
|
+
from nilearn import image as nimg
|
22
22
|
from nilearn._utils.niimg_conversions import check_niimg_4d
|
23
|
-
from nilearn.image import clean_img
|
24
23
|
|
25
24
|
from ...api.decorators import register_preprocessor
|
26
25
|
from ...data import get_mask
|
@@ -28,10 +27,6 @@ from ...utils import logger, raise_error
|
|
28
27
|
from ..base import BasePreprocessor
|
29
28
|
|
30
29
|
|
31
|
-
if TYPE_CHECKING:
|
32
|
-
from nibabel import MGHImage, Nifti1Image, Nifti2Image
|
33
|
-
|
34
|
-
|
35
30
|
FMRIPREP_BASICS = {
|
36
31
|
"motion": [
|
37
32
|
"trans_x",
|
@@ -164,7 +159,7 @@ class fMRIPrepConfoundRemover(BasePreprocessor):
|
|
164
159
|
t_r: Optional[float] = None,
|
165
160
|
masks: Union[str, Dict, List[Union[Dict, str]], None] = None,
|
166
161
|
) -> None:
|
167
|
-
"""
|
162
|
+
"""Initialize the class."""
|
168
163
|
if strategy is None:
|
169
164
|
strategy = {
|
170
165
|
"motion": "full",
|
@@ -208,69 +203,38 @@ class fMRIPrepConfoundRemover(BasePreprocessor):
|
|
208
203
|
"include it in the future",
|
209
204
|
klass=ValueError,
|
210
205
|
)
|
211
|
-
super().__init__(
|
212
|
-
|
213
|
-
|
214
|
-
"""Validate the input to the pipeline step.
|
206
|
+
super().__init__(
|
207
|
+
on="BOLD", required_data_types=["BOLD", "BOLD_confounds"]
|
208
|
+
)
|
215
209
|
|
216
|
-
|
217
|
-
|
218
|
-
input : list of str
|
219
|
-
The input to the pipeline step. The list must contain the
|
220
|
-
available Junifer Data object keys.
|
210
|
+
def get_valid_inputs(self) -> List[str]:
|
211
|
+
"""Get valid data types for input.
|
221
212
|
|
222
213
|
Returns
|
223
214
|
-------
|
224
215
|
list of str
|
225
|
-
The
|
226
|
-
|
227
|
-
|
228
|
-
Raises
|
229
|
-
------
|
230
|
-
ValueError
|
231
|
-
If the input does not have the required data.
|
216
|
+
The list of data types that can be used as input for this
|
217
|
+
preprocessor.
|
232
218
|
|
233
219
|
"""
|
234
|
-
|
235
|
-
if any(x not in input for x in _required_inputs):
|
236
|
-
raise_error(
|
237
|
-
msg="Input does not have the required data. \n"
|
238
|
-
f"Input: {input} \n"
|
239
|
-
f"Required (all off): {_required_inputs} \n",
|
240
|
-
klass=ValueError,
|
241
|
-
)
|
242
|
-
|
243
|
-
return [x for x in self._on if x in input]
|
220
|
+
return ["BOLD"]
|
244
221
|
|
245
|
-
def get_output_type(self,
|
246
|
-
"""Get
|
222
|
+
def get_output_type(self, input_type: str) -> str:
|
223
|
+
"""Get output type.
|
247
224
|
|
248
225
|
Parameters
|
249
226
|
----------
|
250
|
-
|
251
|
-
The input to the
|
252
|
-
available Junifer Data object keys.
|
227
|
+
input_type : str
|
228
|
+
The input to the preprocessor.
|
253
229
|
|
254
230
|
Returns
|
255
231
|
-------
|
256
|
-
|
257
|
-
The
|
258
|
-
the pipeline step.
|
232
|
+
str
|
233
|
+
The data type output by the preprocessor.
|
259
234
|
|
260
235
|
"""
|
261
236
|
# Does not add any new keys
|
262
|
-
return
|
263
|
-
|
264
|
-
def get_valid_inputs(self) -> List[str]:
|
265
|
-
"""Get the valid inputs for the pipeline step.
|
266
|
-
|
267
|
-
Returns
|
268
|
-
-------
|
269
|
-
list of str
|
270
|
-
The valid inputs for the pipeline step.
|
271
|
-
|
272
|
-
"""
|
273
|
-
return ["BOLD"]
|
237
|
+
return input_type
|
274
238
|
|
275
239
|
def _map_adhoc_to_fmriprep(self, input: Dict[str, Any]) -> None:
|
276
240
|
"""Map the adhoc format to the fmpriprep format spec.
|
@@ -333,6 +297,11 @@ class fMRIPrepConfoundRemover(BasePreprocessor):
|
|
333
297
|
spike_name : str
|
334
298
|
Name of the confound to use for spike detection
|
335
299
|
|
300
|
+
Raises
|
301
|
+
------
|
302
|
+
ValueError
|
303
|
+
If invalid confounds file is found.
|
304
|
+
|
336
305
|
"""
|
337
306
|
confounds_df = input["data"]
|
338
307
|
available_vars = confounds_df.columns
|
@@ -347,7 +316,7 @@ class fMRIPrepConfoundRemover(BasePreprocessor):
|
|
347
316
|
|
348
317
|
if any(x not in available_vars for x in t_basics):
|
349
318
|
missing = [x for x in t_basics if x not in available_vars]
|
350
|
-
|
319
|
+
raise_error(
|
351
320
|
"Invalid confounds file. Missing basic confounds: "
|
352
321
|
f"{missing}. "
|
353
322
|
"Check if this file is really an fmriprep confounds file. "
|
@@ -377,7 +346,7 @@ class fMRIPrepConfoundRemover(BasePreprocessor):
|
|
377
346
|
spike_name = "framewise_displacement"
|
378
347
|
if self.spike is not None:
|
379
348
|
if spike_name not in available_vars:
|
380
|
-
|
349
|
+
raise_error(
|
381
350
|
"Invalid confounds file. Missing framewise_displacement "
|
382
351
|
"(spike) confound. "
|
383
352
|
"Check if this file is really an fmriprep confounds file. "
|
@@ -460,22 +429,35 @@ class fMRIPrepConfoundRemover(BasePreprocessor):
|
|
460
429
|
Dictionary containing the rest of the Junifer Data object. Must
|
461
430
|
include the ``BOLD_confounds`` key.
|
462
431
|
|
463
|
-
|
432
|
+
Raises
|
433
|
+
------
|
434
|
+
ValueError
|
435
|
+
If ``extra_input`` is None or
|
436
|
+
if ``"BOLD_confounds"`` is not found in ``extra_input`` or
|
437
|
+
if ``"data"`` key is not found in ``"BOLD_confounds"`` or
|
438
|
+
if ``"data"`` is not pandas.DataFrame or
|
439
|
+
if image time series and confounds have different lengths or
|
440
|
+
if ``"format"`` is not found in ``"BOLD_confounds"`` or
|
441
|
+
if ``format = "adhoc"`` and ``"mappings"`` key or ``"fmriprep"``
|
442
|
+
key or correct fMRIPrep mappings or required fMRIPrep mappings are
|
443
|
+
not found or if invalid confounds format is found.
|
464
444
|
|
465
|
-
|
445
|
+
"""
|
446
|
+
# BOLD must be 4D niimg
|
466
447
|
check_niimg_4d(input["data"])
|
467
|
-
|
448
|
+
# Check for extra inputs
|
468
449
|
if extra_input is None:
|
469
|
-
raise_error(
|
450
|
+
raise_error(
|
451
|
+
"No extra input provided, requires `BOLD_confounds` data type "
|
452
|
+
"in particular"
|
453
|
+
)
|
470
454
|
if "BOLD_confounds" not in extra_input:
|
471
|
-
raise_error("
|
455
|
+
raise_error("`BOLD_confounds` data type not provided")
|
472
456
|
if "data" not in extra_input["BOLD_confounds"]:
|
473
|
-
raise_error("
|
474
|
-
# Confounds must be a
|
457
|
+
raise_error("`BOLD_confounds.data` not provided")
|
458
|
+
# Confounds must be a pandas.DataFrame
|
475
459
|
if not isinstance(extra_input["BOLD_confounds"]["data"], pd.DataFrame):
|
476
|
-
raise_error(
|
477
|
-
"Confounds data must be a pandas dataframe", ValueError
|
478
|
-
)
|
460
|
+
raise_error("`BOLD_confounds.data` must be a `pandas.DataFrame`")
|
479
461
|
|
480
462
|
confound_df = extra_input["BOLD_confounds"]["data"]
|
481
463
|
bold_img = input["data"]
|
@@ -486,26 +468,20 @@ class fMRIPrepConfoundRemover(BasePreprocessor):
|
|
486
468
|
f"\tConfounds: {len(confound_df)}"
|
487
469
|
)
|
488
470
|
|
471
|
+
# Check format
|
489
472
|
if "format" not in extra_input["BOLD_confounds"]:
|
490
|
-
raise_error(
|
491
|
-
"Confounds format must be specified in "
|
492
|
-
'input["BOLD_confounds"]'
|
493
|
-
)
|
494
|
-
|
473
|
+
raise_error("`BOLD_confounds.format` not provided")
|
495
474
|
t_format = extra_input["BOLD_confounds"]["format"]
|
496
|
-
|
497
475
|
if t_format == "adhoc":
|
498
476
|
if "mappings" not in extra_input["BOLD_confounds"]:
|
499
477
|
raise_error(
|
500
|
-
"
|
501
|
-
"
|
502
|
-
'input["BOLD_confounds"]["mappings"]'
|
478
|
+
"`BOLD_confounds.mappings` need to be set when "
|
479
|
+
"`BOLD_confounds.format == 'adhoc'`"
|
503
480
|
)
|
504
481
|
if "fmriprep" not in extra_input["BOLD_confounds"]["mappings"]:
|
505
482
|
raise_error(
|
506
|
-
"
|
507
|
-
"
|
508
|
-
'input["BOLD_confounds"]["mappings"]["fmriprep"]'
|
483
|
+
"`BOLD_confounds.mappings.fmriprep` need to be set when "
|
484
|
+
"`BOLD_confounds.format == 'adhoc'`"
|
509
485
|
)
|
510
486
|
fmriprep_mappings = extra_input["BOLD_confounds"]["mappings"][
|
511
487
|
"fmriprep"
|
@@ -517,7 +493,7 @@ class fMRIPrepConfoundRemover(BasePreprocessor):
|
|
517
493
|
]
|
518
494
|
if len(wrong_names) > 0:
|
519
495
|
raise_error(
|
520
|
-
"The following mapping values are not valid
|
496
|
+
"The following mapping values are not valid fMRIPrep "
|
521
497
|
f"names: {wrong_names}"
|
522
498
|
)
|
523
499
|
# Check that all the required columns are present
|
@@ -528,106 +504,87 @@ class fMRIPrepConfoundRemover(BasePreprocessor):
|
|
528
504
|
]
|
529
505
|
|
530
506
|
if len(missing) > 0:
|
531
|
-
|
507
|
+
raise_error(
|
532
508
|
"Invalid confounds file. Missing columns: "
|
533
509
|
f"{missing}. "
|
534
510
|
"Check if this file matches the adhoc specification for "
|
535
511
|
"this dataset."
|
536
512
|
)
|
537
513
|
elif t_format != "fmriprep":
|
538
|
-
|
514
|
+
raise_error(f"Invalid confounds format {t_format}")
|
539
515
|
|
540
|
-
def
|
516
|
+
def preprocess(
|
541
517
|
self,
|
542
518
|
input: Dict[str, Any],
|
543
519
|
extra_input: Optional[Dict[str, Any]] = None,
|
544
|
-
) ->
|
545
|
-
"""
|
520
|
+
) -> Tuple[Dict[str, Any], Optional[Dict[str, Dict[str, Any]]]]:
|
521
|
+
"""Preprocess.
|
546
522
|
|
547
523
|
Parameters
|
548
524
|
----------
|
549
525
|
input : dict
|
550
|
-
|
551
|
-
Junifer Data object.
|
526
|
+
A single input from the Junifer Data object to preprocess.
|
552
527
|
extra_input : dict, optional
|
553
|
-
|
554
|
-
|
528
|
+
The other fields in the Junifer Data object. Must include the
|
529
|
+
``BOLD_confounds`` key.
|
555
530
|
|
556
531
|
Returns
|
557
532
|
-------
|
558
|
-
|
559
|
-
|
533
|
+
dict
|
534
|
+
The computed result as dictionary.
|
535
|
+
dict or None
|
536
|
+
If `self.masks` is not None, then the target data computed mask is
|
537
|
+
returned else None.
|
560
538
|
|
561
539
|
"""
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
540
|
+
# Validate data
|
541
|
+
self._validate_data(input, extra_input)
|
542
|
+
# Pick confounds
|
543
|
+
confounds_df = self._pick_confounds(extra_input["BOLD_confounds"]) # type: ignore
|
544
|
+
# Get BOLD data
|
566
545
|
bold_img = input["data"]
|
546
|
+
# Set t_r
|
567
547
|
t_r = self.t_r
|
568
548
|
if t_r is None:
|
569
|
-
logger.info("No `t_r` specified, using t_r from
|
570
|
-
|
571
|
-
t_r = zooms[3]
|
549
|
+
logger.info("No `t_r` specified, using t_r from NIfTI header")
|
550
|
+
t_r = bold_img.header.get_zooms()[3] # type: ignore
|
572
551
|
logger.info(
|
573
|
-
f"Read t_r from
|
552
|
+
f"Read t_r from NIfTI header: {t_r}",
|
574
553
|
)
|
575
|
-
|
554
|
+
# Set mask data
|
576
555
|
mask_img = None
|
556
|
+
bold_mask_dict = None
|
577
557
|
if self.masks is not None:
|
578
558
|
logger.debug(f"Masking with {self.masks}")
|
579
559
|
mask_img = get_mask(
|
580
560
|
masks=self.masks, target_data=input, extra_input=extra_input
|
581
561
|
)
|
582
|
-
#
|
562
|
+
# Return the BOLD mask and link it to the BOLD data type dict;
|
583
563
|
# this allows to use "inherit" down the pipeline
|
584
564
|
if extra_input is not None:
|
585
|
-
logger.debug("Setting mask_item")
|
586
|
-
extra_input["BOLD_mask"] = {"data": mask_img}
|
565
|
+
logger.debug("Setting `BOLD.mask_item`")
|
587
566
|
input["mask_item"] = "BOLD_mask"
|
588
|
-
|
589
|
-
|
567
|
+
bold_mask_dict = {
|
568
|
+
"BOLD_mask": {
|
569
|
+
"data": mask_img,
|
570
|
+
"space": input["space"],
|
571
|
+
}
|
572
|
+
}
|
573
|
+
# Clean image
|
574
|
+
logger.info("Cleaning image using nilearn")
|
590
575
|
logger.debug(f"\tdetrend: {self.detrend}")
|
591
576
|
logger.debug(f"\tstandardize: {self.standardize}")
|
592
577
|
logger.debug(f"\tlow_pass: {self.low_pass}")
|
593
578
|
logger.debug(f"\thigh_pass: {self.high_pass}")
|
594
|
-
|
579
|
+
input["data"] = nimg.clean_img(
|
595
580
|
imgs=bold_img,
|
596
581
|
detrend=self.detrend,
|
597
582
|
standardize=self.standardize,
|
598
|
-
confounds=
|
583
|
+
confounds=confounds_df.values,
|
599
584
|
low_pass=self.low_pass,
|
600
585
|
high_pass=self.high_pass,
|
601
586
|
t_r=t_r,
|
602
587
|
mask_img=mask_img,
|
603
588
|
)
|
604
589
|
|
605
|
-
return
|
606
|
-
|
607
|
-
def preprocess(
|
608
|
-
self,
|
609
|
-
input: Dict[str, Any],
|
610
|
-
extra_input: Optional[Dict[str, Any]] = None,
|
611
|
-
) -> Tuple[str, Dict[str, Any]]:
|
612
|
-
"""Preprocess.
|
613
|
-
|
614
|
-
Parameters
|
615
|
-
----------
|
616
|
-
input : dict
|
617
|
-
A single input from the Junifer Data object in which to preprocess.
|
618
|
-
extra_input : dict, optional
|
619
|
-
The other fields in the Junifer Data object. Must include the
|
620
|
-
``BOLD_confounds`` key.
|
621
|
-
|
622
|
-
Returns
|
623
|
-
-------
|
624
|
-
key : str
|
625
|
-
The key to store the output in the Junifer Data object.
|
626
|
-
object : dict
|
627
|
-
The computed result as dictionary. This will be stored in the
|
628
|
-
Junifer Data object under the key ``key``.
|
629
|
-
|
630
|
-
"""
|
631
|
-
self._validate_data(input, extra_input)
|
632
|
-
input["data"] = self._remove_confounds(input, extra_input=extra_input)
|
633
|
-
return "BOLD", input
|
590
|
+
return input, bold_mask_dict
|