コード例 #1
0
ファイル: plot_haxby_decoding.py プロジェクト: ruizm/tutorial
"""
The haxby dataset: face vs house in object recognition
=======================================================

A significant part of the running time of this example is actually spent
in loading the data: we load all the data but only use the face and
houses conditions.
"""

### Load Haxby dataset ########################################################
from nisl import datasets
import numpy as np
import nibabel
dataset_files = datasets.fetch_haxby()

# fmri_data and mask are copied to lose the reference to the original data
bold_img = nibabel.load(dataset_files.func)
fmri_data = np.copy(bold_img.get_data())
affine = bold_img.get_affine()
y, session = np.loadtxt(dataset_files.session_target).astype("int").T
conditions = np.recfromtxt(dataset_files.conditions_target)['f0']
mask = dataset_files.mask
# fmri_data.shape is (40, 64, 64, 1452)
# and mask.shape is (40, 64, 64)

### Preprocess data ###########################################################
# Build the mean image because we have no anatomic data
mean_img = fmri_data.mean(axis=-1)

### Restrict to faces and houses ##############################################
コード例 #2
0
"""
Simple example of decoding: the Haxby dataset
==============================================

Here is a simple example of decoding, reproducing the Haxby 2001
study.
"""

### Load haxby dataset ########################################################

from nisl import datasets
dataset = datasets.fetch_haxby()

### Load Target labels ########################################################

import numpy as np
import sklearn.utils.fixes
# Load target information as string and give a numerical identifier to each
labels = np.loadtxt(dataset.session_target[0],
                    dtype=np.str,
                    skiprows=1,
                    usecols=(0, ))

# For compatibility with numpy 1.3 and scikit-learn 0.12
# "return_inverse" option appeared in numpy 1.4, scikit-learn >= 0.14 supports
# text labels.
# With scikit-learn >= 0.14, replace this line by: target = labels
_, target = sklearn.utils.fixes.unique(labels, return_inverse=True)

### Remove resting state condition ############################################
コード例 #3
0
"""
Searchlight analysis of face vs house recognition
==================================================

Searchlight analysis requires fitting a classifier a large amount of
times. As a result, it is an intrinsically slow method. In order to speed
up computing, in this example, Searchlight is run only on one slice on
the fMRI (see the generated figures).

"""

### Load Haxby dataset ########################################################
from nisl import datasets
dataset = datasets.fetch_haxby()
fmri_data = dataset.data
mask = dataset.mask
affine = dataset.affine
y = dataset.target
conditions = dataset.target_strings
session = dataset.session

### Preprocess data ###########################################################
import numpy as np

# Change axis in order to have X under n_samples * x * y * z
X = np.rollaxis(fmri_data, 3)
# X.shape is (1452, 40, 64, 64)

# Mean image: used as background in visualisation
mean_img = np.mean(X, axis=0)
コード例 #4
0
ファイル: plot_haxby_mask.py プロジェクト: ruizm/tutorial
"""
Example of automatic mask computation
"""

import pylab as pl
from nisl import datasets, io

# Load Haxby dataset
dataset_files = datasets.fetch_haxby()

masker = io.NiftiMasker()
masker.fit(dataset_files.func)

pl.imshow(masker.mask_.get_data()[..., 30])
pl.show()