Skip to content

Commit 5b6fc82

Browse files
committed
RF: update ds105 example for SPM8 batching
1 parent 0608a41 commit 5b6fc82

File tree

1 file changed

+34
-29
lines changed

1 file changed

+34
-29
lines changed

examples/interfaces/process_ds105.py

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030

3131
# The batch scripts currently need SPM5
32-
nimat.matlab_cmd = 'matlab-2007a-spm5 -nodesktop -nosplash'
32+
nimat.matlab_cmd = 'matlab-spm8 -nodesktop -nosplash'
3333

3434
# This definition is partly for slice timing. We can't do slice timing for this
3535
# dataset because the slice dimension is the first, and SPM assumes it is the
@@ -107,24 +107,26 @@ def add_ana_defaults(self, ana_def):
107107
full_ana_def['fwhm'] = 8.0
108108
return full_ana_def
109109

110-
def slicetime(self, prefix=''):
111-
sess_scans = scans_for_fnames(self.data_def['functionals'])
110+
def slicetime(self, in_prefix='', out_prefix='a'):
111+
sess_scans = scans_for_fnames(
112+
fnames_presuffix(self.data_def['functionals'], in_prefix))
112113
sdef = self.study_def
113114
stinfo = make_job('temporal', 'st', {
114115
'scans': sess_scans,
115116
'so': sdef['time_to_space'],
116117
'tr': sdef['TR'],
117118
'ta': sdef['TA'],
118119
'nslices': float(sdef['n_slices']),
119-
'refslice':1
120+
'refslice':1,
121+
'prefix': out_prefix,
120122
})
121123
run_jobdef(stinfo)
122-
return 'a' + prefix
124+
return out_prefix + in_prefix
123125

124126

125-
def realign(self, prefix=''):
127+
def realign(self, in_prefix=''):
126128
sess_scans = scans_for_fnames(
127-
fnames_presuffix(self.data_def['functionals'], prefix))
129+
fnames_presuffix(self.data_def['functionals'], in_prefix))
128130
rinfo = make_job('spatial', 'realign', [{
129131
'estimate':{
130132
'data':sess_scans,
@@ -140,9 +142,9 @@ def realign(self, prefix=''):
140142
}
141143
}])
142144
run_jobdef(rinfo)
143-
return prefix
145+
return in_prefix
144146

145-
def reslice(self, prefix='', out=('1..n', 'mean')):
147+
def reslice(self, in_prefix='', out_prefix='r', out=('1..n', 'mean')):
146148
which = [0, 0]
147149
if 'mean' in out:
148150
which[1] = 1
@@ -151,7 +153,7 @@ def reslice(self, prefix='', out=('1..n', 'mean')):
151153
elif '2..n' in out:
152154
which[0] = 1
153155
sess_scans = scans_for_fnames(
154-
fnames_presuffix(self.data_def['functionals'], prefix))
156+
fnames_presuffix(self.data_def['functionals'], in_prefix))
155157
rsinfo = make_job('spatial', 'realign', [{
156158
'write':{
157159
'data': np.vstack(sess_scans.flat),
@@ -160,20 +162,22 @@ def reslice(self, prefix='', out=('1..n', 'mean')):
160162
'interp':4.0,
161163
'wrap':[0.0,0.0,0.0],
162164
'mask':True,
165+
'prefix': out_prefix
163166
}
164167
}
165168
}])
166169
run_jobdef(rsinfo)
167-
return 'r' + prefix
170+
return out_prefix + in_prefix
168171

