1
1
"""Image tools interfaces."""
2
+ from pathlib import Path
3
+
2
4
from nipype import logging
3
5
from nipype .interfaces .base import (
4
- traits , TraitedSpec , BaseInterfaceInputSpec , SimpleInterface , File
6
+ BaseInterfaceInputSpec ,
7
+ File ,
8
+ SimpleInterface ,
9
+ TraitedSpec ,
10
+ traits
5
11
)
6
12
7
- from dmriprep .utils .images import extract_b0 , rescale_b0 , median
13
+ from dmriprep .utils .images import extract_b0 , median , rescale_b0
8
14
9
15
LOGGER = logging .getLogger ('nipype.interface' )
10
16
11
17
12
18
class _ExtractB0InputSpec (BaseInterfaceInputSpec ):
13
19
in_file = File (exists = True , mandatory = True , desc = 'dwi file' )
14
- b0_ixs = traits .List (traits .Int , mandatory = True ,
15
- desc = 'Index of b0s' )
20
+ b0_ixs = traits .List (traits .Int , mandatory = True , desc = 'Index of b0s' )
16
21
17
22
18
23
class _ExtractB0OutputSpec (TraitedSpec ):
19
- out_file = File (exists = True , desc = 'b0 file' )
24
+ out_file = File (exists = True , desc = 'output b0 file' )
20
25
21
26
22
27
class ExtractB0 (SimpleInterface ):
@@ -37,10 +42,18 @@ class ExtractB0(SimpleInterface):
37
42
output_spec = _ExtractB0OutputSpec
38
43
39
44
def _run_interface (self , runtime ):
40
- self ._results ['out_file' ] = extract_b0 (
45
+ from nipype .utils .filemanip import fname_presuffix
46
+
47
+ out_file = fname_presuffix (
41
48
self .inputs .in_file ,
42
- self .inputs .b0_ixs ,
43
- out_path = runtime .cwd )
49
+ suffix = '_b0' ,
50
+ use_ext = True ,
51
+ newpath = str (Path (runtime .cwd ).absolute ()),
52
+ )
53
+
54
+ self ._results ['out_file' ] = extract_b0 (
55
+ self .inputs .in_file , self .inputs .b0_ixs , out_file
56
+ )
44
57
return runtime
45
58
46
59
@@ -72,13 +85,27 @@ class RescaleB0(SimpleInterface):
72
85
output_spec = _RescaleB0OutputSpec
73
86
74
87
def _run_interface (self , runtime ):
88
+ from nipype .utils .filemanip import fname_presuffix
89
+
90
+ out_b0s = fname_presuffix (
91
+ self .inputs .in_file ,
92
+ suffix = '_rescaled' ,
93
+ use_ext = True ,
94
+ newpath = str (Path (runtime .cwd ).absolute ())
95
+ )
96
+ out_ref = fname_presuffix (
97
+ self .inputs .in_file ,
98
+ suffix = '_ref' ,
99
+ use_ext = True ,
100
+ newpath = str (Path (runtime .cwd ).absolute ())
101
+ )
102
+
75
103
self ._results ['out_b0s' ] = rescale_b0 (
76
104
self .inputs .in_file ,
77
- self .inputs .mask_file ,
78
- out_path = runtime .cwd
105
+ self .inputs .mask_file , out_b0s
79
106
)
80
107
self ._results ['out_ref' ] = median (
81
108
self ._results ['out_b0s' ],
82
- out_path = runtime . cwd
109
+ out_path = out_ref
83
110
)
84
111
return runtime
0 commit comments