[pymvpa] Mask in from_wizard generates no data.
Yaroslav Halchenko
debian at onerussian.com
Wed Dec 10 16:10:26 UTC 2014
On Wed, 10 Dec 2014, Thomas Nickson wrote:
> My main problem is that this isn't at all consistent with how the function
> for constructing fmri datasets works. Which way do you consider to be
> correct?
I thought "correct way" is when mask dimensionality (be it a boolean
array or tuple of indices) matches the dimensionality of the data
array. That is I think how all our functions work
> I think the fmri way of handling it makes more sense. This way I
> have to understand that the mask needs to be flattened and I need to
> provide an array of nonzero indices.
that is where you are loosing me ;) why mask needs to be flattened?
> The other way does not work. No other
> way works.A I can't just provide a flattened boolean mask, if by that you
> mean 1's and 0's.
I mean dtype=bool array of True and False's. Array of indices 1 and 0
is just that -- array of indicies ;)
> I can't provide a mask of the same shape as the original
> data.
that is what confuses me -- it must work. looking back to our
correspondence -- you never showed that dtype of your mask is bool...
may be that is the catch?
> This is confusing because the original data will be automatically
> flattened but the mask won't.
confused
> Why does that make any sense?
dunno since it doesn't
> Surely you
> would at least want the inputs to be consistent for the mask and the
> original data?
yeah
> It's neither consistent within the function itself nor is
> it consistent between other functions that do the same thing.
hm... confused
> The fmri data provided for the tutorial does exactly the same thing. It
> hasn't got anything to do with the data. I can provide the code.
oy-- lets check that hypothesis of mine about dtype of your mask first
> Anyway, I don't mean to non-constructively criticise but I found it
> confusing and frustrating and thought it might be nice to alleviate some
> of that.
> #Open the main VBM data - some functions to help
> import numpy as np
> import nibabel as nb
> import os
> from functools import partial
> from operator import mul
> import pickle as p
> from mvpa2.datasets.base import Dataset
> from mvpa2.mappers.zscore import zscore
> from mvpa2.datasets.mri import fmri_dataset
> """4ddata is fddata and 2ddata is tddata"""
> def getImages(imagePath):
> A A A """load a nifti"""
> A A A return nb.load(imagePath)
> def writeDatatoImages(writePath, Data):
> A A A """Write a numpy array to a nifti1 image"""
> A A A N = nb.Nifti1Image(Data, np.eye(4))
> A A A N.to_filename(writePath)
> def getImageData(imagePath):
> A A A """load a nifti as numpy data"""
> A A A return getImages(imagePath).get_data()
> A A A
> def rotateShape(FDData):
> A A A """we need to rotate the shape of the data as other wise the time
> dimension (here denoting the subjects) is actually last"""
> A A A if len(FDData.shape) == 4:
> A A A A A A A FDData = np.rollaxis(FDData, -1)
> A A A return FDData
> def reshapeFlatten(FDData):
> A A A """Reshape the data and then flatten each member of the array"""
> A A A Data = rotateShape(FDData)
> A A A return Data.reshape(Data.shape[0],reduce(mul,Data.shape[1:],1))
> #======================================Helper functions
> above=====================================
> DATA_LOCATION = ./pymvpa/PyMVPA/tutorial_data/data/bold.nii.gz'
> MASK = './pymvpa/PyMVPA/tutorial_data/data/mask_brain.nii.gz'
> #Load the metadata pickle
> #metaData = p.load(open('VBMMeta.pkl'))
> #get image data and reshape
> rotatedImageData = rotateShape(getImageData(DATA_LOCATION))
> #Get mask data
> mask = getImageData(MASK).flatten()#.nonzero()[0]#.flatten().nonzero()[0]
just try
getImageData(MASK).astype(bool)
?
> #mask = np.float32(mask)
> #print type(mask)
> #Load dataset
> ds = Dataset.from_wizard(rotatedImageData,
> mask=mask)#targets=metaData['diagnosesT1'], mask=mask)
> #ds = fmri_dataset(rotatedImageData)#, targets=metaData['diagnosesT1'],
> mask=mask)
> #ds = fmri_dataset(DATA_LOCATION, mask=mask)#,
> targets=metaData['diagnosesT1'], mask=mask, chunks=np.array(range(133)))
> #zscore normalise the data
> #zscore(ds, chunks_attr=None)
--
Yaroslav O. Halchenko, Ph.D.
http://neuro.debian.net http://www.pymvpa.org http://www.fail2ban.org
Research Scientist, Psychological and Brain Sciences Dept.
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