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."""
10
2
11
3
from nipype import logging
12
4
from nipype .interfaces .base import (
13
- TraitedSpec , BaseInterfaceInputSpec , SimpleInterface , File
5
+ traits , TraitedSpec , BaseInterfaceInputSpec , SimpleInterface , File
14
6
)
15
7
16
8
LOGGER = logging .getLogger ('nipype.interface' )
17
9
18
10
19
11
class ExtractB0InputSpec (BaseInterfaceInputSpec ):
20
12
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 ' )
23
15
24
16
25
17
class ExtractB0OutputSpec (TraitedSpec ):
26
- out_file = File (exists = True , desc = 'mean b0 file' )
18
+ out_file = File (exists = True , desc = 'b0 file' )
27
19
28
20
29
21
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
+ """
30
33
input_spec = ExtractB0InputSpec
31
34
output_spec = ExtractB0OutputSpec
32
35
33
36
def _run_interface (self , runtime ):
34
37
self ._results ['out_file' ] = extract_b0 (
35
38
self .inputs .in_file ,
36
- self .inputs .in_rasb ,
39
+ self .inputs .b0_ixs ,
37
40
newpath = runtime .cwd )
38
41
return runtime
39
42
40
43
41
- def extract_b0 (in_file , b0_mask , newpath = None ):
44
+ def extract_b0 (in_file , b0_ixs , newpath = None ):
42
45
"""Extract the *b0* volumes from a DWI dataset."""
43
46
import numpy as np
44
47
import nibabel as nib
@@ -50,9 +53,7 @@ def extract_b0(in_file, b0_mask, newpath=None):
50
53
img = nib .load (in_file )
51
54
data = img .get_fdata ()
52
55
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 ]
56
57
57
58
hdr = img .header .copy ()
58
59
hdr .set_data_shape (b0 .shape )
0 commit comments