[pymvpa] Using searchlight for quick spherical ROIs? (Michael Hanke)

Johan Carlin jdc55 at cam.ac.uk
Tue Mar 17 20:20:49 UTC 2009


Thanks for the input! I now have a workable solution. First, I tried to
create an output map to convert back to nifti. This fails because the sl_map
output only contains nROI values rather than nFeatures, so ds.map2Nifti
throws an error. I put together a very ugly hack to get around this:

from numpy import array, nan

feat_ids = []
for roi_x, roi_y, roi_z in ROI_coords: # Transform ROIs to feature IDs
    feat_ids.append(tds.mapper.getOutId((roi_z, roi_y, roi_x)))

sl = Searchlight(cv, radius=slr, center_ids=feat_ids) #Restrict to feature
IDs..
sl_map = sl(tds) # RUN
sl_new = array([nan])
sl_new = sl_new.repeat(tds.nfeatures)
sl_new = list(sl_new) # an empty list
toindex = dict(zip(feat_ids, sl_map))
for id, value in toindex.iteritems():
sl_new[id] = value # index in ROI IDs

#

So basically I create a list of NaNs, and index in the ROI feature IDs.
There are probably more elegant ways of doing this, but I'm still figuring
out the basics of Python... Anyway, you end up with a nifti image of the
ROIs.

This is probably of very limited use, except as a sanity check to ensure
that your ROI coordinates get properly mapped to feature IDs and back.
Instead, I ended up skipping the nifti, and instead running the SL analysis
with a single feature ID at a time. This way I can take the single sl_map
output as a measure of performance for that particular ROI:

for roi_l, roi_c in ROIs.iteritems(): # ROI loop
    roi_id = []
    roi_id.append(tds.mapper.getOutId(roi_c))

    sl = Searchlight(cv, radius=roi_r, center_ids=roi_id) # Now one
coordinate at a time
    sl_map = sl(tds) # RUN

# Save results
    resres = '\t' + str(sl_map[0])
    resfile.write(resres)

#

I don't particularly encourage anyone to use this code, but at least it
shows loosely what to do, if anyone else is doing spherical ROIs.
Suggestions for improvements / optimisations would be welcome.

Thanks again for the help!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.alioth.debian.org/pipermail/pkg-exppsy-pymvpa/attachments/20090317/32e0ac92/attachment.htm 


More information about the Pkg-ExpPsy-PyMVPA mailing list