Skip to content

Commit 157a21f

Browse files
committed
Merge branch 'master' into enh_add_average_error_2_errormap
2 parents ba11e7c + 66ba90b commit 157a21f

35 files changed

+896
-179
lines changed

CHANGES

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
Next release
22
============
33

4+
* BUG: matplotlib is supposed to be optional (https://github.com/nipy/nipype/pull/1003)
5+
* FIX: Fix split_filename behaviour when path has no file component (https://github.com/nipy/nipype/pull/1035)
6+
* ENH: Updated FSL dtifit to include option for grad non-linearities (https://github.com/nipy/nipype/pull/1032)
7+
* ENH: Updated Camino tracking interfaces, which can now use FSL bedpostx output.
8+
New options also include choice of tracker, interpolator, stepsize and
9+
curveinterval for angle threshold (https://github.com/nipy/nipype/pull/1029)
10+
* FIX: Interfaces redirecting X crashed if $DISPLAY not defined (https://github.com/nipy/nipype/pull/1027)
11+
* FIX: Bug crashed 'make api' (https://github.com/nipy/nipype/pull/1026)
12+
* ENH: Updated antsIntroduction to handle RA and RI registrations (https://github.com/nipy/nipype/pull/1009)
413
* ENH: Updated N4BiasCorrection input spec to include weight image and spline order. Made
514
argument formatting consistent. Cleaned ants.segmentation according to PEP8.
615
(https://github.com/nipy/nipype/pull/990/files)
@@ -10,6 +19,9 @@ Next release
1019
* ENH: Resting state fMRI example with NiPy realignment and no SPM (https://github.com/nipy/nipype/pull/992)
1120
* FIX: Corrected Freesurfer SegStats _list_outputs to avoid error if summary_file is
1221
undefined (issue #994)(https://https://github.com/nipy/nipype/pull/996)
22+
* FIX: OpenfMRI support and FSL 5.0.7 changes (https://github.com/nipy/nipype/pull/1006)
23+
* FIX: Output prefix in SPM Normalize with modulation (https://github.com/nipy/nipype/pull/1023)
24+
* ENH: Usability improvements in cluster environments (https://github.com/nipy/nipype/pull/1025)
1325

1426
Release 0.10.0 (October 10, 2014)
1527
============

doc/devel/software_using_nipype.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ Forward
2828

2929
`Forward <http://cyclotronresearchcentre.github.io/forward/>`_ is set of tools simplifying the preparation of accurate electromagnetic head models for EEG forward modeling. It uses Nipype Workflows and Interfaces.
3030

31+
Limbo
32+
-----
33+
34+
`Limbo <https://github.com/Gilles86/in_limbo>`_ is a toolbox for finding brain regions that are neither significantly active nor inactive, but rather “in limbo”. It was build using custom Nipype Interfaces and Workflows.
35+
3136
Lyman
3237
-----
3338

@@ -38,6 +43,11 @@ Medimsight
3843

3944
`Medimsight <https://www.medimsight.com>`_ is a commercial service medical imaging cloud platform. It uses Nipype to interface with various neuroimaging software.
4045

46+
MIA
47+
---
48+
49+
`MIA <http://mia.sourceforge.net>`_ MIA is a a toolkit for gray scale medical image analysis. It provides Nipype interfaces for easy integration with other software.
50+
4151
Mindboggle
4252
----------
4353

doc/users/config_file.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ Execution
120120
characters will be replaced by their hash. (possible values: ``true`` and
121121
``false``; default value: ``true``)
122122

123+
*poll_sleep_duration*
124+
This controls how long the job submission loop will sleep between submitting
125+
all pending jobs and checking for job completion. To be nice to cluster
126+
schedulers the default is set to 60 seconds.
127+
123128
Example
124129
~~~~~~~
125130

examples/fmri_ants_openfmri.py

Lines changed: 92 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
from nipype import config
1616
config.enable_provenance()
17-
from nipype.external import six
1817

18+
from nipype.external import six
1919

2020
from glob import glob
2121
import os
@@ -174,8 +174,8 @@ def create_reg_workflow(name='registration'):
174174
reg.inputs.winsorize_upper_quantile = 0.995
175175
reg.inputs.args = '--float'
176176
reg.inputs.output_warped_image = 'output_warped_image.nii.gz'
177-
reg.inputs.num_threads = 4
178-
reg.plugin_args = {'qsub_args': '-l nodes=1:ppn=4'}
177+
reg.inputs.num_threads = 2
178+
reg.plugin_args = {'qsub_args': '-pe orte 2'}
179179
register.connect(stripper, 'out_file', reg, 'moving_image')
180180
register.connect(inputnode,'target_image_brain', reg,'fixed_image')
181181

@@ -284,12 +284,13 @@ def get_subjectinfo(subject_id, base_dir, task_id, model_id):
284284
for idx in range(n_tasks):
285285
taskidx = np.where(taskinfo[:, 0] == 'task%03d' % (idx + 1))
286286
conds.append([condition.replace(' ', '_') for condition
287-
in taskinfo[taskidx[0], 2]])
288-
files = glob(os.path.join(base_dir,
289-
subject_id,
290-
'BOLD',
291-
'task%03d_run*' % (idx + 1)))
292-
run_ids.insert(idx, range(1, len(files) + 1))
287+
in taskinfo[taskidx[0], 2]]) # if 'junk' not in condition])
288+
files = sorted(glob(os.path.join(base_dir,
289+
subject_id,
290+
'BOLD',
291+
'task%03d_run*' % (idx + 1))))
292+
runs = [int(val[-3:]) for val in files]
293+
run_ids.insert(idx, runs)
293294
TR = np.genfromtxt(os.path.join(base_dir, 'scan_key.txt'))[1]
294295
return run_ids[task_id - 1], conds[task_id - 1], TR
295296

@@ -361,25 +362,45 @@ def analyze_openfmri_dataset(data_dir, subject=None, model_id=None,
361362
"""
362363
Return data components as anat, bold and behav
363364
"""
364-
365-
datasource = pe.Node(nio.DataGrabber(infields=['subject_id', 'run_id',
365+
contrast_file = os.path.join(data_dir, 'models', 'model%03d' % model_id,
366+
'task_contrasts.txt')
367+
has_contrast = os.path.exists(contrast_file)
368+
if has_contrast:
369+
datasource = pe.Node(nio.DataGrabber(infields=['subject_id', 'run_id',
366370
'task_id', 'model_id'],
367371
outfields=['anat', 'bold', 'behav',
368372
'contrasts']),
369373
name='datasource')
374+
else:
375+
datasource = pe.Node(nio.DataGrabber(infields=['subject_id', 'run_id',
376+
'task_id', 'model_id'],
377+
outfields=['anat', 'bold', 'behav']),
378+
name='datasource')
370379
datasource.inputs.base_directory = data_dir
371380
datasource.inputs.template = '*'
372-
datasource.inputs.field_template = {'anat': '%s/anatomy/highres001.nii.gz',
373-
'bold': '%s/BOLD/task%03d_r*/bold.nii.gz',
374-
'behav': ('%s/model/model%03d/onsets/task%03d_'
375-
'run%03d/cond*.txt'),
376-
'contrasts': ('models/model%03d/'
377-
'task_contrasts.txt')}
378-
datasource.inputs.template_args = {'anat': [['subject_id']],
381+
382+
if has_contrast:
383+
datasource.inputs.field_template = {'anat': '%s/anatomy/highres001.nii.gz',
384+
'bold': '%s/BOLD/task%03d_r*/bold.nii.gz',
385+
'behav': ('%s/model/model%03d/onsets/task%03d_'
386+
'run%03d/cond*.txt'),
387+
'contrasts': ('models/model%03d/'
388+
'task_contrasts.txt')}
389+
datasource.inputs.template_args = {'anat': [['subject_id']],
379390
'bold': [['subject_id', 'task_id']],
380391
'behav': [['subject_id', 'model_id',
381392
'task_id', 'run_id']],
382393
'contrasts': [['model_id']]}
394+
else:
395+
datasource.inputs.field_template = {'anat': '%s/anatomy/highres001.nii.gz',
396+
'bold': '%s/BOLD/task%03d_r*/bold.nii.gz',
397+
'behav': ('%s/model/model%03d/onsets/task%03d_'
398+
'run%03d/cond*.txt')}
399+
datasource.inputs.template_args = {'anat': [['subject_id']],
400+
'bold': [['subject_id', 'task_id']],
401+
'behav': [['subject_id', 'model_id',
402+
'task_id', 'run_id']]}
403+
383404
datasource.inputs.sort_filelist = True
384405

385406
"""
@@ -412,9 +433,11 @@ def get_highpass(TR, hpcutoff):
412433

413434
def get_contrasts(contrast_file, task_id, conds):
414435
import numpy as np
415-
contrast_def = np.genfromtxt(contrast_file, dtype=object)
416-
if len(contrast_def.shape) == 1:
417-
contrast_def = contrast_def[None, :]
436+
import os
437+
contrast_def = []
438+
if os.path.exists(contrast_file):
439+
with open(contrast_file, 'rt') as fp:
440+
contrast_def.extend([np.array(row.split()) for row in fp.readlines() if row.strip()])
418441
contrasts = []
419442
for row in contrast_def:
420443
if row[0] != 'task%03d' % task_id:
@@ -448,22 +471,33 @@ def get_contrasts(contrast_file, task_id, conds):
448471
name="modelspec")
449472
modelspec.inputs.input_units = 'secs'
450473

451-
def check_behav_list(behav):
452-
out_behav = []
474+
def check_behav_list(behav, run_id, conds):
475+
from nipype.external import six
476+
import numpy as np
477+
num_conds = len(conds)
453478
if isinstance(behav, six.string_types):
454479
behav = [behav]
455-
for val in behav:
456-
if not isinstance(val, list):
457-
out_behav.append([val])
458-
else:
459-
out_behav.append(val)
460-
return out_behav
480+
behav_array = np.array(behav).flatten()
481+
num_elements = behav_array.shape[0]
482+
return behav_array.reshape(num_elements/num_conds, num_conds).tolist()
483+
484+
reshape_behav = pe.Node(niu.Function(input_names=['behav', 'run_id', 'conds'],
485+
output_names=['behav'],
486+
function=check_behav_list),
487+
name='reshape_behav')
461488

462489
wf.connect(subjinfo, 'TR', modelspec, 'time_repetition')
463-
wf.connect(datasource, ('behav', check_behav_list), modelspec, 'event_files')
490+
wf.connect(datasource, 'behav', reshape_behav, 'behav')
491+
wf.connect(subjinfo, 'run_id', reshape_behav, 'run_id')
492+
wf.connect(subjinfo, 'conds', reshape_behav, 'conds')
493+
wf.connect(reshape_behav, 'behav', modelspec, 'event_files')
494+
464495
wf.connect(subjinfo, 'TR', modelfit, 'inputspec.interscan_interval')
465496
wf.connect(subjinfo, 'conds', contrastgen, 'conds')
466-
wf.connect(datasource, 'contrasts', contrastgen, 'contrast_file')
497+
if has_contrast:
498+
wf.connect(datasource, 'contrasts', contrastgen, 'contrast_file')
499+
else:
500+
contrastgen.inputs.contrast_file = ''
467501
wf.connect(infosource, 'task_id', contrastgen, 'task_id')
468502
wf.connect(contrastgen, 'contrasts', modelfit, 'inputspec.contrasts')
469503

@@ -487,32 +521,39 @@ def check_behav_list(behav):
487521
Reorder the copes so that now it combines across runs
488522
"""
489523

490-
def sort_copes(files):
491-
numelements = len(files[0])
492-
outfiles = []
493-
for i in range(numelements):
494-
outfiles.insert(i, [])
495-
for j, elements in enumerate(files):
496-
outfiles[i].append(elements[i])
497-
return outfiles
498-
499-
def num_copes(files):
500-
return len(files)
524+
def sort_copes(copes, varcopes, contrasts):
525+
import numpy as np
526+
if not isinstance(copes, list):
527+
copes = [copes]
528+
varcopes = [varcopes]
529+
num_copes = len(contrasts)
530+
n_runs = len(copes)
531+
all_copes = np.array(copes).flatten()
532+
all_varcopes = np.array(varcopes).flatten()
533+
outcopes = all_copes.reshape(len(all_copes)/num_copes, num_copes).T.tolist()
534+
outvarcopes = all_varcopes.reshape(len(all_varcopes)/num_copes, num_copes).T.tolist()
535+
return outcopes, outvarcopes, n_runs
536+
537+
cope_sorter = pe.Node(niu.Function(input_names=['copes', 'varcopes',
538+
'contrasts'],
539+
output_names=['copes', 'varcopes',
540+
'n_runs'],
541+
function=sort_copes),
542+
name='cope_sorter')
501543

502544
pickfirst = lambda x: x[0]
503545

546+
wf.connect(contrastgen, 'contrasts', cope_sorter, 'contrasts')
504547
wf.connect([(preproc, fixed_fx, [(('outputspec.mask', pickfirst),
505548
'flameo.mask_file')]),
506-
(modelfit, fixed_fx, [(('outputspec.copes', sort_copes),
507-
'inputspec.copes'),
508-
('outputspec.dof_file',
549+
(modelfit, cope_sorter, [('outputspec.copes', 'copes')]),
550+
(modelfit, cope_sorter, [('outputspec.varcopes', 'varcopes')]),
551+
(cope_sorter, fixed_fx, [('copes', 'inputspec.copes'),
552+
('varcopes', 'inputspec.varcopes'),
553+
('n_runs', 'l2model.num_copes')]),
554+
(modelfit, fixed_fx, [('outputspec.dof_file',
509555
'inputspec.dof_files'),
510-
(('outputspec.varcopes',
511-
sort_copes),
512-
'inputspec.varcopes'),
513-
(('outputspec.copes', num_copes),
514-
'l2model.num_copes'),
515-
])
556+
])
516557
])
517558

518559
wf.connect(preproc, 'outputspec.mean', registration, 'inputspec.mean_image')

examples/rsfmri_vol_surface_preprocessing_nipy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,7 @@ def create_resting_workflow(args, name=None):
945945
if args.dicom_file:
946946
TR, slice_times, slice_thickness = get_info(args.dicom_file)
947947
slice_times = (np.array(slice_times)/1000.).tolist()
948-
948+
949949
if name is None:
950950
name = 'resting_' + args.subject_id
951951
kwargs = dict(files=[os.path.abspath(filename) for filename in args.files],
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT
2+
from nipype.testing import assert_equal
3+
from nipype.algorithms.misc import Overlap
4+
5+
def test_Overlap_inputs():
6+
input_map = dict(bg_overlap=dict(mandatory=True,
7+
usedefault=True,
8+
),
9+
ignore_exception=dict(nohash=True,
10+
usedefault=True,
11+
),
12+
mask_volume=dict(),
13+
out_file=dict(usedefault=True,
14+
),
15+
vol_units=dict(mandatory=True,
16+
usedefault=True,
17+
),
18+
volume1=dict(mandatory=True,
19+
),
20+
volume2=dict(mandatory=True,
21+
),
22+
weighting=dict(usedefault=True,
23+
),
24+
)
25+
inputs = Overlap.input_spec()
26+
27+
for key, metadata in input_map.items():
28+
for metakey, value in metadata.items():
29+
yield assert_equal, getattr(inputs.traits()[key], metakey), value
30+
31+
def test_Overlap_outputs():
32+
output_map = dict(dice=dict(),
33+
diff_file=dict(),
34+
jaccard=dict(),
35+
labels=dict(),
36+
roi_di=dict(),
37+
roi_ji=dict(),
38+
roi_voldiff=dict(),
39+
volume_difference=dict(),
40+
)
41+
outputs = Overlap.output_spec()
42+
43+
for key, metadata in output_map.items():
44+
for metakey, value in metadata.items():
45+
yield assert_equal, getattr(outputs.traits()[key], metakey), value
46+

nipype/interfaces/ants/legacy.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,21 @@ class antsIntroduction(ANTSCommand):
9494

9595
def _list_outputs(self):
9696
outputs = self._outputs().get()
97+
transmodel = self.inputs.transformation_model
98+
99+
# When transform is set as 'RI'/'RA', wrap fields should not be expected
100+
# The default transformation is GR, which outputs the wrap fields
101+
if not isdefined(transmodel) or (isdefined(transmodel) and transmodel not in ['RI', 'RA']):
102+
outputs['warp_field'] = os.path.join(os.getcwd(),
103+
self.inputs.out_prefix +
104+
'Warp.nii.gz')
105+
outputs['inverse_warp_field'] = os.path.join(os.getcwd(),
106+
self.inputs.out_prefix +
107+
'InverseWarp.nii.gz')
97108

98109
outputs['affine_transformation'] = os.path.join(os.getcwd(),
99110
self.inputs.out_prefix +
100111
'Affine.txt')
101-
outputs['warp_field'] = os.path.join(os.getcwd(),
102-
self.inputs.out_prefix +
103-
'Warp.nii.gz')
104-
outputs['inverse_warp_field'] = os.path.join(os.getcwd(),
105-
self.inputs.out_prefix +
106-
'InverseWarp.nii.gz')
107112
outputs['input_file'] = os.path.join(os.getcwd(),
108113
self.inputs.out_prefix +
109114
'repaired.nii.gz')

nipype/interfaces/ants/segmentation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ class N4BiasFieldCorrection(ANTSCommand):
268268
269269
Examples
270270
--------
271-
271+
272272
>>> import copy
273273
>>> from nipype.interfaces.ants import N4BiasFieldCorrection
274274
>>> n4 = N4BiasFieldCorrection()
@@ -327,14 +327,14 @@ def _format_arg(self, name, trait_spec, value):
327327
output = self._gen_filename('output_image')
328328
newval = '[ %s, %s ]' % (output, bias_image)
329329
return trait_spec.argstr % newval
330-
330+
331331
if name == 'bspline_fitting_distance':
332332
if isdefined(self.inputs.bspline_order):
333333
newval = '[ %g, %d ]' % (value, self.inputs.bspline_order)
334334
else:
335335
newval = '[ %g ]' % value
336336
return trait_spec.argstr % newval
337-
337+
338338
if ((name == 'n_iterations') and
339339
(isdefined(self.inputs.convergence_threshold))):
340340
newval = '[ %s, %g ]' % ('x'.join([str(elt) for elt in value]),

0 commit comments

Comments
 (0)