2
2
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
3
3
# vi: set ft=python sts=4 ts=4 sw=4 et:
4
4
""" Set of interfaces that allow interaction with BIDS data. Currently
5
- available interfaces are:
5
+ available interfaces are:
6
6
7
- BIDSDataGrabber: Query data from BIDS dataset using pybids grabbids.
7
+ BIDSDataGrabber: Query data from BIDS dataset using pybids grabbids.
8
8
9
- Change directory to provide relative paths for doctests
10
- >>> import os
11
- >>> import bids
12
- >>> filepath = os.path.realpath(os.path.dirname(bids.__file__))
13
- >>> datadir = os.path.realpath(os.path.join(filepath, 'grabbids/tests/data/'))
14
- >>> os.chdir(datadir)
9
+ Change directory to provide relative paths for doctests
10
+ >>> import os
11
+ >>> import bids
12
+ >>> filepath = os.path.realpath(os.path.dirname(bids.__file__))
13
+ >>> datadir = os.path.realpath(os.path.join(filepath, 'grabbids/tests/data/'))
14
+ >>> os.chdir(datadir)
15
15
16
16
"""
17
17
18
18
from .base import (traits ,
19
19
DynamicTraitedSpec ,
20
+ Directory ,
20
21
BaseInterface ,
21
22
isdefined ,
22
23
Str ,
32
33
from warnings import warn
33
34
34
35
class BIDSDataGrabberInputSpec (DynamicTraitedSpec ):
35
- base_dir = traits . Directory (exists = True ,
36
- desc = 'Path to BIDS Directory.' ,
37
- mandatory = True )
36
+ base_dir = Directory (exists = True ,
37
+ desc = 'Path to BIDS Directory.' ,
38
+ mandatory = True )
38
39
output_query = traits .Dict (key_trait = Str ,
39
40
value_trait = traits .Dict ,
40
41
desc = 'Queries for outfield outputs' )
@@ -47,49 +48,49 @@ class BIDSDataGrabberInputSpec(DynamicTraitedSpec):
47
48
class BIDSDataGrabber (BaseInterface ):
48
49
49
50
""" BIDS datagrabber module that wraps around pybids to allow arbitrary
50
- querying of BIDS datasets.
51
-
52
- Examples
53
- --------
54
-
55
- >>> from nipype.interfaces.bids import BIDSDataGrabber
56
- >>> from os.path import basename
57
- >>> import pprint
58
-
59
- Select all files from a BIDS project
60
-
61
- >>> bg = BIDSDataGrabber()
62
- >>> bg.inputs.base_dir = 'ds005/'
63
- >>> results = bg.run()
64
- >>> len(results.outputs.outfield) # doctest: +ALLOW_UNICODE
65
- 135
66
-
67
- Using dynamically created, user-defined input fields,
68
- filter files based on BIDS entities.
69
-
70
- >>> bg = BIDSDataGrabber(infields = ['subject', 'run'])
71
- >>> bg.inputs.base_dir = 'ds005/'
72
- >>> bg.inputs.subject = '01'
73
- >>> bg.inputs.run = '01'
74
- >>> results = bg.run()
75
- >>> basename(results.outputs.outfield[0]) # doctest: +ALLOW_UNICODE
76
- 'sub-01_task-mixedgamblestask_run-01_bold.nii.gz'
77
-
78
- Using user-defined output fields, return different types of outputs,
79
- filtered on common entities
80
- filter files based on BIDS entities.
81
-
82
- >>> bg = BIDSDataGrabber(infields = ['subject'], outfields = ['func', 'anat'])
83
- >>> bg.inputs.base_dir = 'ds005/'
84
- >>> bg.inputs.subject = '01'
85
- >>> bg.inputs.output_query['func'] = dict(modality='func')
86
- >>> bg.inputs.output_query['anat'] = dict(modality='anat')
87
- >>> results = bg.run()
88
- >>> basename(results.outputs.func[0]) # doctest: +ALLOW_UNICODE
89
- 'sub-01_task-mixedgamblestask_run-01_bold.nii.gz'
90
-
91
- >>> basename(results.outputs.anat[0]) # doctest: +ALLOW_UNICODE
92
- 'sub-01_T1w.nii.gz'
51
+ querying of BIDS datasets.
52
+
53
+ Examples
54
+ --------
55
+
56
+ >>> from nipype.interfaces.bids import BIDSDataGrabber
57
+ >>> from os.path import basename
58
+ >>> import pprint
59
+
60
+ Select all files from a BIDS project
61
+
62
+ >>> bg = BIDSDataGrabber()
63
+ >>> bg.inputs.base_dir = 'ds005/'
64
+ >>> results = bg.run()
65
+ >>> len(results.outputs.outfield) # doctest: +ALLOW_UNICODE
66
+ 135
67
+
68
+ Using dynamically created, user-defined input fields,
69
+ filter files based on BIDS entities.
70
+
71
+ >>> bg = BIDSDataGrabber(infields = ['subject', 'run'])
72
+ >>> bg.inputs.base_dir = 'ds005/'
73
+ >>> bg.inputs.subject = '01'
74
+ >>> bg.inputs.run = '01'
75
+ >>> results = bg.run()
76
+ >>> basename(results.outputs.outfield[0]) # doctest: +ALLOW_UNICODE
77
+ 'sub-01_task-mixedgamblestask_run-01_bold.nii.gz'
78
+
79
+ Using user-defined output fields, return different types of outputs,
80
+ filtered on common entities
81
+ filter files based on BIDS entities.
82
+
83
+ >>> bg = BIDSDataGrabber(infields = ['subject'], outfields = ['func', 'anat'])
84
+ >>> bg.inputs.base_dir = 'ds005/'
85
+ >>> bg.inputs.subject = '01'
86
+ >>> bg.inputs.output_query['func'] = dict(modality='func')
87
+ >>> bg.inputs.output_query['anat'] = dict(modality='anat')
88
+ >>> results = bg.run()
89
+ >>> basename(results.outputs.func[0]) # doctest: +ALLOW_UNICODE
90
+ 'sub-01_task-mixedgamblestask_run-01_bold.nii.gz'
91
+
92
+ >>> basename(results.outputs.anat[0]) # doctest: +ALLOW_UNICODE
93
+ 'sub-01_T1w.nii.gz'
93
94
"""
94
95
input_spec = BIDSDataGrabberInputSpec
95
96
output_spec = DynamicTraitedSpec
0 commit comments