Skip to content

Commit d93d6c8

Browse files
josephmjeoesteban
authored andcommitted
update to use inputs according to #26
1 parent 7d34342 commit d93d6c8

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

dmriprep/interfaces/images.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,47 @@
1-
#!/usr/bin/env python
2-
# -*- coding: utf-8 -*-
3-
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
4-
# vi: set ft=python sts=4 ts=4 sw=4 et:
5-
"""
6-
Image tools interfaces
7-
~~~~~~~~~~~~~~~~~~~~~~
8-
9-
"""
1+
"""Image tools interfaces."""
102

113
from nipype import logging
124
from nipype.interfaces.base import (
13-
TraitedSpec, BaseInterfaceInputSpec, SimpleInterface, File
5+
traits, TraitedSpec, BaseInterfaceInputSpec, SimpleInterface, File
146
)
157

168
LOGGER = logging.getLogger('nipype.interface')
179

1810

1911
class ExtractB0InputSpec(BaseInterfaceInputSpec):
2012
in_file = File(exists=True, mandatory=True, desc='dwi file')
21-
in_rasb = File(exists=True, mandatory=True,
22-
desc='File containing the gradient directions in RAS+ scanner coordinates')
13+
b0_ixs = traits.List(traits.Int, mandatory=True,
14+
desc='Index of b0s')
2315

2416

2517
class ExtractB0OutputSpec(TraitedSpec):
26-
out_file = File(exists=True, desc='mean b0 file')
18+
out_file = File(exists=True, desc='b0 file')
2719

2820

2921
class ExtractB0(SimpleInterface):
22+
"""
23+
24+
Example
25+
-------
26+
27+
>>> os.chdir(tmpdir)
28+
>>> check = ExtractB0(
29+
... in_file=str(data_dir / 'dwi.nii.gz'),
30+
... b0_ixs=[0, 9, 18, 27, 36, 45, 54, 63, 72, 81, 90, 100]).run()
31+
32+
"""
3033
input_spec = ExtractB0InputSpec
3134
output_spec = ExtractB0OutputSpec
3235

3336
def _run_interface(self, runtime):
3437
self._results['out_file'] = extract_b0(
3538
self.inputs.in_file,
36-
self.inputs.in_rasb,
39+
self.inputs.b0_ixs,
3740
newpath=runtime.cwd)
3841
return runtime
3942

4043

41-
def extract_b0(in_file, b0_mask, newpath=None):
44+
def extract_b0(in_file, b0_ixs, newpath=None):
4245
"""Extract the *b0* volumes from a DWI dataset."""
4346
import numpy as np
4447
import nibabel as nib
@@ -50,9 +53,7 @@ def extract_b0(in_file, b0_mask, newpath=None):
5053
img = nib.load(in_file)
5154
data = img.get_fdata()
5255

53-
bvals = np.loadtxt(in_rasb, usecols=-1, skiprows=1)
54-
55-
b0 = data[..., np.array(b0_mask, dtype=bool)]
56+
b0 = data[..., b0_ixs]
5657

5758
hdr = img.header.copy()
5859
hdr.set_data_shape(b0.shape)

0 commit comments

Comments
 (0)