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.
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.dev188.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.dev188.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.dev188.dist-info/RECORD +0 -199
  175. {junifer-0.0.3.dev188.dist-info → junifer-0.0.4.dist-info}/AUTHORS.rst +0 -0
  176. {junifer-0.0.3.dev188.dist-info → junifer-0.0.4.dist-info}/LICENSE.md +0 -0
  177. {junifer-0.0.3.dev188.dist-info → junifer-0.0.4.dist-info}/entry_points.txt +0 -0
  178. {junifer-0.0.3.dev188.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
- """Initialise the class."""
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
- def validate_input(self, input: List[str]) -> List[str]:
214
- """Validate the input to the pipeline step.
206
+ super().__init__(
207
+ on="BOLD", required_data_types=["BOLD", "BOLD_confounds"]
208
+ )
215
209
 
216
- Parameters
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 actual elements of the input that will be processed by this
226
- pipeline step.
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
- _required_inputs = ["BOLD", "BOLD_confounds"]
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, input: List[str]) -> List[str]:
246
- """Get the kind of the pipeline step.
222
+ def get_output_type(self, input_type: str) -> str:
223
+ """Get output type.
247
224
 
248
225
  Parameters
249
226
  ----------
250
- input : list of str
251
- The input to the pipeline step. The list must contain 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
- list of str
257
- The updated list of available Junifer Data object keys after
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 input
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
- raise ValueError(
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
- raise ValueError(
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
- # Bold must be 4D niimg
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("No extra input provided", ValueError)
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("No BOLD_confounds provided", ValueError)
455
+ raise_error("`BOLD_confounds` data type not provided")
472
456
  if "data" not in extra_input["BOLD_confounds"]:
473
- raise_error("No BOLD_confounds data provided", ValueError)
474
- # Confounds must be a dataframe
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
- "When using adhoc format, you must specify "
501
- "the variables names mappings in "
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
- "When using adhoc format, you must specify "
507
- "the variables names mappings to fmriprep format in "
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 fmriprep "
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
- raise ValueError(
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
- raise ValueError(f"Invalid confounds format {t_format}")
514
+ raise_error(f"Invalid confounds format {t_format}")
539
515
 
540
- def _remove_confounds(
516
+ def preprocess(
541
517
  self,
542
518
  input: Dict[str, Any],
543
519
  extra_input: Optional[Dict[str, Any]] = None,
544
- ) -> Union["Nifti1Image", "Nifti2Image", "MGHImage", List]:
545
- """Remove confounds from the BOLD image.
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
- Dictionary containing the ``BOLD`` value from the
551
- Junifer Data object.
526
+ A single input from the Junifer Data object to preprocess.
552
527
  extra_input : dict, optional
553
- Dictionary containing the rest of the Junifer Data object. Must
554
- include the ``BOLD_confounds`` key.
528
+ The other fields in the Junifer Data object. Must include the
529
+ ``BOLD_confounds`` key.
555
530
 
556
531
  Returns
557
532
  -------
558
- Niimg-like object
559
- Input image with confounds removed.
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
- assert extra_input is not None # Not the case, data is validated
563
- confounds_df = self._pick_confounds(extra_input["BOLD_confounds"])
564
- confounds_array = confounds_df.values
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 nifti header")
570
- zooms = bold_img.header.get_zooms() # type: ignore
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 nifti header: {t_r}",
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
- # Save the mask in the extra input and link it to the bold data
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
- logger.info("Cleaning image")
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
- clean_bold = clean_img(
579
+ input["data"] = nimg.clean_img(
595
580
  imgs=bold_img,
596
581
  detrend=self.detrend,
597
582
  standardize=self.standardize,
598
- confounds=confounds_array,
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 clean_bold
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