-
Notifications
You must be signed in to change notification settings - Fork 21
/
utils.py
153 lines (133 loc) · 3.74 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
"""Miscellaneous utility interfaces."""
from nipype import logging
from nipype.interfaces.base import (
BaseInterfaceInputSpec,
File,
OutputMultiObject,
SimpleInterface,
TraitedSpec,
Undefined,
traits,
traits_extension,
)
from xcp_d.utils.modified_data import downcast_to_32
LOGGER = logging.getLogger("nipype.interface")
class _ConvertTo32InputSpec(BaseInterfaceInputSpec):
bold_file = traits.Either(
None,
File(exists=True),
desc="BOLD file",
mandatory=False,
usedefault=True,
)
boldref = traits.Either(
None,
File(exists=True),
desc="BOLD reference file",
mandatory=False,
usedefault=True,
)
bold_mask = traits.Either(
None,
File(exists=True),
desc="BOLD mask file",
mandatory=False,
usedefault=True,
)
t1w = traits.Either(
None,
File(exists=True),
desc="T1-weighted anatomical file",
mandatory=False,
usedefault=True,
)
t2w = traits.Either(
None,
File(exists=True),
desc="T2-weighted anatomical file",
mandatory=False,
usedefault=True,
)
anat_dseg = traits.Either(
None,
File(exists=True),
desc="T1-space segmentation file",
mandatory=False,
usedefault=True,
)
class _ConvertTo32OutputSpec(TraitedSpec):
bold_file = traits.Either(
None,
File(exists=True),
desc="BOLD file",
mandatory=False,
)
boldref = traits.Either(
None,
File(exists=True),
desc="BOLD reference file",
mandatory=False,
)
bold_mask = traits.Either(
None,
File(exists=True),
desc="BOLD mask file",
mandatory=False,
)
t1w = traits.Either(
None,
File(exists=True),
desc="T1-weighted anatomical file",
mandatory=False,
)
t2w = traits.Either(
None,
File(exists=True),
desc="T2-weighted anatomical file",
mandatory=False,
)
anat_dseg = traits.Either(
None,
File(exists=True),
desc="T1-space segmentation file",
mandatory=False,
)
class ConvertTo32(SimpleInterface):
"""Downcast files from >32-bit to 32-bit if necessary."""
input_spec = _ConvertTo32InputSpec
output_spec = _ConvertTo32OutputSpec
def _run_interface(self, runtime):
self._results["bold_file"] = downcast_to_32(self.inputs.bold_file)
self._results["boldref"] = downcast_to_32(self.inputs.boldref)
self._results["bold_mask"] = downcast_to_32(self.inputs.bold_mask)
self._results["t1w"] = downcast_to_32(self.inputs.t1w)
self._results["t2w"] = downcast_to_32(self.inputs.t2w)
self._results["anat_dseg"] = downcast_to_32(self.inputs.anat_dseg)
return runtime
class _FilterUndefinedInputSpec(BaseInterfaceInputSpec):
inlist = traits.List(
traits.Either(
traits.Str,
None,
Undefined,
),
mandatory=True,
desc="List of objects to filter.",
)
class _FilterUndefinedOutputSpec(TraitedSpec):
outlist = OutputMultiObject(
traits.Str,
desc="Filtered list of objects.",
)
class FilterUndefined(SimpleInterface):
"""Extract timeseries and compute connectivity matrices."""
input_spec = _FilterUndefinedInputSpec
output_spec = _FilterUndefinedOutputSpec
def _run_interface(self, runtime):
inlist = self.inputs.inlist
outlist = []
for item in inlist:
if item is not None and traits_extension.isdefined(item):
outlist.append(item)
self._results["outlist"] = outlist
return runtime