Skip to content

Commit 50536d4

Browse files
committed
Added interface to FSL POSSUM/b0calc
1 parent e815741 commit 50536d4

File tree

4 files changed

+160
-0
lines changed

4 files changed

+160
-0
lines changed

nipype/interfaces/fsl/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,5 @@
2727
from .maths import (ChangeDataType, Threshold, MeanImage, ApplyMask,
2828
IsotropicSmooth, TemporalFilter, DilateImage, ErodeImage,
2929
SpatialFilter, UnaryMaths, BinaryMaths, MultiImageMaths)
30+
31+
from .possum import (B0Calc)

nipype/interfaces/fsl/possum.py

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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+
# @Author: oesteban - [email protected]
7+
# @Date: 2014-07-03 15:27:53
8+
# @Last Modified by: oesteban
9+
# @Last Modified time: 2014-07-03 16:26:09
10+
"""
11+
The possum module provides classes for interfacing with `POSSUM
12+
<http://fsl.fmrib.ox.ac.uk/fsl/fslwiki/POSSUM>`_ command line tools.
13+
Please, check out the link for pertinent citations using POSSUM.
14+
15+
.. Note:: This was written to work with FSL version 5.0.6.
16+
17+
Change directory to provide relative paths for doctests
18+
>>> import os
19+
>>> filepath = os.path.dirname( os.path.realpath( __file__ ) )
20+
>>> datadir = os.path.realpath(os.path.join(filepath, '../../testing/data'))
21+
>>> os.chdir(datadir)
22+
23+
"""
24+
25+
import os
26+
import shutil
27+
import warnings
28+
29+
from nipype.interfaces.fsl.base import FSLCommand, FSLCommandInputSpec, Info
30+
from nipype.interfaces.base import (TraitedSpec, isdefined, File, Directory,
31+
InputMultiPath, OutputMultiPath, traits)
32+
from nipype.utils.filemanip import fname_presuffix, split_filename, copyfile
33+
34+
35+
class B0CalcInputSpec(FSLCommandInputSpec):
36+
in_file = File(exists=True, mandatory=True, argstr='-i %s', position=0,
37+
desc='filename of input image (usually a tissue/air segmentation)')
38+
out_file = File(argstr='-o %s', position=1, name_source=['in_file'],
39+
name_template='%s_b0field', output_name='out_file',
40+
desc='filename of B0 output volume')
41+
42+
43+
x_grad = traits.Float(0.0, argstr='--gx=%0.4f', desc=('Value for zeroth-order x-gradient field '
44+
'(per mm)'))
45+
y_grad = traits.Float(0.0, argstr='--gy=%0.4f', desc=('Value for zeroth-order y-gradient field '
46+
'(per mm)'))
47+
z_grad = traits.Float(0.0, argstr='--gz=%0.4f', desc=('Value for zeroth-order z-gradient field '
48+
'(per mm)'))
49+
50+
x_b0 = traits.Float(0.0, argstr='--b0x=%0.2f', desc=('Value for zeroth-order b0 field '
51+
'(x-component), in Tesla'))
52+
y_b0 = traits.Float(0.0, argstr='--b0y=%0.2f', desc=('Value for zeroth-order b0 field '
53+
'(y-component), in Tesla'))
54+
z_b0 = traits.Float(1.0, argstr='--b0=%0.2f', desc=('Value for zeroth-order b0 field '
55+
'(z-component), in Tesla'))
56+
57+
delta = traits.Float(-9.45e-6, argstr='-d %e', desc='Delta value (chi_tissue - chi_air)')
58+
chi_air = traits.Float(4.0e-7, argstr='--chi0=%e', desc='susceptibility of air')
59+
compute_xyz = traits.Bool(False, argstr='--xyz',
60+
desc='calculate and save all 3 field components (i.e. x,y,z)')
61+
extendboundary = traits.Float(1.0, argstr='--extendboundary=%0.2f', desc=('Relative proportion to '
62+
'extend voxels at boundary'))
63+
directconv = traits.Bool(False, argstr='--directconv',
64+
desc='use direct (image space) convolution, not FFT')
65+
66+
67+
class B0CalcOutputSpec(TraitedSpec):
68+
out_file = File(exists=True, desc='filename of B0 output volume')
69+
70+
71+
class B0Calc(FSLCommand):
72+
"""
73+
B0 inhomogeneities occur at interfaces of materials with different magnetic susceptibilities,
74+
such as tissue-air interfaces. These differences lead to distortion in the local magnetic field,
75+
as Maxwell’s equations need to be satisfied. An example of B0 inhomogneity is the first volume
76+
of the 4D volume ```$FSLDIR/data/possum/b0_ppm.nii.gz```.
77+
78+
Examples ::
79+
80+
>>> from nipype.interfaces.fsl import B0Calc
81+
>>> b0calc = B0Calc()
82+
>>> b0calc.inputs.in_file = 'tissue+air_map.nii'
83+
>>> b0calc.inputs.z_b0 = 3.0
84+
>>> b0calc.cmdline
85+
'b0calc -i tissue+air_map.nii -o tissue+air_map_b0field.nii.gz --b0=3.00'
86+
87+
"""
88+
89+
_cmd = 'b0calc'
90+
input_spec = B0CalcInputSpec
91+
output_spec = B0CalcOutputSpec
92+
93+
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT
2+
from nipype.testing import assert_equal
3+
from nipype.interfaces.fsl.possum import B0Calc
4+
5+
def test_B0Calc_inputs():
6+
input_map = dict(args=dict(argstr='%s',
7+
),
8+
chi_air=dict(argstr='--chi0=%e',
9+
),
10+
compute_xyz=dict(argstr='--xyz',
11+
),
12+
delta=dict(argstr='-d %e',
13+
),
14+
directconv=dict(argstr='--directconv',
15+
),
16+
environ=dict(nohash=True,
17+
usedefault=True,
18+
),
19+
extendboundary=dict(argstr='--extendboundary=%0.2f',
20+
),
21+
ignore_exception=dict(nohash=True,
22+
usedefault=True,
23+
),
24+
in_file=dict(argstr='-i %s',
25+
mandatory=True,
26+
position=0,
27+
),
28+
out_file=dict(argstr='-o %s',
29+
name_source=['in_file'],
30+
name_template='%s_b0field',
31+
output_name='out_file',
32+
position=1,
33+
),
34+
output_type=dict(),
35+
terminal_output=dict(mandatory=True,
36+
nohash=True,
37+
),
38+
x_b0=dict(argstr='--b0x=%0.2f',
39+
),
40+
x_grad=dict(argstr='--gx=%0.4f',
41+
),
42+
y_b0=dict(argstr='--b0y=%0.2f',
43+
),
44+
y_grad=dict(argstr='--gy=%0.4f',
45+
),
46+
z_b0=dict(argstr='--b0=%0.2f',
47+
),
48+
z_grad=dict(argstr='--gz=%0.4f',
49+
),
50+
)
51+
inputs = B0Calc.input_spec()
52+
53+
for key, metadata in input_map.items():
54+
for metakey, value in metadata.items():
55+
yield assert_equal, getattr(inputs.traits()[key], metakey), value
56+
57+
def test_B0Calc_outputs():
58+
output_map = dict(out_file=dict(),
59+
)
60+
outputs = B0Calc.output_spec()
61+
62+
for key, metadata in output_map.items():
63+
for metakey, value in metadata.items():
64+
yield assert_equal, getattr(outputs.traits()[key], metakey), value
65+

nipype/testing/data/tissue+air_map.nii

Whitespace-only changes.

0 commit comments

Comments
 (0)