Skip to content

Commit 306f786

Browse files
committed
DOC: Improve docstring for DataFinder, include example usage.
1 parent ee961a3 commit 306f786

File tree

1 file changed

+38
-7
lines changed

1 file changed

+38
-7
lines changed

nipype/interfaces/io.py

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -572,14 +572,45 @@ class DataFinderInputSpec(DynamicTraitedSpec, BaseInterfaceInputSpec):
572572

573573

574574
class DataFinder(IOBase):
575-
"""Search for paths that match a given regular expression. Matched
576-
paths are available in the output 'out_paths'. Any named groups of
577-
captured text from the regular expression are also available as
578-
ouputs of the same name.
575+
"""Search for paths that match a given regular expression. Allows a less
576+
proscriptive approach to gathering input files compared to DataGrabber.
577+
Will recursively search any subdirectories by default. This can be limited
578+
with the min/max depth options.
579579
580-
Will recursively search any subdirectories by default. This can be
581-
limited with the min/max depth options. Named groups of text
582-
captured by the regular expression will also be output dynamically.
580+
Matched paths are available in the output 'out_paths'. Any named groups of
581+
captured text from the regular expression are also available as ouputs of
582+
the same name.
583+
584+
Examples
585+
--------
586+
587+
>>> from nipype.interfaces.io import DataFinder
588+
589+
Look for Nifti files in directories with "ep2d_fid" or "qT1" in the name,
590+
starting in the current directory.
591+
592+
>>> df = DataFinder()
593+
>>> df.inputs.root_paths = '.'
594+
>>> df.inputs.match_regex = '.+/(?P<series_dir>.+(qT1|ep2d_fid_T1).+)/(?P<basename>.+)\.nii.gz'
595+
>>> result = df.run()
596+
>>> print result.outputs.out_paths
597+
['./027-ep2d_fid_T1_Gd4/acquisition.nii.gz',
598+
'./018-ep2d_fid_T1_Gd2/acquisition.nii.gz',
599+
'./016-ep2d_fid_T1_Gd1/acquisition.nii.gz',
600+
'./013-ep2d_fid_T1_pre/acquisition.nii.gz']
601+
602+
>>> print result.outputs.series_dir
603+
['027-ep2d_fid_T1_Gd4',
604+
'018-ep2d_fid_T1_Gd2',
605+
'016-ep2d_fid_T1_Gd1',
606+
'013-ep2d_fid_T1_pre']
607+
608+
>>> print result.outputs.basename
609+
['acquisition',
610+
'acquisition',
611+
'acquisition',
612+
'acquisition']
613+
583614
"""
584615

585616
input_spec = DataFinderInputSpec

0 commit comments

Comments
 (0)