Skip to content

Commit 486775c

Browse files
authored
Merge pull request #1774 from TheChymera/fsl_model_ortho
added support for orthogonalization
2 parents 29b4597 + d040246 commit 486775c

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

nipype/interfaces/fsl/model.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ class Level1DesignInputSpec(BaseInterfaceInputSpec):
4747
mandatory=True,
4848
desc=("name of basis function and options e.g., "
4949
"{'dgamma': {'derivs': True}}"))
50+
orthogonalization = traits.Dict(traits.Int, traits.Dict(traits.Int,
51+
traits.Either(traits.Bool,traits.Int)),
52+
mandatory=False,
53+
desc=("which regressors to make orthogonal e.g., "
54+
"{1: {0:0,1:0,2:0}, 2: {0:1,1:1,2:0}} to make the second "
55+
"regressor in a 2-regressor model orthogonal to the first."),
56+
default={})
5057
model_serial_correlations = traits.Bool(
5158
desc="Option to model serial correlations using an \
5259
autoregressive estimator (order 1). Setting this option is only \
@@ -123,8 +130,8 @@ def _create_ev_file(self, evfname, evinfo):
123130
f.close()
124131

125132
def _create_ev_files(
126-
self, cwd, runinfo, runidx, ev_parameters, contrasts,
127-
do_tempfilter, basis_key):
133+
self, cwd, runinfo, runidx, ev_parameters, orthogonalization,
134+
contrasts, do_tempfilter, basis_key):
128135
"""Creates EV files from condition and regressor information.
129136
130137
Parameters:
@@ -138,6 +145,8 @@ def _create_ev_files(
138145
ev_parameters : dict
139146
A dictionary containing the model parameters for the
140147
given design type.
148+
orthogonalization : dict
149+
A dictionary of dictionaries specifying orthogonal EVs.
141150
contrasts : list of lists
142151
Information on contrasts to be evaluated
143152
"""
@@ -208,7 +217,11 @@ def _create_ev_files(
208217
# add ev orthogonalization
209218
for i in range(1, num_evs[0] + 1):
210219
for j in range(0, num_evs[0] + 1):
211-
ev_txt += ev_ortho.substitute(c0=i, c1=j)
220+
try:
221+
orthogonal = int(orthogonalization[i][j])
222+
except (KeyError, TypeError, ValueError, IndexError):
223+
orthogonal = 0
224+
ev_txt += ev_ortho.substitute(c0=i, c1=j, orthogonal=orthogonal)
212225
ev_txt += "\n"
213226
# add contrast info to fsf file
214227
if isdefined(contrasts):
@@ -321,6 +334,7 @@ def _run_interface(self, runtime):
321334
if info['hpf'] == np.inf:
322335
do_tempfilter = 0
323336
num_evs, cond_txt = self._create_ev_files(cwd, info, i, ev_parameters,
337+
self.inputs.orthogonalization,
324338
self.inputs.contrasts,
325339
do_tempfilter, basis_key)
326340
nim = load(func_files[i])

nipype/interfaces/fsl/tests/test_Level1Design_functions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ def test_level1design():
1111
runidx = 0
1212
contrasts = Undefined
1313
do_tempfilter = False
14+
orthogonalization = {}
1415
ev_parameters = {"temporalderiv":False}
1516
for key, val in [('hrf', 3), ('dgamma', 3), ('gamma', 2), ('none', 0)]:
1617
output_num, output_txt = Level1Design._create_ev_files(l, os.getcwd(),
1718
runinfo, runidx,
1819
ev_parameters,
20+
orthogonalization,
1921
contrasts,
2022
do_tempfilter,
2123
key)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# Orthogonalise EV $c0 wrt EV $c1
2-
set fmri(ortho$c0.$c1) 0
2+
set fmri(ortho$c0.$c1) $orthogonal

0 commit comments

Comments
 (0)