[pymvpa] Dataset with multidimensional feature vector per voxel
Yaroslav Halchenko
debian at onerussian.com
Thu Nov 5 14:14:24 UTC 2015
On Thu, 05 Nov 2015, Ulrike Kuhl wrote:
> Dear Yaroslav,
> thanks a lot for your reply.
> With your snipped it was really easy for me to set up the matrix as you described it. :-)
> For those interested, this is the code that works for me:
> sub_list = [list of subjects]
> param_list = [list of parameters]
> dss = []
> for sub_index, sub in enumerate(sub_list):
> for suf_index, suf in enumerate(param_list):
> ds = fmri_dataset('/path/to/image/file',mask='/path/to/mask/file')
> ds.fa['modality'] = [suf] * ds.nfeatures # for each feature, set the modality attribute
> ds.fa['modality_index'] = [suf_index] * ds.nfeatures # this as numeric might come handy for searchlights later
> if sub.startswith('L'):
> learn = 1
> elif sub.startswith('N'):
> learn = 0
> ds.sa['targets'] = [learn]
> ds.sa['chunks'] = [sub_index]
> dss.append(ds)
> dsall = hstack(dss)
Here is my tune up with # yoh: comments
####################################
sub_list = [list of subjects]
param_list = [list of parameters]
dss = []
for sub_index, sub in enumerate(sub_list):
for suf_index, suf in enumerate(param_list):
ds = fmri_dataset('/path/to/image/file',mask='/path/to/mask/file')
# yoh: no need to broadcast -- should do automagically
ds.fa['modality'] = [suf] # for each feature, set the modality attribute
ds.fa['modality_index'] = [suf_index] # this as numeric might come handy for searchlights later
if sub.startswith('L'):
learn = 1
elif sub.startswith('N'):
learn = 0
else:
# yoh: make it explicit, otherwise you would assign previous learn to next one not L or N
raise ValueError("Do not know what to do with %s" % sub)
# yoh: seems it was incorrectly indented into elif
ds.sa['targets'] = [learn]
ds.sa['chunks'] = [sub_index]
dss.append(ds)
dsall = hstack(dss)
####################################
cheers
--
Yaroslav O. Halchenko
Center for Open Neuroscience http://centerforopenneuroscience.org
Dartmouth College, 419 Moore Hall, Hinman Box 6207, Hanover, NH 03755
Phone: +1 (603) 646-9834 Fax: +1 (603) 646-1419
WWW: http://www.linkedin.com/in/yarik
More information about the Pkg-ExpPsy-PyMVPA
mailing list