Пример #1
0
def test_fail_fetch_harvard_oxford():
    # specify non-existing atlas item
    assert_raises_regex(ValueError, 'Invalid atlas name',
                        datasets.fetch_harvard_oxford, 'not_inside')

    # specify existing atlas item
    target_atlas = 'cort-maxprob-thr0-1mm'
    target_atlas_fname = 'HarvardOxford-' + target_atlas + '.nii.gz'

    HO_dir = os.path.join(tmpdir, 'harvard_oxford')
    os.mkdir(HO_dir)
    nifti_dir = os.path.join(HO_dir, 'HarvardOxford')
    os.mkdir(nifti_dir)

    target_atlas_nii = os.path.join(nifti_dir, target_atlas_fname)
    datasets.load_mni152_template().to_filename(target_atlas_nii)

    dummy = open(os.path.join(HO_dir, 'HarvardOxford-Cortical.xml'), 'w')
    dummy.write("<?xml version='1.0' encoding='us-ascii'?> "
                "<metadata>"
                "</metadata>")
    dummy.close()

    out_nii, arr = datasets.fetch_harvard_oxford(target_atlas, data_dir=tmpdir)

    assert_true(isinstance(nibabel.load(out_nii), nibabel.Nifti1Image))
    assert_true(isinstance(arr, np.ndarray))
    assert_true(len(arr) > 0)
Пример #2
0
def test_fail_fetch_harvard_oxford():
    # specify non-existing atlas item
    assert_raises_regex(ValueError, 'Invalid atlas name',
                        datasets.fetch_harvard_oxford, 'not_inside')

    # specify existing atlas item
    target_atlas = 'cort-maxprob-thr0-1mm'
    target_atlas_fname = 'HarvardOxford-' + target_atlas + '.nii.gz'

    HO_dir = os.path.join(tmpdir, 'harvard_oxford')
    os.mkdir(HO_dir)
    nifti_dir = os.path.join(HO_dir, 'HarvardOxford')
    os.mkdir(nifti_dir)

    target_atlas_nii = os.path.join(nifti_dir, target_atlas_fname)
    datasets.load_mni152_template().to_filename(target_atlas_nii)

    dummy = open(os.path.join(HO_dir, 'HarvardOxford-Cortical.xml'), 'w')
    dummy.write("<?xml version='1.0' encoding='us-ascii'?> "
                "<metadata>"
                "</metadata>")
    dummy.close()

    out_nii, arr = datasets.fetch_harvard_oxford(target_atlas, data_dir=tmpdir)

    assert_true(isinstance(nibabel.load(out_nii), nibabel.Nifti1Image))
    assert_true(isinstance(arr, np.ndarray))
    assert_true(len(arr) > 0)
"""
Basic Atlas plotting
=======================

Plot the regions of a reference atlas (here the Harvard-Oxford atlas).
"""

import matplotlib.pyplot as plt
from nilearn import datasets
from nilearn import plotting

atlas_filename, labels = datasets.fetch_harvard_oxford('cort-maxprob-thr25-2mm')

plotting.plot_roi(atlas_filename, title="Harvard Oxford atlas")
plt.show()
from sklearn.multiclass import OneVsOneClassifier, OneVsRestClassifier
# from sklearn.pipeline import Pipeline
from sklearn import linear_model
from sklearn import preprocessing

from sklearn.cross_validation import cross_val_score
# from ni_rrr import fit_predict
from scipy.stats import spearmanr
from scipy import stats, linalg
from joblib import Parallel, delayed

haxby_dataset = datasets.fetch_haxby_simple()
func_filename = haxby_dataset.func
mask_filename = haxby_dataset.mask

atlas_filename, labels = datasets.fetch_harvard_oxford(
    'cort-maxprob-thr25-2mm', symmetric_split=True)


affine = load(mask_filename).get_affine()
shape = load(mask_filename).get_shape()
atlas = image.resample_img(atlas_filename, target_affine=affine,
                           target_shape=shape, interpolation='nearest')
roi_masker = input_data.NiftiLabelsMasker(labels_img=atlas,
                                          mask_img=mask_filename)
roi_masker.fit(mask_filename) ## just to have it fitted

labels = np.recfromcsv(haxby_dataset.session_target[0], delimiter=" ")
target = labels['labels']
###################################################

y, session = np.loadtxt(haxby_dataset.session_target).astype('int').T
from sklearn.multiclass import OneVsOneClassifier, OneVsRestClassifier
# from sklearn.pipeline import Pipeline
from sklearn import linear_model
from sklearn import preprocessing

from sklearn.cross_validation import cross_val_score
# from ni_rrr import fit_predict
from scipy.stats import spearmanr
from scipy import stats, linalg
from joblib import Parallel, delayed

haxby_dataset = datasets.fetch_haxby_simple()
func_filename = haxby_dataset.func
mask_filename = haxby_dataset.mask

atlas_filename, labels = datasets.fetch_harvard_oxford(
    'cort-maxprob-thr25-2mm', symmetric_split=True)

affine = load(mask_filename).get_affine()
shape = load(mask_filename).get_shape()
atlas = image.resample_img(atlas_filename,
                           target_affine=affine,
                           target_shape=shape,
                           interpolation='nearest')
roi_masker = input_data.NiftiLabelsMasker(labels_img=atlas,
                                          mask_img=mask_filename)
roi_masker.fit(mask_filename)  ## just to have it fitted

labels = np.recfromcsv(haxby_dataset.session_target[0], delimiter=" ")
target = labels['labels']
###################################################
Пример #6
0
"""
Basic Atlas plotting
=======================

Plot the regions of a reference atlas (here the Harvard-Oxford atlas).
"""

import matplotlib.pyplot as plt
from nilearn import datasets
from nilearn import plotting

atlas_filename, labels = datasets.fetch_harvard_oxford(
    'cort-maxprob-thr25-2mm')

plotting.plot_roi(atlas_filename, title="Harvard Oxford atlas")
plt.show()