modalities.fmri.fmri

Module: modalities.fmri.fmri

Inheritance diagram for nipy.modalities.fmri.fmri:

Inheritance diagram of nipy.modalities.fmri.fmri

FmriImageList

class nipy.modalities.fmri.fmri.FmriImageList(images=None, volume_start_times=None, slice_times=None)

Bases: nipy.core.image.image_list.ImageList

Class to implement image list interface for FMRI time series

Allows metadata such as volume and slice times

__init__(images=None, volume_start_times=None, slice_times=None)

An implementation of an fMRI image as in ImageList

Parameters
imagesiterable

an iterable object whose items are meant to be images; this is checked by asserting that each has a coordmap attribute and a get_data method. Note that Image objects are not iterable by default; use the from_image classmethod or iter_axis function to convert images to image lists - see examples below for the latter.

volume_start_times: None or float or (N,) ndarray

start time of each frame. It can be specified either as an ndarray with N=len(images) elements or as a single float, the TR. None results in np.arange(len(images)).astype(np.float)

slice_times: None or (N,) ndarray

specifying offset for each slice of each frame, from the frame start time.

See also

nipy.core.image_list.ImageList

Examples

>>> from nipy.testing import funcfile
>>> from nipy.io.api import load_image
>>> from nipy.core.api import iter_axis
>>> funcim = load_image(funcfile)
>>> iterable_img = iter_axis(funcim, 't')
>>> fmrilist = FmriImageList(iterable_img)
>>> print(fmrilist.get_list_data(axis=0).shape)
(20, 17, 21, 3)
>>> print(fmrilist[4].shape)
(17, 21, 3)
classmethod from_image(fourdimage, axis='t', volume_start_times=None, slice_times=None)

Create an FmriImageList from a 4D Image

Get images by extracting 3d images along the ‘t’ axis.

Parameters
fourdimageImage instance

A 4D Image

volume_start_times: None or float or (N,) ndarray

start time of each frame. It can be specified either as an ndarray with N=len(images) elements or as a single float, the TR. None results in np.arange(len(images)).astype(np.float)

slice_times: None or (N,) ndarray

specifying offset for each slice of each frame, from the frame start time.

Returns
filistFmriImageList instance
get_list_data(axis=None)

Return data in ndarray with list dimension at position axis

Parameters
axisint

axis specifies which axis of the output will take the role of the list dimension. For example, 0 will put the list dimension in the first axis of the result.

Returns
datandarray

data in image list as array, with data across elements of the list concetenated at dimension axis of the array.

Examples

>>> from nipy.testing import funcfile
>>> from nipy.io.api import load_image
>>> funcim = load_image(funcfile)
>>> ilist = ImageList.from_image(funcim, axis='t')
>>> ilist.get_list_data(axis=0).shape
(20, 17, 21, 3)
nipy.modalities.fmri.fmri.axis0_generator(data, slicers=None)

Takes array-like data, returning slices over axes > 0

This function takes an array-like object data and yields tuples of slicing thing and slices like:

[slicer, np.asarray(data)[:,slicer] for slicer in slicer]

which in the default (slicers is None) case, boils down to:

[i, np.asarray(data)[:,i] for i in range(data.shape[1])]

This can be used to get arrays of time series out of an array if the time axis is axis 0.

Parameters
dataarray-like

object such that arr = np.asarray(data) returns an array of at least 2 dimensions.

slicersNone or sequence

sequence of objects that can be used to slice into array arr returned from data. If None, default is range(data.shape[1])