예제 #1
0
def test_iterate_over_image():
    # Fit a model, iterating over the slices of an array
    # associated to an FmriImage.
    c = np.zeros(FDATA.shape[1:]) + 0.5
    res_gen = result_generator(flatten_generator(axis0_generator(FDATA)))
    write_data(c, unflatten_generator(contrast_generator(res_gen)))
    # Fit a model, iterating over the array associated to an
    # FmriImage, iterating over a list of ROIs defined by binary
    # regions of the same shape as a frame of FmriImage

    # this might really be an anatomical image or AR(1) coefficients
    a = np.asarray(FDATA[0])
    p = np.greater(a, a.mean())
    d = np.ones(FDATA.shape[1:]) * 2.0
    flat_gen = flatten_generator(axis0_generator(FDATA, parcels(p)))
    write_data(d, contrast_generator(result_generator(flat_gen)))
    assert_array_almost_equal(d, c)

    e = np.zeros(FDATA.shape[1:]) + 3.0
    flat_gen2 = flatten_generator(axis0_generator(FDATA, parcels(p)))
    write_data(e, f_generator(contrast, result_generator(flat_gen2)))
    assert_array_almost_equal(d, e)
예제 #2
0
def test_iterate_over_image():
    # Fit a model, iterating over the slices of an array
    # associated to an FmriImage.
    c = np.zeros(FDATA.shape[1:]) + 0.5
    res_gen = result_generator(flatten_generator(axis0_generator(FDATA)))
    write_data(c, unflatten_generator(contrast_generator(res_gen)))
    # Fit a model, iterating over the array associated to an
    # FmriImage, iterating over a list of ROIs defined by binary
    # regions of the same shape as a frame of FmriImage

    # this might really be an anatomical image or AR(1) coefficients
    a = np.asarray(FDATA[0])
    p = np.greater(a, a.mean())
    d = np.ones(FDATA.shape[1:]) * 2.0
    flat_gen = flatten_generator(axis0_generator(FDATA, parcels(p)))
    write_data(d, contrast_generator(result_generator(flat_gen)))
    assert_array_almost_equal(d, c)

    e = np.zeros(FDATA.shape[1:]) + 3.0
    flat_gen2 = flatten_generator(axis0_generator(FDATA, parcels(p)))
    write_data(e, f_generator(contrast, result_generator(flat_gen2)))
    assert_array_almost_equal(d, e)
예제 #3
0
from os.path import dirname, join as pjoin

import nipy

from nipy.core.utils.generators import parcels

OUR_PATH = dirname(__file__)
DATA_PATH = pjoin(OUR_PATH, '..', 'data')
BG_IMAGE_FNAME = pjoin(DATA_PATH, 'mni_basal_ganglia.nii.gz')

bg_img = nipy.load_image(BG_IMAGE_FNAME)
bg_data = bg_img.get_data()
"""
I happen to know that the image has these codes:

14 - Left striatum
16 - Right striatum
39 - Left caudate
53 - Right caudate

All the other voxels are zero, I don't want those.
"""

print("Number of voxels for L, R striatum; L, R caudate")
for mask in parcels(bg_data, exclude=(0, )):
    print(mask.sum())
""" Given we know the codes we can also give them directly """
print("Again with the number of voxels for L, R striatum; L, R caudate")
for mask in parcels(bg_data, labels=(14, 16, 39, 53)):
    print(mask.sum())
예제 #4
0
import nipy

from nipy.core.utils.generators import parcels

OUR_PATH = dirname(__file__)
DATA_PATH = pjoin(OUR_PATH, '..', 'data')
BG_IMAGE_FNAME = pjoin(DATA_PATH, 'mni_basal_ganglia.nii.gz')

bg_img = nipy.load_image(BG_IMAGE_FNAME)
bg_data = bg_img.get_data()

"""
I happen to know that the image has these codes:

14 - Left striatum
16 - Right striatum
39 - Left caudate
53 - Right caudate

All the other voxels are zero, I don't want those.
"""

print("Number of voxels for L, R striatum; L, R caudate")
for mask in parcels(bg_data, exclude=(0,)):
    print(mask.sum())

""" Given we know the codes we can also give them directly """
print("Again with the number of voxels for L, R striatum; L, R caudate")
for mask in parcels(bg_data, labels=(14, 16, 39, 53)):
    print(mask.sum())