[pymvpa] selecting features by mask

John Clithero john.clithero at gmail.com
Fri Aug 28 01:02:29 UTC 2009

Hi Michael,

Thanks. I took that and just made one (very) minor change --
"new_mask.data" instead of "new_mask", for ndarray -- and it appears
to have worked perfectly!
Hopefully this is what you had in mind:

##wb data##
dataset_wb = NiftiDataset((wb_file),
##New mask##
comb_mask = N.logical_and(new_mask.data != 0,
                                  dataset_wb.mapper.getMask(copy=False) != 0)
fmask = dataset_wb.mapper.forward( comb_mask != 0 )
dataset_vmpfc=dataset_wb.selectFeatures(fmask.nonzero()[0], plain=True)


On Thu, Aug 27, 2009 at 8:09 PM, Michael Hanke<michael.hanke at gmail.com> wrote:
> Hi,
> On Thu, Aug 27, 2009 at 07:22:03PM -0400, John Clithero wrote:
>> Hi all,
>> Another relatively simple question (I think).
>> I can load/create a dataset as follows:
>> dataset_wb = NiftiDataset((wb_file),
>>       labels=attr.labels,
>>       chunks=attr.chunks,
>>       mask=os.path.join(roidir,'wb.nii.gz'))
>> And then, after this, I want to use SelectFeatures based on a mask I
>> have to run some additional classifiers on a subset of the features
>> using a new mask, say:
>> roi_mask=os.path.join(roidir,'vmpfc.nii.gz')
>> It is advantageous for me to create the dataset_wb as wholebrain using
>> the 'wb.nii.gz' mask and then after analyses, use this other mask on
>> the dataset (I want to detrend etc. at the whole-brain, not the ROI
>> level).
>> It seems like something that used to exist,
>> "selectFeaturesByMask(mask, plain=False)"
>> would have been perfect for this. It seems that now, based on a post
>> earlier, a list of Ids from my roi_mask is needed for selectFeatures.
>> My question then, is given all of my fMRI data are in the same 3D
>> space (or, each timepoint is in the same 3D space as my masks), there
>> must be some way to use getOutId to get a list of Ids (say, Z) from
>> roi_mask to plug into
>> new_dataset_roi=dataset_wb.selectFeatures(Z).
> Congrats, you fell into a pit we digged out for construction works and
> never closed ;-)
> The quickest way for you is probably to take a look at
> MaskedDataset.selectFeaturesByMask(). That is a 3-liner that should to
> what you need. It should be relatively straightforward to apply that to
> any NiftiDataset without having to subclass it.
> HTH,
> Michael
> --
> GPG key:  1024D/3144BE0F Michael Hanke
> http://apsy.gse.uni-magdeburg.de/hanke
> _______________________________________________
> Pkg-ExpPsy-PyMVPA mailing list
> Pkg-ExpPsy-PyMVPA at lists.alioth.debian.org
> http://lists.alioth.debian.org/mailman/listinfo/pkg-exppsy-pymvpa

More information about the Pkg-ExpPsy-PyMVPA mailing list