junifer 0.0.7.dev192__py3-none-any.whl → 0.0.7.dev217__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.
Potentially problematic release.
This version of junifer might be problematic. Click here for more details.
- junifer/_version.py +2 -2
- junifer/preprocess/warping/_ants_warper.py +71 -22
- junifer/preprocess/warping/_fsl_warper.py +205 -79
- junifer/preprocess/warping/space_warper.py +68 -20
- {junifer-0.0.7.dev192.dist-info → junifer-0.0.7.dev217.dist-info}/METADATA +1 -1
- {junifer-0.0.7.dev192.dist-info → junifer-0.0.7.dev217.dist-info}/RECORD +11 -11
- {junifer-0.0.7.dev192.dist-info → junifer-0.0.7.dev217.dist-info}/WHEEL +0 -0
- {junifer-0.0.7.dev192.dist-info → junifer-0.0.7.dev217.dist-info}/entry_points.txt +0 -0
- {junifer-0.0.7.dev192.dist-info → junifer-0.0.7.dev217.dist-info}/licenses/AUTHORS.rst +0 -0
- {junifer-0.0.7.dev192.dist-info → junifer-0.0.7.dev217.dist-info}/licenses/LICENSE.md +0 -0
- {junifer-0.0.7.dev192.dist-info → junifer-0.0.7.dev217.dist-info}/top_level.txt +0 -0
junifer/_version.py
CHANGED
|
@@ -28,7 +28,7 @@ version_tuple: VERSION_TUPLE
|
|
|
28
28
|
commit_id: COMMIT_ID
|
|
29
29
|
__commit_id__: COMMIT_ID
|
|
30
30
|
|
|
31
|
-
__version__ = version = '0.0.7.
|
|
32
|
-
__version_tuple__ = version_tuple = (0, 0, 7, '
|
|
31
|
+
__version__ = version = '0.0.7.dev217'
|
|
32
|
+
__version_tuple__ = version_tuple = (0, 0, 7, 'dev217')
|
|
33
33
|
|
|
34
34
|
__commit_id__ = commit_id = None
|
|
@@ -180,27 +180,74 @@ class ANTsWarper:
|
|
|
180
180
|
|
|
181
181
|
# Template space warping
|
|
182
182
|
else:
|
|
183
|
+
input_space = input["space"]
|
|
183
184
|
logger.debug(
|
|
184
|
-
f"Using ANTs to warp data from {
|
|
185
|
+
f"Using ANTs to warp data from {input_space} space "
|
|
186
|
+
f"to {reference} space"
|
|
185
187
|
)
|
|
186
188
|
|
|
187
|
-
#
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
189
|
+
# Native to MNI
|
|
190
|
+
if input_space == "native":
|
|
191
|
+
# Get warp file path
|
|
192
|
+
xfm_file_path = None
|
|
193
|
+
for entry in extra_input["Warp"]:
|
|
194
|
+
if entry["src"] == "native" and entry["dst"] == reference:
|
|
195
|
+
xfm_file_path = entry["path"]
|
|
196
|
+
if xfm_file_path is None:
|
|
197
|
+
raise_error(
|
|
198
|
+
klass=RuntimeError,
|
|
199
|
+
msg="Could not find correct warp file path",
|
|
200
|
+
)
|
|
201
|
+
|
|
202
|
+
# Use ResampleImage if input data resolution and reference
|
|
203
|
+
# resolution don't match
|
|
204
|
+
input_res = np.min(input["data"].header.get_zooms()[:3])
|
|
205
|
+
ref_res = np.min(
|
|
206
|
+
input["reference"]["data"].header.get_zooms()[:3]
|
|
207
|
+
)
|
|
208
|
+
logger.debug(f"Input resolution: {input_res}")
|
|
209
|
+
logger.debug(f"Reference resolution: {ref_res}")
|
|
210
|
+
if input_res != ref_res:
|
|
211
|
+
# Create a tempfile for resampled reference output
|
|
212
|
+
ref_path = (
|
|
213
|
+
element_tempdir
|
|
214
|
+
/ f"resampled_reference-{reference}.nii.gz"
|
|
215
|
+
)
|
|
216
|
+
# Set ResampleImage command
|
|
217
|
+
resample_image_cmd = [
|
|
218
|
+
"ResampleImage",
|
|
219
|
+
"3", # image dimension
|
|
220
|
+
f"{input['reference']['path'].resolve()}",
|
|
221
|
+
f"{ref_path.resolve()}",
|
|
222
|
+
f"{input_res}x{input_res}x{input_res}",
|
|
223
|
+
"0", # option for spacing and not size
|
|
224
|
+
"3 3", # Lanczos windowed sinc
|
|
225
|
+
]
|
|
226
|
+
# Call ResampleImage
|
|
227
|
+
run_ext_cmd(name="ResampleImage", cmd=resample_image_cmd)
|
|
228
|
+
else:
|
|
229
|
+
logger.debug(
|
|
230
|
+
"Reference resolution matches input resolution"
|
|
231
|
+
)
|
|
232
|
+
ref_path = input["reference"]["path"]
|
|
233
|
+
|
|
234
|
+
# MNI to MNI
|
|
235
|
+
else:
|
|
236
|
+
# Get xfm file
|
|
237
|
+
xfm_file_path = get_xfm(src=input_space, dst=reference)
|
|
238
|
+
# Get template space image in correct resolution
|
|
239
|
+
template_space_img = get_template(
|
|
240
|
+
space=reference,
|
|
241
|
+
target_img=input["data"],
|
|
242
|
+
extra_input=None,
|
|
243
|
+
)
|
|
244
|
+
# Save template
|
|
245
|
+
ref_path = element_tempdir / f"{reference}_T1w.nii.gz"
|
|
246
|
+
nib.save(template_space_img, ref_path)
|
|
200
247
|
|
|
201
248
|
# Create a tempfile for warped output
|
|
202
249
|
warped_output_path = element_tempdir / (
|
|
203
|
-
f"warped_data_from_{
|
|
250
|
+
f"warped_data_from_{input_space}_to_{reference}.nii.gz"
|
|
204
251
|
)
|
|
205
252
|
|
|
206
253
|
# Set antsApplyTransforms command
|
|
@@ -210,7 +257,7 @@ class ANTsWarper:
|
|
|
210
257
|
"-e 3",
|
|
211
258
|
"-n LanczosWindowedSinc",
|
|
212
259
|
f"-i {input['path'].resolve()}",
|
|
213
|
-
f"-r {
|
|
260
|
+
f"-r {ref_path.resolve()}",
|
|
214
261
|
f"-t {xfm_file_path.resolve()}",
|
|
215
262
|
f"-o {warped_output_path.resolve()}",
|
|
216
263
|
]
|
|
@@ -226,18 +273,20 @@ class ANTsWarper:
|
|
|
226
273
|
"data": nib.load(warped_output_path),
|
|
227
274
|
# Update warped input's space
|
|
228
275
|
"space": reference,
|
|
229
|
-
# Save reference path
|
|
230
|
-
|
|
276
|
+
# Save resampled reference path or overwrite original
|
|
277
|
+
# keeping it same
|
|
278
|
+
"reference": {"path": ref_path},
|
|
231
279
|
# Keep pre-warp space for further operations
|
|
232
|
-
"prewarp_space":
|
|
280
|
+
"prewarp_space": input_space,
|
|
233
281
|
}
|
|
234
282
|
)
|
|
235
283
|
|
|
236
284
|
# Check for data type's mask and warp if found
|
|
237
285
|
if input.get("mask") is not None:
|
|
286
|
+
logger.debug("Warping associated mask")
|
|
238
287
|
# Create a tempfile for warped mask output
|
|
239
288
|
apply_transforms_mask_out_path = element_tempdir / (
|
|
240
|
-
f"warped_mask_from_{
|
|
289
|
+
f"warped_mask_from_{input_space}_to_{reference}.nii.gz"
|
|
241
290
|
)
|
|
242
291
|
# Set antsApplyTransforms command
|
|
243
292
|
apply_transforms_mask_cmd = [
|
|
@@ -246,8 +295,8 @@ class ANTsWarper:
|
|
|
246
295
|
"-e 3",
|
|
247
296
|
"-n 'GenericLabel[NearestNeighbor]'",
|
|
248
297
|
f"-i {input['mask']['path'].resolve()}",
|
|
249
|
-
# use resampled reference
|
|
250
|
-
f"-r {
|
|
298
|
+
# use resampled reference or original
|
|
299
|
+
f"-r {ref_path.resolve()}",
|
|
251
300
|
f"-t {xfm_file_path.resolve()}",
|
|
252
301
|
f"-o {apply_transforms_mask_out_path.resolve()}",
|
|
253
302
|
]
|
|
@@ -40,6 +40,7 @@ class FSLWarper:
|
|
|
40
40
|
self,
|
|
41
41
|
input: dict[str, Any],
|
|
42
42
|
extra_input: dict[str, Any],
|
|
43
|
+
reference: str,
|
|
43
44
|
) -> dict[str, Any]: # pragma: no cover
|
|
44
45
|
"""Preprocess using FSL.
|
|
45
46
|
|
|
@@ -50,6 +51,10 @@ class FSLWarper:
|
|
|
50
51
|
extra_input : dict
|
|
51
52
|
The other fields in the Junifer Data object. Should have ``T1w``
|
|
52
53
|
and ``Warp`` data types.
|
|
54
|
+
reference : str
|
|
55
|
+
The data type or template space to use as reference for warping.
|
|
56
|
+
Template space conversion is only possible from native space,
|
|
57
|
+
not from another template space.
|
|
53
58
|
|
|
54
59
|
Returns
|
|
55
60
|
-------
|
|
@@ -62,102 +67,223 @@ class FSLWarper:
|
|
|
62
67
|
If warp file path could not be found in ``extra_input``.
|
|
63
68
|
|
|
64
69
|
"""
|
|
65
|
-
logger.debug("Using FSL for space warping")
|
|
66
|
-
|
|
67
|
-
# Get the min of the voxel sizes from input and use it as the
|
|
68
|
-
# resolution
|
|
69
|
-
resolution = np.min(input["data"].header.get_zooms()[:3])
|
|
70
|
-
|
|
71
|
-
# Get warp file path
|
|
72
|
-
warp_file_path = None
|
|
73
|
-
for entry in extra_input["Warp"]:
|
|
74
|
-
if entry["dst"] == "native":
|
|
75
|
-
warp_file_path = entry["path"]
|
|
76
|
-
if warp_file_path is None:
|
|
77
|
-
raise_error(
|
|
78
|
-
klass=RuntimeError, msg="Could not find correct warp file path"
|
|
79
|
-
)
|
|
80
|
-
|
|
81
70
|
# Create element-specific tempdir for storing post-warping assets
|
|
82
71
|
element_tempdir = WorkDirManager().get_element_tempdir(
|
|
83
72
|
prefix="fsl_warper"
|
|
84
73
|
)
|
|
85
74
|
|
|
86
|
-
#
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
f"-ref {extra_input['T1w']['path'].resolve()}",
|
|
94
|
-
f"-applyisoxfm {resolution}",
|
|
95
|
-
f"-out {flirt_out_path.resolve()}",
|
|
96
|
-
]
|
|
97
|
-
# Call flirt
|
|
98
|
-
run_ext_cmd(name="flirt", cmd=flirt_cmd)
|
|
99
|
-
|
|
100
|
-
# Create a tempfile for warped output
|
|
101
|
-
applywarp_out_path = element_tempdir / "warped_data.nii.gz"
|
|
102
|
-
# Set applywarp command
|
|
103
|
-
applywarp_cmd = [
|
|
104
|
-
"applywarp",
|
|
105
|
-
"--interp=spline",
|
|
106
|
-
f"-i {input['path'].resolve()}",
|
|
107
|
-
# use resampled reference
|
|
108
|
-
f"-r {flirt_out_path.resolve()}",
|
|
109
|
-
f"-w {warp_file_path.resolve()}",
|
|
110
|
-
f"-o {applywarp_out_path.resolve()}",
|
|
111
|
-
]
|
|
112
|
-
# Call applywarp
|
|
113
|
-
run_ext_cmd(name="applywarp", cmd=applywarp_cmd)
|
|
114
|
-
|
|
115
|
-
logger.debug("Updating warped data")
|
|
116
|
-
input.update(
|
|
117
|
-
{
|
|
118
|
-
# Update path to sync with "data"
|
|
119
|
-
"path": applywarp_out_path,
|
|
120
|
-
# Load nifti
|
|
121
|
-
"data": nib.load(applywarp_out_path),
|
|
122
|
-
# Use reference input's space as warped input's space
|
|
123
|
-
"space": extra_input["T1w"]["space"],
|
|
124
|
-
# Save resampled reference path
|
|
125
|
-
"reference": {"path": flirt_out_path},
|
|
126
|
-
# Keep pre-warp space for further operations
|
|
127
|
-
"prewarp_space": input["space"],
|
|
128
|
-
}
|
|
129
|
-
)
|
|
75
|
+
# Warping to native space
|
|
76
|
+
if reference == "T1w":
|
|
77
|
+
logger.debug("Using FSL for space warping")
|
|
78
|
+
|
|
79
|
+
# Get the min of the voxel sizes from input and use it as the
|
|
80
|
+
# resolution
|
|
81
|
+
resolution = np.min(input["data"].header.get_zooms()[:3])
|
|
130
82
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
83
|
+
# Get warp file path
|
|
84
|
+
warp_file_path = None
|
|
85
|
+
for entry in extra_input["Warp"]:
|
|
86
|
+
if entry["dst"] == "native":
|
|
87
|
+
warp_file_path = entry["path"]
|
|
88
|
+
if warp_file_path is None:
|
|
89
|
+
raise_error(
|
|
90
|
+
klass=RuntimeError,
|
|
91
|
+
msg="Could not find correct warp file path",
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
# Create a tempfile for resampled reference output
|
|
95
|
+
flirt_out_path = element_tempdir / "resampled_reference.nii.gz"
|
|
96
|
+
# Set flirt command
|
|
97
|
+
flirt_cmd = [
|
|
98
|
+
"flirt",
|
|
99
|
+
"-interp spline",
|
|
100
|
+
f"-in {extra_input['T1w']['path'].resolve()}",
|
|
101
|
+
f"-ref {extra_input['T1w']['path'].resolve()}",
|
|
102
|
+
f"-applyisoxfm {resolution}",
|
|
103
|
+
f"-out {flirt_out_path.resolve()}",
|
|
104
|
+
]
|
|
105
|
+
# Call flirt
|
|
106
|
+
run_ext_cmd(name="flirt", cmd=flirt_cmd)
|
|
107
|
+
|
|
108
|
+
# Create a tempfile for warped output
|
|
109
|
+
applywarp_out_path = element_tempdir / "warped_data.nii.gz"
|
|
135
110
|
# Set applywarp command
|
|
136
|
-
|
|
111
|
+
applywarp_cmd = [
|
|
137
112
|
"applywarp",
|
|
138
|
-
"--interp=
|
|
139
|
-
f"-i {input['
|
|
113
|
+
"--interp=spline",
|
|
114
|
+
f"-i {input['path'].resolve()}",
|
|
140
115
|
# use resampled reference
|
|
141
|
-
f"-r {
|
|
116
|
+
f"-r {flirt_out_path.resolve()}",
|
|
142
117
|
f"-w {warp_file_path.resolve()}",
|
|
143
|
-
f"-o {
|
|
118
|
+
f"-o {applywarp_out_path.resolve()}",
|
|
144
119
|
]
|
|
145
120
|
# Call applywarp
|
|
146
|
-
run_ext_cmd(name="applywarp", cmd=
|
|
121
|
+
run_ext_cmd(name="applywarp", cmd=applywarp_cmd)
|
|
147
122
|
|
|
148
|
-
logger.debug("Updating warped
|
|
123
|
+
logger.debug("Updating warped data")
|
|
149
124
|
input.update(
|
|
150
125
|
{
|
|
151
|
-
"
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
126
|
+
# Update path to sync with "data"
|
|
127
|
+
"path": applywarp_out_path,
|
|
128
|
+
# Load nifti
|
|
129
|
+
"data": nib.load(applywarp_out_path),
|
|
130
|
+
# Use reference input's space as warped input's space
|
|
131
|
+
"space": extra_input["T1w"]["space"],
|
|
132
|
+
# Save resampled reference path
|
|
133
|
+
"reference": {"path": flirt_out_path},
|
|
134
|
+
# Keep pre-warp space for further operations
|
|
135
|
+
"prewarp_space": input["space"],
|
|
136
|
+
}
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
# Check for data type's mask and warp if found
|
|
140
|
+
if input.get("mask") is not None:
|
|
141
|
+
# Create a tempfile for warped mask output
|
|
142
|
+
applywarp_mask_out_path = (
|
|
143
|
+
element_tempdir / "warped_mask.nii.gz"
|
|
144
|
+
)
|
|
145
|
+
# Set applywarp command
|
|
146
|
+
applywarp_mask_cmd = [
|
|
147
|
+
"applywarp",
|
|
148
|
+
"--interp=nn",
|
|
149
|
+
f"-i {input['mask']['path'].resolve()}",
|
|
150
|
+
# use resampled reference
|
|
151
|
+
f"-r {input['reference']['path'].resolve()}",
|
|
152
|
+
f"-w {warp_file_path.resolve()}",
|
|
153
|
+
f"-o {applywarp_mask_out_path.resolve()}",
|
|
154
|
+
]
|
|
155
|
+
# Call applywarp
|
|
156
|
+
run_ext_cmd(name="applywarp", cmd=applywarp_mask_cmd)
|
|
157
|
+
|
|
158
|
+
logger.debug("Updating warped mask data")
|
|
159
|
+
input.update(
|
|
160
|
+
{
|
|
161
|
+
"mask": {
|
|
162
|
+
# Update path to sync with "data"
|
|
163
|
+
"path": applywarp_mask_out_path,
|
|
164
|
+
# Load nifti
|
|
165
|
+
"data": nib.load(applywarp_mask_out_path),
|
|
166
|
+
# Use reference input's space as warped input
|
|
167
|
+
# mask's space
|
|
168
|
+
"space": extra_input["T1w"]["space"],
|
|
169
|
+
}
|
|
159
170
|
}
|
|
171
|
+
)
|
|
172
|
+
|
|
173
|
+
# Warping from native to template space
|
|
174
|
+
else:
|
|
175
|
+
logger.debug(
|
|
176
|
+
f"Using FSL to warp data from native space to {reference} "
|
|
177
|
+
"space"
|
|
178
|
+
)
|
|
179
|
+
|
|
180
|
+
# Get warp file path
|
|
181
|
+
warp_file_path = None
|
|
182
|
+
for entry in extra_input["Warp"]:
|
|
183
|
+
if entry["src"] == "native" and entry["dst"] == reference:
|
|
184
|
+
warp_file_path = entry["path"]
|
|
185
|
+
if warp_file_path is None:
|
|
186
|
+
raise_error(
|
|
187
|
+
klass=RuntimeError,
|
|
188
|
+
msg="Could not find correct warp file path",
|
|
189
|
+
)
|
|
190
|
+
|
|
191
|
+
# Use flirt if input data resolution and reference resolution don't
|
|
192
|
+
# match
|
|
193
|
+
input_resolution = np.min(input["data"].header.get_zooms()[:3])
|
|
194
|
+
ref_resolution = np.min(
|
|
195
|
+
input["reference"]["data"].header.get_zooms()[:3]
|
|
196
|
+
)
|
|
197
|
+
logger.debug(f"Input resolution: {input_resolution}")
|
|
198
|
+
logger.debug(f"Reference resolution: {ref_resolution}")
|
|
199
|
+
if input_resolution != ref_resolution:
|
|
200
|
+
logger.debug("Resampling reference to match input resolution")
|
|
201
|
+
# Create a tempfile for resampled reference output
|
|
202
|
+
ref_path = (
|
|
203
|
+
element_tempdir / f"resampled_reference-{reference}.nii.gz"
|
|
204
|
+
)
|
|
205
|
+
# Set flirt command
|
|
206
|
+
flirt_cmd = [
|
|
207
|
+
"flirt",
|
|
208
|
+
"-interp spline",
|
|
209
|
+
f"-in {input['reference']['path'].resolve()}",
|
|
210
|
+
f"-ref {input['reference']['path'].resolve()}",
|
|
211
|
+
f"-applyisoxfm {input_resolution}",
|
|
212
|
+
f"-out {ref_path.resolve()}",
|
|
213
|
+
]
|
|
214
|
+
# Call flirt
|
|
215
|
+
run_ext_cmd(name="flirt", cmd=flirt_cmd)
|
|
216
|
+
else:
|
|
217
|
+
logger.debug("Reference resolution matches input resolution")
|
|
218
|
+
ref_path = input["reference"]["path"]
|
|
219
|
+
|
|
220
|
+
# Create a tempfile for warped output
|
|
221
|
+
applywarp_out_path = (
|
|
222
|
+
element_tempdir
|
|
223
|
+
/ f"warped_data_from_native_to_{reference}.nii.gz"
|
|
224
|
+
)
|
|
225
|
+
# Set applywarp command
|
|
226
|
+
applywarp_cmd = [
|
|
227
|
+
"applywarp",
|
|
228
|
+
"--interp=spline",
|
|
229
|
+
f"-i {input['path'].resolve()}",
|
|
230
|
+
# use resampled reference or original
|
|
231
|
+
f"-r {ref_path.resolve()}",
|
|
232
|
+
f"-w {warp_file_path.resolve()}",
|
|
233
|
+
f"-o {applywarp_out_path.resolve()}",
|
|
234
|
+
]
|
|
235
|
+
# Call applywarp
|
|
236
|
+
run_ext_cmd(name="applywarp", cmd=applywarp_cmd)
|
|
237
|
+
|
|
238
|
+
logger.debug("Updating warped data")
|
|
239
|
+
input.update(
|
|
240
|
+
{
|
|
241
|
+
# Update path to sync with "data"
|
|
242
|
+
"path": applywarp_out_path,
|
|
243
|
+
# Load nifti
|
|
244
|
+
"data": nib.load(applywarp_out_path),
|
|
245
|
+
# Switch space and prewarp_space
|
|
246
|
+
"space": reference,
|
|
247
|
+
"prewarp_space": input["space"],
|
|
248
|
+
# Save resampled reference path or overwrite original
|
|
249
|
+
# keeping it same
|
|
250
|
+
"reference": {"path": ref_path},
|
|
160
251
|
}
|
|
161
252
|
)
|
|
162
253
|
|
|
254
|
+
# Check for data type's mask and warp if found
|
|
255
|
+
if input.get("mask") is not None:
|
|
256
|
+
logger.debug("Warping associated mask")
|
|
257
|
+
# Create a tempfile for warped mask output
|
|
258
|
+
applywarp_mask_out_path = (
|
|
259
|
+
element_tempdir
|
|
260
|
+
/ f"warped_mask_from_native_to_{reference}.nii.gz"
|
|
261
|
+
)
|
|
262
|
+
# Set applywarp command
|
|
263
|
+
applywarp_mask_cmd = [
|
|
264
|
+
"applywarp",
|
|
265
|
+
"--interp=nn",
|
|
266
|
+
f"-i {input['mask']['path'].resolve()}",
|
|
267
|
+
# use resampled reference or original
|
|
268
|
+
f"-r {ref_path.resolve()}",
|
|
269
|
+
f"-w {warp_file_path.resolve()}",
|
|
270
|
+
f"-o {applywarp_mask_out_path.resolve()}",
|
|
271
|
+
]
|
|
272
|
+
# Call applywarp
|
|
273
|
+
run_ext_cmd(name="applywarp", cmd=applywarp_mask_cmd)
|
|
274
|
+
|
|
275
|
+
logger.debug("Updating warped mask data")
|
|
276
|
+
input.update(
|
|
277
|
+
{
|
|
278
|
+
"mask": {
|
|
279
|
+
# Update path to sync with "data"
|
|
280
|
+
"path": applywarp_mask_out_path,
|
|
281
|
+
# Load nifti
|
|
282
|
+
"data": nib.load(applywarp_mask_out_path),
|
|
283
|
+
# Update mask's space
|
|
284
|
+
"space": reference,
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
)
|
|
288
|
+
|
|
163
289
|
return input
|
|
@@ -133,7 +133,7 @@ class SpaceWarper(BasePreprocessor):
|
|
|
133
133
|
# Does not add any new keys
|
|
134
134
|
return input_type
|
|
135
135
|
|
|
136
|
-
def preprocess(
|
|
136
|
+
def preprocess( # noqa: C901
|
|
137
137
|
self,
|
|
138
138
|
input: dict[str, Any],
|
|
139
139
|
extra_input: Optional[dict[str, Any]] = None,
|
|
@@ -162,7 +162,7 @@ class SpaceWarper(BasePreprocessor):
|
|
|
162
162
|
i.e., using ``"T1w"`` as reference.
|
|
163
163
|
RuntimeError
|
|
164
164
|
If warper could not be found in ``extra_input`` when
|
|
165
|
-
``using="auto"`` or
|
|
165
|
+
``using="auto"`` or converting from native space or
|
|
166
166
|
if the data is in the correct space and does not require
|
|
167
167
|
warping or
|
|
168
168
|
if FSL is used when ``reference="T1w"``.
|
|
@@ -184,6 +184,7 @@ class SpaceWarper(BasePreprocessor):
|
|
|
184
184
|
input = FSLWarper().preprocess(
|
|
185
185
|
input=input,
|
|
186
186
|
extra_input=extra_input,
|
|
187
|
+
reference=self.reference,
|
|
187
188
|
)
|
|
188
189
|
elif self.using == "ants":
|
|
189
190
|
input = ANTsWarper().preprocess(
|
|
@@ -204,6 +205,7 @@ class SpaceWarper(BasePreprocessor):
|
|
|
204
205
|
input = FSLWarper().preprocess(
|
|
205
206
|
input=input,
|
|
206
207
|
extra_input=extra_input,
|
|
208
|
+
reference=self.reference,
|
|
207
209
|
)
|
|
208
210
|
elif warper == "ants":
|
|
209
211
|
input = ANTsWarper().preprocess(
|
|
@@ -211,10 +213,11 @@ class SpaceWarper(BasePreprocessor):
|
|
|
211
213
|
extra_input=extra_input,
|
|
212
214
|
reference=self.reference,
|
|
213
215
|
)
|
|
214
|
-
# Transform to template space
|
|
215
|
-
|
|
216
|
+
# Transform to template space
|
|
217
|
+
if self.using in ["fsl", "ants"] and self.reference != "T1w":
|
|
218
|
+
input_space = input["space"]
|
|
216
219
|
# Check pre-requirements for space manipulation
|
|
217
|
-
if self.
|
|
220
|
+
if self.using == "ants" and self.reference == input_space:
|
|
218
221
|
raise_error(
|
|
219
222
|
(
|
|
220
223
|
f"The target data is in {self.reference} space "
|
|
@@ -224,20 +227,65 @@ class SpaceWarper(BasePreprocessor):
|
|
|
224
227
|
),
|
|
225
228
|
klass=RuntimeError,
|
|
226
229
|
)
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
230
|
+
# Transform from native to MNI possible conditionally
|
|
231
|
+
if input_space == "native": # pragma: no cover
|
|
232
|
+
# Check for reference as no T1w available
|
|
233
|
+
if input.get("reference") is None:
|
|
234
|
+
raise_error(
|
|
235
|
+
"`reference` key missing from input data type."
|
|
236
|
+
)
|
|
237
|
+
# Check for extra inputs
|
|
238
|
+
if extra_input is None:
|
|
239
|
+
raise_error(
|
|
240
|
+
"No extra input provided, requires `Warp` "
|
|
241
|
+
"data type in particular."
|
|
242
|
+
)
|
|
243
|
+
# Warp
|
|
244
|
+
input_prewarp_space = input["prewarp_space"]
|
|
245
|
+
warper = None
|
|
246
|
+
for entry in extra_input["Warp"]:
|
|
247
|
+
if (
|
|
248
|
+
entry["src"] == input_space
|
|
249
|
+
and entry["dst"] == input_prewarp_space
|
|
250
|
+
):
|
|
251
|
+
warper = entry["warper"]
|
|
252
|
+
if warper is None:
|
|
253
|
+
raise_error(
|
|
254
|
+
klass=RuntimeError, msg="Could not find correct warper"
|
|
255
|
+
)
|
|
256
|
+
if warper == "fsl":
|
|
257
|
+
input = FSLWarper().preprocess(
|
|
258
|
+
input=input,
|
|
259
|
+
extra_input=extra_input,
|
|
260
|
+
reference=input_prewarp_space,
|
|
261
|
+
)
|
|
262
|
+
elif warper == "ants":
|
|
263
|
+
input = ANTsWarper().preprocess(
|
|
264
|
+
input=input,
|
|
265
|
+
extra_input=extra_input,
|
|
266
|
+
reference=input_prewarp_space,
|
|
267
|
+
)
|
|
268
|
+
else:
|
|
269
|
+
raise_error(
|
|
270
|
+
klass=RuntimeError, msg="Could not find correct warper"
|
|
271
|
+
)
|
|
272
|
+
else:
|
|
273
|
+
# Transform from MNI to MNI template space not possible
|
|
274
|
+
if self.using == "fsl":
|
|
275
|
+
raise_error(
|
|
276
|
+
(
|
|
277
|
+
f"Warping from {input_space} space to "
|
|
278
|
+
f"{self.reference} space not possible with "
|
|
279
|
+
"FSL, use ANTs instead."
|
|
280
|
+
),
|
|
281
|
+
klass=RuntimeError,
|
|
282
|
+
)
|
|
283
|
+
# Transform from MNI to MNI template space possible
|
|
284
|
+
else:
|
|
285
|
+
input = ANTsWarper().preprocess(
|
|
286
|
+
input=input,
|
|
287
|
+
extra_input={},
|
|
288
|
+
reference=self.reference,
|
|
289
|
+
)
|
|
242
290
|
|
|
243
291
|
return input, None
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: junifer
|
|
3
|
-
Version: 0.0.7.
|
|
3
|
+
Version: 0.0.7.dev217
|
|
4
4
|
Summary: JUelich NeuroImaging FEature extractoR
|
|
5
5
|
Author-email: Fede Raimondo <f.raimondo@fz-juelich.de>, Synchon Mandal <s.mandal@fz-juelich.de>
|
|
6
6
|
Maintainer-email: Fede Raimondo <f.raimondo@fz-juelich.de>, Synchon Mandal <s.mandal@fz-juelich.de>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
junifer/__init__.py,sha256=2McgH1yNue6Z1V26-uN_mfMjbTcx4CLhym-DMBl5xA4,266
|
|
2
2
|
junifer/__init__.pyi,sha256=SsTvgq2Dod6UqJN96GH1lCphH6hJQQurEJHGNhHjGUI,508
|
|
3
|
-
junifer/_version.py,sha256=
|
|
3
|
+
junifer/_version.py,sha256=jojIipt7bxgP509PRfGj-EkE7lgUM4vZF4nivU5itTI,721
|
|
4
4
|
junifer/conftest.py,sha256=qnumYhFkwHBPrzvhPFOFHBp22x5zU0JfVBDOWjidlGo,1583
|
|
5
5
|
junifer/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
6
|
junifer/stats.py,sha256=e9aaagMGtgpRfW3Wdpz9ocpnYld1IWylCDcjFUgX9Mk,6225
|
|
@@ -297,10 +297,10 @@ junifer/preprocess/tests/test_temporal_filter.py,sha256=ZgEDIGqpFX3dGGKOJAf1vhvg
|
|
|
297
297
|
junifer/preprocess/tests/test_temporal_slicer.py,sha256=bbt6kxOM-Bv_s9iPn4wrf2YxpA64xO2S0kgRYUEeBNo,4061
|
|
298
298
|
junifer/preprocess/warping/__init__.py,sha256=rzUUP7-6H_nygQ7a7TBZ4_RY7p0ELacosYsWQbSdVZk,214
|
|
299
299
|
junifer/preprocess/warping/__init__.pyi,sha256=Drbqp8N3uprvXcKSxqdfj90fesz9XYVLgivhPnKAYcc,65
|
|
300
|
-
junifer/preprocess/warping/_ants_warper.py,sha256=
|
|
301
|
-
junifer/preprocess/warping/_fsl_warper.py,sha256=
|
|
300
|
+
junifer/preprocess/warping/_ants_warper.py,sha256=VCporb5Nq21m3xTvIdgHZPPlXRgBtTzB39VYk1bfpW8,12441
|
|
301
|
+
junifer/preprocess/warping/_fsl_warper.py,sha256=08enG3jKIHzkv4bwpZYY2ITVhBaBSWcXTT_AJCFkkSg,10770
|
|
302
302
|
junifer/preprocess/warping/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
303
|
-
junifer/preprocess/warping/space_warper.py,sha256=
|
|
303
|
+
junifer/preprocess/warping/space_warper.py,sha256=r79c_g85QG-VgY2hfc2__zF4scP9CtZCR-ZPIu6Ihsc,10040
|
|
304
304
|
junifer/preprocess/warping/tests/test_space_warper.py,sha256=amFHtt-q7L7v9uL4cOvrmHEbUOGDhmoMHkLnKJ0dF7A,5543
|
|
305
305
|
junifer/storage/__init__.py,sha256=aPGBFPPsTcZYMdkC_o5HIrzRIIwp-bc5bJDoh_GuQmo,270
|
|
306
306
|
junifer/storage/__init__.pyi,sha256=MHC-R129z_WuXVQuKBrFu8H1wqmUPAl5ZOQT_WZaXek,292
|
|
@@ -344,10 +344,10 @@ junifer/utils/tests/test_config.py,sha256=7ltIXuwb_W4Mv_1dxQWyiyM10XgUAfsWKV6D_i
|
|
|
344
344
|
junifer/utils/tests/test_fs.py,sha256=WQS7cKlKEZ742CIuiOYYpueeAhY9PqlastfDVpVVtvE,923
|
|
345
345
|
junifer/utils/tests/test_helpers.py,sha256=k5qqfxK8dFyuewTJyR1Qn6-nFaYNuVr0ysc18bfPjyU,929
|
|
346
346
|
junifer/utils/tests/test_logging.py,sha256=W4tFKmaf8_CxnWZ-o_-XxM7DQbhGG18RsLZJk8bZelI,8163
|
|
347
|
-
junifer-0.0.7.
|
|
348
|
-
junifer-0.0.7.
|
|
349
|
-
junifer-0.0.7.
|
|
350
|
-
junifer-0.0.7.
|
|
351
|
-
junifer-0.0.7.
|
|
352
|
-
junifer-0.0.7.
|
|
353
|
-
junifer-0.0.7.
|
|
347
|
+
junifer-0.0.7.dev217.dist-info/licenses/AUTHORS.rst,sha256=rmULKpchpSol4ExWFdm-qu4fkpSZPYqIESVJBZtGb6E,163
|
|
348
|
+
junifer-0.0.7.dev217.dist-info/licenses/LICENSE.md,sha256=MqCnOBu8uXsEOzRZWh9EBVfVz-kE9NkXcLCrtGXo2yU,34354
|
|
349
|
+
junifer-0.0.7.dev217.dist-info/METADATA,sha256=1U4XFku69TLNTWrDOwB0qCDrVzTLTw2xdMdNIH2p8lY,8396
|
|
350
|
+
junifer-0.0.7.dev217.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
351
|
+
junifer-0.0.7.dev217.dist-info/entry_points.txt,sha256=6O8ru0BP-SP7YMUZiizFNoaZ2HvJpadO2G7nKk4PwjI,48
|
|
352
|
+
junifer-0.0.7.dev217.dist-info/top_level.txt,sha256=4bAq1R2QFQ4b3hohjys2JBvxrl0GKk5LNFzYvz9VGcA,8
|
|
353
|
+
junifer-0.0.7.dev217.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|