169-
def coregister(self, prefix=''):
172+
def coregister(self, in_prefix=''):
170173
func1 = self.data_def['functionals'][0]
171-
mean_fname = fname_presuffix(func1, 'mean' + prefix)
174+
mean_fname = fname_presuffix(func1, 'mean' + in_prefix)
172175
crinfo = make_job('spatial', 'coreg', [{
173176
'estimate':{
174-
'ref': [mean_fname],
175-
'source': [self.data_def['anatomical']],
176-
'other': [[]],
177+
'ref': np.asarray(mean_fname, dtype=object),
178+
'source': np.asarray(self.data_def['anatomical'],
179+
dtype=object),
180+
'other': [''],
177181
'eoptions':{
178182
'cost_fun':'nmi',
179183
'sep':[4.0, 2.0],
@@ -187,9 +191,9 @@ def coregister(self, prefix=''):
187191
}
188192
}])
189193
run_jobdef(crinfo)
190-
return prefix
194+
return in_prefix
191195

192-
def seg_norm(self, prefix=''):
196+
def seg_norm(self, in_prefix=''):
193197
def_tpms = np.zeros((3,1), dtype=np.object)
194198
spm_path = spm_info.spm_path
195199
def_tpms[0] = pjoin(spm_path, 'tpm', 'grey.nii'),
@@ -219,11 +223,11 @@ def seg_norm(self, prefix=''):
219223
}
220224
})
221225
run_jobdef(sninfo)
222-
return prefix
226+
return in_prefix
223227

224-
def norm_write(self, prefix=''):
228+
def norm_write(self, in_prefix='', out_prefix='w'):
225229
sess_scans = scans_for_fnames(
226-
fnames_presuffix(self.data_def['functionals'], prefix))
230+
fnames_presuffix(self.data_def['functionals'], in_prefix))
227231
matname = fname_presuffix(self.data_def['anatomical'],
228232
suffix='_seg_sn.mat',
229233
use_ext=False)
@@ -238,6 +242,7 @@ def norm_write(self, prefix=''):
238242
'vox':fltcols([2.0,2.0,2.0]),
239243
'interp':1.0,
240244
'wrap':[0.0,0.0,0.0],
245+
'prefix': out_prefix,
241246
}
242247
nwinfo = make_job('spatial', 'normalise', [{
243248
'write':{
@@ -251,23 +256,23 @@ def norm_write(self, prefix=''):
251256
subj['resample'][0] = self.data_def['anatomical']
252257
roptions['interp'] = 4.0
253258
run_jobdef(nwinfo)
254-
return 'w' + prefix
259+
return out_prefix + in_prefix
255260

256-
def smooth(self, prefix=''):
261+
def smooth(self, in_prefix='', out_prefix='s'):
257262
fwhm = self.ana_def['fwhm']
258263
try:
259264
len(fwhm)
260265
except TypeError:
261266
fwhm = [fwhm] * 3
262267
fwhm = np.asarray(fwhm, dtype=np.float).reshape(1,3)
263268
sess_scans = scans_for_fnames(
264-
fnames_presuffix(self.data_def['functionals'], prefix))
269+
fnames_presuffix(self.data_def['functionals'], in_prefix))
265270
sinfo = make_job('spatial', 'smooth',
266271
{'data':np.vstack(sess_scans.flat),
267272
'fwhm':fwhm,
268273
'dtype':0})
269274
run_jobdef(sinfo)
270-
return 's' + prefix
275+
return out_prefix + in_prefix
271276

272277

273278
def process_subject(ddef, study_def, ana_def):
@@ -279,9 +284,9 @@ def process_subject(ddef, study_def, ana_def):
279284
ana = SPMSubjectAnalysis(ddef, study_def, ana_def)
280285
# st_prefix = ana.slicetime('') # We can't run slice timing
281286
st_prefix = ''
282-
ana.realign(st_prefix)
283-
ana.reslice(st_prefix, out=('mean',))
284-
ana.coregister(st_prefix)
287+
ana.realign(in_prefix=st_prefix)
288+
ana.reslice(in_prefix=st_prefix, out=('mean',))
289+
ana.coregister(in_prefix=st_prefix)
285290
ana.seg_norm()
286291
n_st_prefix = ana.norm_write(st_prefix)
287292
ana.smooth(n_st_prefix)
@@ -302,7 +307,7 @@ def main():
302307
if len(sys.argv) > 2:
303308
subj_ids = [int(id) for id in sys.argv[2:]]
304309
else:
305-
subj_ids = range(1, 6)
310+
subj_ids = range(1, 7)
306311
for subj_id in subj_ids:
307312
ddef = get_data(data_path, subj_id)
308313
assert len(ddef['functionals']) in (11, 12)

0 commit comments

Comments
 (0)