def __init__(self, images=None, volume_start_times=None, slice_times=None): """ A lightweight implementation of an fMRI image as in ImageList Parameters ---------- images: a sliceable object whose items are meant to be images, this is checked by asserting that each has a `coordmap` attribute volume_start_times: start time of each frame. It can be specified either as an ndarray with len(images) elements or as a single float, the TR. Defaults to arange(len(images)).astype(np.float) slice_times: ndarray specifying offset for each slice of each frame See Also -------- nipy.core.image_list.ImageList Examples -------- >>> from numpy import asarray >>> from nipy.testing import funcfile >>> from nipy.io.api import load_image >>> # fmrilist and ilist represent the same data >>> funcim = load_image(funcfile) >>> fmrilist = FmriImageList.from_image(funcim) >>> ilist = FmriImageList(funcim) >>> print asarray(ilist).shape (17, 21, 3, 20) >>> print asarray(ilist[4]).shape (21, 3, 20) """ ImageList.__init__(self, images=images) if volume_start_times is None: volume_start_times = 1. v = asarray(volume_start_times) try: length = len(self.list) except TypeError: length = len(self.list.get_data()) if v.shape == (length,): self.volume_start_times = volume_start_times else: v = float(volume_start_times) self.volume_start_times = arange(length) * v self.slice_times = slice_times
def from_image(klass, fourdimage, volume_start_times=None, slice_times=None, axis="t"): """Create an FmriImageList from a 4D Image by extracting 3d images along the 't' axis. Parameters ---------- fourdimage: a 4D Image volume_start_times: start time of each frame. It can be specified either as an ndarray with len(images) elements or as a single float, the TR. Defaults to the diagonal entry of slowest moving dimension of Affine transform slice_times: ndarray specifying offset for each slice of each frame """ if fourdimage.ndim != 4: raise ValueError("expecting a 4-dimensional Image") image_list = ImageList.from_image(fourdimage, axis="t") return klass(images=image_list.list, volume_start_times=volume_start_times, slice_times=slice_times)