Skip to content

Commit a0e205c

Browse files
committed
fix image interfaces
1 parent 68c0c09 commit a0e205c

File tree

2 files changed

+40
-13
lines changed

2 files changed

+40
-13
lines changed

dmriprep/interfaces/images.py

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
11
"""Image tools interfaces."""
2+
from pathlib import Path
3+
24
from nipype import logging
35
from nipype.interfaces.base import (
4-
traits, TraitedSpec, BaseInterfaceInputSpec, SimpleInterface, File
6+
BaseInterfaceInputSpec,
7+
File,
8+
SimpleInterface,
9+
TraitedSpec,
10+
traits
511
)
612

7-
from dmriprep.utils.images import extract_b0, rescale_b0, median
13+
from dmriprep.utils.images import extract_b0, median, rescale_b0
814

915
LOGGER = logging.getLogger('nipype.interface')
1016

1117

1218
class _ExtractB0InputSpec(BaseInterfaceInputSpec):
1319
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')
1621

1722

1823
class _ExtractB0OutputSpec(TraitedSpec):
19-
out_file = File(exists=True, desc='b0 file')
24+
out_file = File(exists=True, desc='output b0 file')
2025

2126

2227
class ExtractB0(SimpleInterface):
@@ -37,10 +42,18 @@ class ExtractB0(SimpleInterface):
3742
output_spec = _ExtractB0OutputSpec
3843

3944
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(
4148
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+
)
4457
return runtime
4558

4659

@@ -72,13 +85,27 @@ class RescaleB0(SimpleInterface):
7285
output_spec = _RescaleB0OutputSpec
7386

7487
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+
75103
self._results['out_b0s'] = rescale_b0(
76104
self.inputs.in_file,
77-
self.inputs.mask_file,
78-
out_path=runtime.cwd
105+
self.inputs.mask_file, out_b0s
79106
)
80107
self._results['out_ref'] = median(
81108
self._results['out_b0s'],
82-
out_path=runtime.cwd
109+
out_path=out_ref
83110
)
84111
return runtime

dmriprep/utils/images.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import numpy as np
21
import nibabel as nb
2+
import numpy as np
33
from nipype.utils.filemanip import fname_presuffix
44

55

@@ -25,7 +25,7 @@ def rescale_b0(in_file, mask_file, out_path=None):
2525
"""Rescale the input volumes using the median signal intensity."""
2626
if out_path is None:
2727
out_path = fname_presuffix(
28-
in_file, suffix='_rescaled_b0', use_ext=True)
28+
in_file, suffix='_rescaled', use_ext=True)
2929

3030
img = nb.load(in_file)
3131
if img.dataobj.ndim == 3:

0 commit comments

Comments
 (0)