junifer 0.0.6.dev154__py3-none-any.whl → 0.0.6.dev194__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/__init__.pyi +2 -0
- junifer/_version.py +2 -2
- junifer/api/decorators.py +6 -11
- junifer/api/functions.py +74 -62
- junifer/api/tests/test_functions.py +2 -2
- junifer/data/__init__.pyi +17 -31
- junifer/data/_dispatch.py +251 -0
- junifer/data/coordinates/__init__.py +9 -0
- junifer/data/coordinates/__init__.pyi +5 -0
- junifer/data/coordinates/_ants_coordinates_warper.py +96 -0
- junifer/data/coordinates/_coordinates.py +356 -0
- junifer/data/coordinates/_fsl_coordinates_warper.py +83 -0
- junifer/data/{tests → coordinates/tests}/test_coordinates.py +25 -31
- junifer/data/masks/__init__.py +9 -0
- junifer/data/masks/__init__.pyi +6 -0
- junifer/data/masks/_ants_mask_warper.py +144 -0
- junifer/data/masks/_fsl_mask_warper.py +87 -0
- junifer/data/masks/_masks.py +624 -0
- junifer/data/{tests → masks/tests}/test_masks.py +63 -58
- junifer/data/parcellations/__init__.py +9 -0
- junifer/data/parcellations/__init__.pyi +6 -0
- junifer/data/parcellations/_ants_parcellation_warper.py +154 -0
- junifer/data/parcellations/_fsl_parcellation_warper.py +91 -0
- junifer/data/{parcellations.py → parcellations/_parcellations.py} +450 -473
- junifer/data/{tests → parcellations/tests}/test_parcellations.py +73 -81
- junifer/data/pipeline_data_registry_base.py +74 -0
- junifer/data/utils.py +4 -0
- junifer/datagrabber/aomic/piop2.py +1 -1
- junifer/markers/complexity/hurst_exponent.py +2 -2
- junifer/markers/complexity/multiscale_entropy_auc.py +2 -2
- junifer/markers/complexity/perm_entropy.py +2 -2
- junifer/markers/complexity/range_entropy.py +2 -2
- junifer/markers/complexity/range_entropy_auc.py +2 -2
- junifer/markers/complexity/sample_entropy.py +2 -2
- junifer/markers/complexity/weighted_perm_entropy.py +2 -2
- junifer/markers/ets_rss.py +2 -2
- junifer/markers/falff/falff_parcels.py +2 -2
- junifer/markers/falff/falff_spheres.py +2 -2
- junifer/markers/functional_connectivity/edge_functional_connectivity_parcels.py +1 -1
- junifer/markers/functional_connectivity/edge_functional_connectivity_spheres.py +1 -1
- junifer/markers/functional_connectivity/functional_connectivity_parcels.py +1 -1
- junifer/markers/functional_connectivity/functional_connectivity_spheres.py +1 -1
- junifer/markers/functional_connectivity/tests/test_functional_connectivity_parcels.py +3 -3
- junifer/markers/functional_connectivity/tests/test_functional_connectivity_spheres.py +2 -2
- junifer/markers/parcel_aggregation.py +11 -7
- junifer/markers/reho/reho_parcels.py +2 -2
- junifer/markers/reho/reho_spheres.py +2 -2
- junifer/markers/sphere_aggregation.py +11 -7
- junifer/markers/temporal_snr/temporal_snr_parcels.py +2 -2
- junifer/markers/temporal_snr/temporal_snr_spheres.py +2 -2
- junifer/markers/tests/test_ets_rss.py +3 -3
- junifer/markers/tests/test_parcel_aggregation.py +24 -24
- junifer/markers/tests/test_sphere_aggregation.py +6 -6
- junifer/pipeline/__init__.pyi +2 -2
- junifer/pipeline/pipeline_component_registry.py +299 -0
- junifer/pipeline/tests/test_pipeline_component_registry.py +201 -0
- junifer/preprocess/confounds/fmriprep_confound_remover.py +6 -3
- junifer/testing/__init__.pyi +2 -2
- junifer/testing/registry.py +4 -7
- junifer/testing/tests/test_testing_registry.py +9 -17
- {junifer-0.0.6.dev154.dist-info → junifer-0.0.6.dev194.dist-info}/METADATA +1 -1
- {junifer-0.0.6.dev154.dist-info → junifer-0.0.6.dev194.dist-info}/RECORD +86 -72
- {junifer-0.0.6.dev154.dist-info → junifer-0.0.6.dev194.dist-info}/WHEEL +1 -1
- junifer/data/coordinates.py +0 -408
- junifer/data/masks.py +0 -670
- junifer/pipeline/registry.py +0 -245
- junifer/pipeline/tests/test_registry.py +0 -150
- /junifer/data/{VOIs → coordinates/VOIs}/meta/AutobiographicalMemory_VOIs.txt +0 -0
- /junifer/data/{VOIs → coordinates/VOIs}/meta/CogAC_VOIs.txt +0 -0
- /junifer/data/{VOIs → coordinates/VOIs}/meta/CogAR_VOIs.txt +0 -0
- /junifer/data/{VOIs → coordinates/VOIs}/meta/DMNBuckner_VOIs.txt +0 -0
- /junifer/data/{VOIs → coordinates/VOIs}/meta/Dosenbach2010_MNI_VOIs.txt +0 -0
- /junifer/data/{VOIs → coordinates/VOIs}/meta/Empathy_VOIs.txt +0 -0
- /junifer/data/{VOIs → coordinates/VOIs}/meta/Motor_VOIs.txt +0 -0
- /junifer/data/{VOIs → coordinates/VOIs}/meta/MultiTask_VOIs.txt +0 -0
- /junifer/data/{VOIs → coordinates/VOIs}/meta/PhysioStress_VOIs.txt +0 -0
- /junifer/data/{VOIs → coordinates/VOIs}/meta/Power2011_MNI_VOIs.txt +0 -0
- /junifer/data/{VOIs → coordinates/VOIs}/meta/Power2013_MNI_VOIs.tsv +0 -0
- /junifer/data/{VOIs → coordinates/VOIs}/meta/Rew_VOIs.txt +0 -0
- /junifer/data/{VOIs → coordinates/VOIs}/meta/Somatosensory_VOIs.txt +0 -0
- /junifer/data/{VOIs → coordinates/VOIs}/meta/ToM_VOIs.txt +0 -0
- /junifer/data/{VOIs → coordinates/VOIs}/meta/VigAtt_VOIs.txt +0 -0
- /junifer/data/{VOIs → coordinates/VOIs}/meta/WM_VOIs.txt +0 -0
- /junifer/data/{VOIs → coordinates/VOIs}/meta/eMDN_VOIs.txt +0 -0
- /junifer/data/{VOIs → coordinates/VOIs}/meta/eSAD_VOIs.txt +0 -0
- /junifer/data/{VOIs → coordinates/VOIs}/meta/extDMN_VOIs.txt +0 -0
- {junifer-0.0.6.dev154.dist-info → junifer-0.0.6.dev194.dist-info}/AUTHORS.rst +0 -0
- {junifer-0.0.6.dev154.dist-info → junifer-0.0.6.dev194.dist-info}/LICENSE.md +0 -0
- {junifer-0.0.6.dev154.dist-info → junifer-0.0.6.dev194.dist-info}/entry_points.txt +0 -0
- {junifer-0.0.6.dev154.dist-info → junifer-0.0.6.dev194.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,144 @@
|
|
1
|
+
"""Provide class for mask space warping via ANTs."""
|
2
|
+
|
3
|
+
# Authors: Synchon Mandal <s.mandal@fz-juelich.de>
|
4
|
+
# License: AGPL
|
5
|
+
|
6
|
+
import uuid
|
7
|
+
from typing import TYPE_CHECKING, Any, Dict, Optional
|
8
|
+
|
9
|
+
import nibabel as nib
|
10
|
+
|
11
|
+
from ...pipeline import WorkDirManager
|
12
|
+
from ...utils import logger, run_ext_cmd
|
13
|
+
from ..template_spaces import get_template, get_xfm
|
14
|
+
|
15
|
+
|
16
|
+
if TYPE_CHECKING:
|
17
|
+
from nibabel.nifti1 import Nifti1Image
|
18
|
+
|
19
|
+
|
20
|
+
__all__ = ["ANTsMaskWarper"]
|
21
|
+
|
22
|
+
|
23
|
+
class ANTsMaskWarper:
|
24
|
+
"""Class for mask space warping via ANTs.
|
25
|
+
|
26
|
+
This class uses ANTs ``antsApplyTransforms`` for transformation.
|
27
|
+
|
28
|
+
"""
|
29
|
+
|
30
|
+
def warp(
|
31
|
+
self,
|
32
|
+
mask_name: str,
|
33
|
+
mask_img: "Nifti1Image",
|
34
|
+
src: str,
|
35
|
+
dst: str,
|
36
|
+
target_data: Dict[str, Any],
|
37
|
+
extra_input: Optional[Dict[str, Any]] = None,
|
38
|
+
) -> "Nifti1Image":
|
39
|
+
"""Warp ``mask_img`` to correct space.
|
40
|
+
|
41
|
+
Parameters
|
42
|
+
----------
|
43
|
+
mask_name : str
|
44
|
+
The name of the mask.
|
45
|
+
mask_img : nibabel.nifti1.Nifti1Image
|
46
|
+
The mask image to transform.
|
47
|
+
src : str
|
48
|
+
The data type or template space to warp from.
|
49
|
+
It should be empty string if ``dst="T1w"``.
|
50
|
+
dst : str
|
51
|
+
The data type or template space to warp to.
|
52
|
+
`"T1w"` is the only allowed data type and it uses the resampled T1w
|
53
|
+
found in ``target_data.reference_path``. The ``"reference_path"``
|
54
|
+
key is added when :class:`.SpaceWarper` is used.
|
55
|
+
target_data : dict
|
56
|
+
The corresponding item of the data object to which the mask
|
57
|
+
will be applied.
|
58
|
+
extra_input : dict, optional
|
59
|
+
The other fields in the data object. Useful for accessing other
|
60
|
+
data kinds that needs to be used in the computation of mask
|
61
|
+
(default None).
|
62
|
+
|
63
|
+
|
64
|
+
Returns
|
65
|
+
-------
|
66
|
+
nibabel.nifti1.Nifti1Image
|
67
|
+
The transformed mask image.
|
68
|
+
|
69
|
+
"""
|
70
|
+
# Create element-scoped tempdir so that warped mask is
|
71
|
+
# available later as nibabel stores file path reference for
|
72
|
+
# loading on computation
|
73
|
+
prefix = (
|
74
|
+
f"ants_mask_warper_{mask_name}"
|
75
|
+
f"{'' if not src else f'_from_{src}'}_to_{dst}_"
|
76
|
+
f"{uuid.uuid1()}"
|
77
|
+
)
|
78
|
+
element_tempdir = WorkDirManager().get_element_tempdir(
|
79
|
+
prefix=prefix,
|
80
|
+
)
|
81
|
+
|
82
|
+
# Native space warping
|
83
|
+
if dst == "T1w":
|
84
|
+
logger.debug("Using ANTs for mask transformation")
|
85
|
+
|
86
|
+
# Save existing mask image to a tempfile
|
87
|
+
prewarp_mask_path = element_tempdir / "prewarp_mask.nii.gz"
|
88
|
+
nib.save(mask_img, prewarp_mask_path)
|
89
|
+
|
90
|
+
# Create a tempfile for warped output
|
91
|
+
warped_mask_path = element_tempdir / "mask_warped.nii.gz"
|
92
|
+
# Set antsApplyTransforms command
|
93
|
+
apply_transforms_cmd = [
|
94
|
+
"antsApplyTransforms",
|
95
|
+
"-d 3",
|
96
|
+
"-e 3",
|
97
|
+
"-n 'GenericLabel[NearestNeighbor]'",
|
98
|
+
f"-i {prewarp_mask_path.resolve()}",
|
99
|
+
# use resampled reference
|
100
|
+
f"-r {target_data['reference_path'].resolve()}",
|
101
|
+
f"-t {extra_input['Warp']['path'].resolve()}",
|
102
|
+
f"-o {warped_mask_path.resolve()}",
|
103
|
+
]
|
104
|
+
# Call antsApplyTransforms
|
105
|
+
run_ext_cmd(name="antsApplyTransforms", cmd=apply_transforms_cmd)
|
106
|
+
|
107
|
+
# Template space warping
|
108
|
+
else:
|
109
|
+
logger.debug(f"Using ANTs to warp mask from {src} to {dst}")
|
110
|
+
|
111
|
+
# Get xfm file
|
112
|
+
xfm_file_path = get_xfm(src=src, dst=dst)
|
113
|
+
# Get template space image
|
114
|
+
template_space_img = get_template(
|
115
|
+
space=dst,
|
116
|
+
target_data=target_data,
|
117
|
+
extra_input=None,
|
118
|
+
)
|
119
|
+
# Save template to a tempfile
|
120
|
+
template_space_img_path = element_tempdir / f"{dst}_T1w.nii.gz"
|
121
|
+
nib.save(template_space_img, template_space_img_path)
|
122
|
+
|
123
|
+
# Save existing mask image to a tempfile
|
124
|
+
prewarp_mask_path = element_tempdir / "prewarp_mask.nii.gz"
|
125
|
+
nib.save(mask_img, prewarp_mask_path)
|
126
|
+
|
127
|
+
# Create a tempfile for warped output
|
128
|
+
warped_mask_path = element_tempdir / "mask_warped.nii.gz"
|
129
|
+
# Set antsApplyTransforms command
|
130
|
+
apply_transforms_cmd = [
|
131
|
+
"antsApplyTransforms",
|
132
|
+
"-d 3",
|
133
|
+
"-e 3",
|
134
|
+
"-n 'GenericLabel[NearestNeighbor]'",
|
135
|
+
f"-i {prewarp_mask_path.resolve()}",
|
136
|
+
f"-r {template_space_img_path.resolve()}",
|
137
|
+
f"-t {xfm_file_path.resolve()}",
|
138
|
+
f"-o {warped_mask_path.resolve()}",
|
139
|
+
]
|
140
|
+
# Call antsApplyTransforms
|
141
|
+
run_ext_cmd(name="antsApplyTransforms", cmd=apply_transforms_cmd)
|
142
|
+
|
143
|
+
# Load nifti
|
144
|
+
return nib.load(warped_mask_path)
|
@@ -0,0 +1,87 @@
|
|
1
|
+
"""Provide class for mask space warping via FSL FLIRT."""
|
2
|
+
|
3
|
+
# Authors: Synchon Mandal <s.mandal@fz-juelich.de>
|
4
|
+
# License: AGPL
|
5
|
+
|
6
|
+
import uuid
|
7
|
+
from typing import TYPE_CHECKING, Any, Dict
|
8
|
+
|
9
|
+
import nibabel as nib
|
10
|
+
|
11
|
+
from ...pipeline import WorkDirManager
|
12
|
+
from ...utils import logger, run_ext_cmd
|
13
|
+
|
14
|
+
|
15
|
+
if TYPE_CHECKING:
|
16
|
+
from nibabel.nifti1 import Nifti1Image
|
17
|
+
|
18
|
+
|
19
|
+
__all__ = ["FSLMaskWarper"]
|
20
|
+
|
21
|
+
|
22
|
+
class FSLMaskWarper:
|
23
|
+
"""Class for mask space warping via FSL FLIRT.
|
24
|
+
|
25
|
+
This class uses FSL FLIRT's ``applywarp`` for transformation.
|
26
|
+
|
27
|
+
"""
|
28
|
+
|
29
|
+
def warp(
|
30
|
+
self,
|
31
|
+
mask_name: str,
|
32
|
+
mask_img: "Nifti1Image",
|
33
|
+
target_data: Dict[str, Any],
|
34
|
+
extra_input: Dict[str, Any],
|
35
|
+
) -> "Nifti1Image":
|
36
|
+
"""Warp ``mask_img`` to correct space.
|
37
|
+
|
38
|
+
Parameters
|
39
|
+
----------
|
40
|
+
mask_name : str
|
41
|
+
The name of the mask.
|
42
|
+
mask_img : nibabel.nifti1.Nifti1Image
|
43
|
+
The mask image to transform.
|
44
|
+
target_data : dict
|
45
|
+
The corresponding item of the data object to which the mask
|
46
|
+
will be applied.
|
47
|
+
extra_input : dict, optional
|
48
|
+
The other fields in the data object. Useful for accessing other
|
49
|
+
data kinds that needs to be used in the computation of mask
|
50
|
+
(default None).
|
51
|
+
|
52
|
+
Returns
|
53
|
+
-------
|
54
|
+
nibabel.nifti1.Nifti1Image
|
55
|
+
The transformed mask image.
|
56
|
+
|
57
|
+
"""
|
58
|
+
logger.debug("Using FSL for mask transformation")
|
59
|
+
|
60
|
+
# Create element-scoped tempdir so that warped mask is
|
61
|
+
# available later as nibabel stores file path reference for
|
62
|
+
# loading on computation
|
63
|
+
element_tempdir = WorkDirManager().get_element_tempdir(
|
64
|
+
prefix=f"fsl_mask_warper_{mask_name}_{uuid.uuid1()}"
|
65
|
+
)
|
66
|
+
|
67
|
+
# Save existing mask image to a tempfile
|
68
|
+
prewarp_mask_path = element_tempdir / "prewarp_mask.nii.gz"
|
69
|
+
nib.save(mask_img, prewarp_mask_path)
|
70
|
+
|
71
|
+
# Create a tempfile for warped output
|
72
|
+
warped_mask_path = element_tempdir / "mask_warped.nii.gz"
|
73
|
+
# Set applywarp command
|
74
|
+
applywarp_cmd = [
|
75
|
+
"applywarp",
|
76
|
+
"--interp=nn",
|
77
|
+
f"-i {prewarp_mask_path.resolve()}",
|
78
|
+
# use resampled reference
|
79
|
+
f"-r {target_data['reference_path'].resolve()}",
|
80
|
+
f"-w {extra_input['Warp']['path'].resolve()}",
|
81
|
+
f"-o {warped_mask_path.resolve()}",
|
82
|
+
]
|
83
|
+
# Call applywarp
|
84
|
+
run_ext_cmd(name="applywarp", cmd=applywarp_cmd)
|
85
|
+
|
86
|
+
# Load nifti
|
87
|
+
return nib.load(warped_mask_path)
|