Skip to content

Commit ccbca51

Browse files
committed
Merge branch 'master' into fix/ants_resampling
2 parents ced8260 + a44b546 commit ccbca51

16 files changed

+236
-16
lines changed

CHANGES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Next Release
22
============
33

4+
* ENH: New FSL interface: EpiReg
45
* ENH: New Freesurfer interface: Tkregister2 (for conversion of fsl style matrices to freesurfer format)
56
* ENH: New FSL interfaces: WarpPoints, WarpPointsToStd.
67
* ENH: New Freesurfer interface: MRIPretess

nipype/interfaces/dcmstack.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
)
2323
import nibabel as nb
2424
from nipype.interfaces.traits_extension import isdefined, Undefined
25+
import imghdr
2526

2627
have_dcmstack = True
2728
try:
@@ -83,6 +84,9 @@ class DcmStackInputSpec(NiftiGeneratorBaseInputSpec):
8384
"any default exclude filters")
8485
include_regexes = traits.List(desc="Meta data to include, overriding any "
8586
"exclude filters")
87+
force_read = traits.Bool(True, usedefault=True,
88+
desc=('Force reading files without DICM marker'))
89+
8690

8791
class DcmStackOutputSpec(TraitedSpec):
8892
out_file = File(exists=True)
@@ -125,8 +129,9 @@ def _run_interface(self, runtime):
125129
include_regexes)
126130
stack = dcmstack.DicomStack(meta_filter=meta_filter)
127131
for src_path in src_paths:
128-
src_dcm = dicom.read_file(src_path, force=True)
129-
stack.add_dcm(src_dcm)
132+
if not imghdr.what(src_path)=="gif":
133+
src_dcm = dicom.read_file(src_path, force=self.inputs.force_read)
134+
stack.add_dcm(src_dcm)
130135
nii = stack.to_nifti(embed_meta=True)
131136
nw = NiftiWrapper(nii)
132137
self.out_path = \

nipype/interfaces/fsl/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
Complex, InvWarp, WarpUtils, ConvertWarp, WarpPoints, WarpPointsToStd)
2020

2121
from .epi import (PrepareFieldmap, TOPUP, ApplyTOPUP, Eddy, EPIDeWarp,
22-
SigLoss, EddyCorrect)
22+
SigLoss, EddyCorrect, EpiReg)
2323

