コード例 #1
0
ファイル: test_datasets.py プロジェクト: ja-che/nistats
def test_fetch_spm_auditory():
    import nibabel as nib
    import shutil
    saf = ["fM00223/fM00223_%03i.img" % index for index in range(4, 100)]
    saf_ = ["fM00223/fM00223_%03i.hdr" % index for index in range(4, 100)]

    data_dir = os.path.join(tst.tmpdir, 'spm_auditory')
    os.mkdir(data_dir)
    subject_dir = os.path.join(data_dir, 'sub001')
    os.mkdir(subject_dir)
    os.mkdir(os.path.join(subject_dir, 'fM00223'))
    os.mkdir(os.path.join(subject_dir, 'sM00223'))

    path_img = os.path.join(tst.tmpdir, 'tmp.img')
    path_hdr = os.path.join(tst.tmpdir, 'tmp.hdr')
    nib.save(nib.Nifti1Image(np.zeros((2, 3, 4)), np.eye(4)), path_img)
    shutil.copy(path_img, os.path.join(subject_dir, "sM00223/sM00223_002.img"))
    shutil.copy(path_hdr, os.path.join(subject_dir, "sM00223/sM00223_002.hdr"))
    for file_ in saf:
        shutil.copy(path_img, os.path.join(subject_dir, file_))
    for file_ in saf_:
        shutil.copy(path_hdr, os.path.join(subject_dir, file_))

    dataset = datasets.fetch_spm_auditory(data_dir=tst.tmpdir)
    assert_true(isinstance(dataset.anat, _basestring))
    assert_true(isinstance(dataset.func[0], _basestring))
    assert_equal(len(dataset.func), 96)
コード例 #2
0
ファイル: plot_spm_auditory.py プロジェクト: mrahim/nistats
"""

import os
import numpy as np
import pandas as pd

import nibabel as nib
from nilearn.plotting import plot_stat_map, show
from nilearn.image import mean_img

from nistats.design_matrix import make_design_matrix
from nistats.glm import FirstLevelGLM
from nistats.datasets import fetch_spm_auditory

# fetch spm auditory data
subject_data = fetch_spm_auditory()
fmri_img = nib.concat_images(subject_data.func)
# compute bg unto which activation will be projected
mean_img = mean_img(fmri_img)

# construct experimental paradigm
tr = 7.
n_scans = 96
epoch_duration = 6 * tr  # duration in seconds
conditions = ['rest', 'active'] * 8
n_blocks = len(conditions)
duration = epoch_duration * np.ones(n_blocks)
onset = np.linspace(0, (n_blocks - 1) * epoch_duration, n_blocks)
paradigm = pd.DataFrame(
    {'onset': onset, 'duration': duration, 'name': conditions})
コード例 #3
0
ファイル: test_datasets.py プロジェクト: aabadie/nistats
def test_fetch_spm_auditory():
    dataset = datasets.fetch_spm_auditory(data_dir=tmpdir)
    assert_true(isinstance(dataset.anat, _basestring))
    assert_true(isinstance(dataset.func[0], _basestring))
    assert_equal(len(dataset.func), 96)
コード例 #4
0
    :depth: 1

"""

###############################################################################
# Retrieving the data
# -------------------
#
# .. note:: In this tutorial, we load the data using a data downloading
#           function. To input your own data, you will need to provide
#           a list of paths to your own files in the ``subject_data`` variable.
#           These should abide to the Brain Imaging Data Structure (BIDS)
#           organization.

from nistats.datasets import fetch_spm_auditory
subject_data = fetch_spm_auditory()
print(subject_data.func)  # print the list of names of functional images

###############################################################################
# We can display the first functional image and the subject's anatomy:
from nilearn.plotting import plot_stat_map, plot_anat, plot_img, show
plot_img(subject_data.func[0])
plot_anat(subject_data.anat)

###############################################################################
# Next, we concatenate all the 3D EPI image into a single 4D image,
# then we average them in order to create a background
# image that will be used to display the activations:

from nilearn.image import concat_imgs, mean_img
fmri_img = concat_imgs(subject_data.func)
コード例 #5
0
ファイル: test_datasets.py プロジェクト: shanyu329/nistats
def test_fetch_spm_auditory():
    dataset = datasets.fetch_spm_auditory(data_dir=tmpdir)
    assert_true(isinstance(dataset.anat, _basestring))
    assert_true(isinstance(dataset.func[0], _basestring))
    assert_equal(len(dataset.func), 96)