2424
from .dti import (BEDPOSTX, DTIFit, ProbTrackX, ProbTrackX2,
2525
VecReg, ProjThresh, FindTheBiggest, DistanceMap,

nipype/interfaces/fsl/epi.py

Lines changed: 124 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class PrepareFieldmapInputSpec(FSLCommandInputSpec):
4646
usedefault=True,
4747
desc=('do not perform sanity checks for image '
4848
'size/range/dimensions'))
49-
out_fieldmap = File(argstr='%s', position=5,
49+
out_fieldmap = File(argstr='%s', position=4,
5050
desc='output name for prepared fieldmap')
5151

5252

@@ -534,6 +534,129 @@ def _gen_filename(self, name):
534534
return self._list_outputs()['out_file']
535535
return None
536536

537+
538+
class EpiRegInputSpec(FSLCommandInputSpec):
539+
epi = File(exists=True, argstr='--epi=%s', mandatory=True,
540+
position=-4, desc='EPI image')
541+
t1_head = File(exists=True, argstr='--t1=%s', mandatory=True,
542+
position=-3, desc='wholehead T1 image')
543+
t1_brain = File(exists=True, argstr='--t1brain=%s', mandatory=True,
544+
position=-2, desc='brain extracted T1 image')
545+
out_base = traits.String(desc='output base name', argstr='--out=%s',
546+
position=-1)
547+
fmap = File(exists=True, argstr='--fmap=%s',
548+
desc='fieldmap image (in rad/s)')
549+
fmapmag = File(exists=True, argstr='--fmapmag=%s',
550+
desc='fieldmap magnitude image - wholehead')
551+
fmapmagbrain = File(exists=True, argstr='--fmapmagbrain=%s',
552+
desc='fieldmap magnitude image - brain extracted')
553+
wmseg = File(exists=True, argstr='--wmseg=%s',
554+
desc='white matter segmentation of T1 image, has to be named \
555+
like the t1brain and end on _wmseg')
556+
echospacing = traits.Float(argstr='--echospacing=%f',
557+
desc='Effective EPI echo spacing \
558+
(sometimes called dwell time) - in seconds')
559+
pedir = traits.Enum('x', 'y', 'z', '-x', '-y', '-z', argstr='--pedir=%s',
560+
desc='phase encoding direction, dir = x/y/z/-x/-y/-z')
561+
562+
weight_image = File(exists=True, argstr='--weight=%s',
563+
desc='weighting image (in T1 space)')
564+
no_fmapreg = traits.Bool(False, argstr='--nofmapreg',
565+
desc='do not perform registration of fmap to T1 \
566+
(use if fmap already registered)')
567+
no_clean = traits.Bool(False, argstr='--noclean',
568+
desc='do not clean up intermediate files')
569+
570+
571+
class EpiRegOutputSpec(TraitedSpec):
572+
out_file = File(exists=True,
573+
desc='unwarped and coregistered epi input')
574+
out_1vol = File(exists=True,
575+
desc='unwarped and coregistered single volume')
576+
fmap2str_mat = File(exists=True,
577+
desc='rigid fieldmap-to-structural transform')
578+
fmap2epi_mat = File(exists=True,
579+
desc='rigid fieldmap-to-epi transform')
580+
fmap_epi = File(exists=True, desc='fieldmap in epi space')
581+
fmap_str = File(exists=True, desc='fieldmap in structural space')
582+
fmapmag_str = File(exists=True,
583+
desc='fieldmap magnitude image in structural space')
584+
epi2str_inv = File(exists=True,
585+
desc='rigid structural-to-epi transform')
586+
epi2str_mat = File(exists=True,
587+
desc='rigid epi-to-structural transform')
588+
shiftmap = File(exists=True, desc='shiftmap in epi space')
589+
fullwarp = File(exists=True,
590+
desc='warpfield to unwarp epi and transform into \
591+
structural space')
592+
wmseg = File(exists=True, desc='white matter segmentation used in flirt bbr')
593+
wmedge = File(exists=True, desc='white matter edges for visualization')
594+
595+
596+
class EpiReg(FSLCommand):
597+
"""
598+
599+
Runs FSL epi_reg script for simultaneous coregistration and fieldmap
600+
unwarping.
601+
602+
Examples
603+
--------
604+
605+
>>> from nipype.interfaces.fsl import EpiReg
606+
>>> epireg = EpiReg()
607+
>>> epireg.inputs.epi='epi.nii'
608+
>>> epireg.inputs.t1_head='T1.nii'
609+
>>> epireg.inputs.t1_brain='T1_brain.nii'
610+
>>> epireg.inputs.out_base='epi2struct'
611+
>>> epireg.inputs.fmap='fieldmap_phase_fslprepared.nii'
612+
>>> epireg.inputs.fmapmag='fieldmap_mag.nii'
613+
>>> epireg.inputs.fmapmagbrain='fieldmap_mag_brain.nii'
614+
>>> epireg.inputs.echospacing=0.00067
615+
>>> epireg.inputs.pedir='y'
616+
>>> epireg.cmdline #doctest: +ELLIPSIS
617+
'epi_reg --echospacing=0.000670 --fmap=fieldmap_phase_fslprepared.nii \
618+
--fmapmag=fieldmap_mag.nii --fmapmagbrain=fieldmap_mag_brain.nii --pedir=y \
619+
--epi=epi.nii --t1=T1.nii --t1brain=T1_brain.nii --out=epi2struct'
620+
>>> epireg.run() # doctest: +SKIP
621+
622+
"""
623+
_cmd = 'epi_reg'
624+
input_spec = EpiRegInputSpec
625+
output_spec = EpiRegOutputSpec
626+
627+
def _list_outputs(self):
628+
outputs = self.output_spec().get()
629+
outputs['out_file'] = os.path.join(os.getcwd(),
630+
self.inputs.out_base + '.nii.gz')
631+
outputs['out_1vol'] = os.path.join(os.getcwd(),
632+
self.inputs.out_base + '_1vol.nii.gz')
633+
outputs['fmap2str_mat'] = os.path.join(os.getcwd(),
634+
self.inputs.out_base + '_fieldmap2str.mat')
635+
outputs['fmap2epi_mat'] = os.path.join(os.getcwd(),
636+
self.inputs.out_base + '_fieldmaprads2epi.mat')
637+
outputs['fmap_epi'] = os.path.join(os.getcwd(),
638+
self.inputs.out_base + '_fieldmaprads2epi.nii.gz')
639+
outputs['fmap_str'] = os.path.join(os.getcwd(),
640+
self.inputs.out_base + '_fieldmaprads2str.nii.gz')
641+
outputs['fmapmag_str'] = os.path.join(os.getcwd(),
642+
self.inputs.out_base + '_fieldmap2str.nii.gz')
643+
outputs['epi2str_inv'] = os.path.join(os.getcwd(),
644+
self.inputs.out_base + '_inv.mat')
645+
outputs['epi2str_mat'] = os.path.join(os.getcwd(),
646+
self.inputs.out_base + '.mat')
647+
outputs['shiftmap'] = os.path.join(os.getcwd(),
648+
self.inputs.out_base + '_fieldmaprads2epi_shift.nii.gz')
649+
outputs['fullwarp'] = os.path.join(os.getcwd(),
650+
self.inputs.out_base + '_warp.nii.gz')
651+
outputs['wmedge'] = os.path.join(os.getcwd(),
652+
self.inputs.out_base + '_fast_wmedge.nii.gz')
653+
outputs['wmseg'] = os.path.join(os.getcwd(),
654+
self.inputs.out_base + '_fast_wmseg.nii.gz')
655+
656+
return outputs
657+
658+
659+
537660
#######################################
538661
# deprecated interfaces
539662
#######################################

nipype/interfaces/fsl/preprocess.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,10 +471,12 @@ class FLIRTInputSpec(FSLCommandInputSpec):
471471
desc='do not use blurring on downsampling')
472472
rigid2D = traits.Bool(argstr='-2D',
473473
desc='use 2D rigid body mode - ignores dof')
474-
475474
save_log = traits.Bool(desc='save to log file')
476475
verbose = traits.Int(argstr='-verbose %d',
477476
desc='verbose mode, 0 is least')
477+
bgvalue = traits.Float(0, argstr='-setbackground %f',
478+
desc=('use specified background value for points '
479+
'outside FOV'))
478480

479481
# BBR options
480482
wm_seg = File(

nipype/interfaces/fsl/tests/test_auto_ApplyXfm.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ def test_ApplyXfm_inputs():
2020
bbrtype=dict(argstr='-bbrtype %s',
2121
min_ver='5.0.0',
2222
),
23+
bgvalue=dict(argstr='-setbackground %f',
24+
),
2325
bins=dict(argstr='-bins %d',
2426
),
2527
coarse_search=dict(argstr='-coarsesearch %d',
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT
2+
from nipype.testing import assert_equal
3+
from nipype.interfaces.fsl.epi import EpiReg
4+
5+
def test_EpiReg_inputs():
6+
input_map = dict(args=dict(argstr='%s',
7+
),
8+
echospacing=dict(argstr='--echospacing=%f',
9+
),
10+
environ=dict(nohash=True,
11+
usedefault=True,
12+
),
13+
epi=dict(argstr='--epi=%s',
14+
mandatory=True,
15+
position=-4,
16+
),
17+
fmap=dict(argstr='--fmap=%s',
18+
),
19+
fmapmag=dict(argstr='--fmapmag=%s',
20+
),
21+
fmapmagbrain=dict(argstr='--fmapmagbrain=%s',
22+
),
23+
ignore_exception=dict(nohash=True,
24+
usedefault=True,
25+
),
26+
no_clean=dict(argstr='--noclean',
27+
),
28+
no_fmapreg=dict(argstr='--nofmapreg',
29+
),
30+
out_base=dict(argstr='--out=%s',
31+
position=-1,
32+
),
33+
output_type=dict(),
34+
pedir=dict(argstr='--pedir=%s',
35+
),
36+
t1_brain=dict(argstr='--t1brain=%s',
37+
mandatory=True,
38+
position=-2,
39+
),
40+
t1_head=dict(argstr='--t1=%s',
41+
mandatory=True,
42+
position=-3,
43+
),
44+
terminal_output=dict(mandatory=True,
45+
nohash=True,
46+
),
47+
weight_image=dict(argstr='--weight=%s',
48+
),
49+
wmseg=dict(argstr='--wmseg=%s',
50+
),
51+
)
52+
inputs = EpiReg.input_spec()
53+
54+
for key, metadata in input_map.items():
55+
for metakey, value in metadata.items():
56+
yield assert_equal, getattr(inputs.traits()[key], metakey), value
57+
58+
def test_EpiReg_outputs():
59+
output_map = dict(epi2str_inv=dict(),
60+
epi2str_mat=dict(),
61+
fmap2epi_mat=dict(),
62+
fmap2str_mat=dict(),
63+
fmap_epi=dict(),
64+
fmap_str=dict(),
65+
fmapmag_str=dict(),
66+
fullwarp=dict(),
67+
out_1vol=dict(),
68+
out_file=dict(),
69+
shiftmap=dict(),
70+
wmedge=dict(),
71+
wmseg=dict(),
72+
)
73+
outputs = EpiReg.output_spec()
74+
75+
for key, metadata in output_map.items():
76+
for metakey, value in metadata.items():
77+
yield assert_equal, getattr(outputs.traits()[key], metakey), value
78+

nipype/interfaces/fsl/tests/test_auto_FLIRT.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ def test_FLIRT_inputs():
1919
bbrtype=dict(argstr='-bbrtype %s',
2020
min_ver='5.0.0',
2121
),
22+
bgvalue=dict(argstr='-setbackground %f',
23+
),
2224
bins=dict(argstr='-bins %d',
2325
),
2426
coarse_search=dict(argstr='-coarsesearch %d',

nipype/interfaces/fsl/tests/test_auto_PrepareFieldmap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def test_PrepareFieldmap_inputs():
2929
usedefault=True,
3030
),
3131
out_fieldmap=dict(argstr='%s',
32-
position=5,
32+
position=4,
3333
),
3434
output_type=dict(),
3535
scanner=dict(argstr='%s',

nipype/interfaces/tests/test_auto_DcmStack.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ def test_DcmStack_inputs():
77
),
88
embed_meta=dict(),
99
exclude_regexes=dict(),
10+
force_read=dict(usedefault=True,
11+
),
1012
include_regexes=dict(),
1113
out_ext=dict(usedefault=True,
1214
),

0 commit comments

Comments
 (0)