def test_iterate_over_image(self): # Fit a model, iterating over the slices of an array # associated to an FmriImage. c = np.zeros(self.fd.shape[1:]) + 0.5 fd = self.fd res_gen = result_generator(flatten_generator(fmri_generator(fd))) 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(fd[0]) p = np.greater(a, a.mean()) d = np.ones(fd.shape[1:]) * 2.0 flat_gen = flatten_generator(fmri_generator(fd, parcels(p))) write_data(d, contrast_generator(result_generator(flat_gen))) yield assert_array_almost_equal, d, c e = np.zeros(fd.shape[1:]) + 3.0 flat_gen2 = flatten_generator(fmri_generator(fd, parcels(p))) write_data(e, f_generator(contrast, result_generator(flat_gen2))) yield assert_array_almost_equal, d, e
def test_labels1(): img = load_image(funcfile) parcelmap = fromarray(np.asarray(img[0]), 'kji', 'zyx') parcelmap = (np.asarray(parcelmap) * 100).astype(np.int32) v = 0 for i, d in fmri_generator(img, parcels(parcelmap)): v += d.shape[1] assert_equal(v, parcelmap.size)
def model_generator(formula, data, volume_start_times, iterable=None, slicetimes=None, model_type=OLSModel, model_params = lambda x: ()): """ Generator for the models for a pass of fmristat analysis. """ for i, d in matrix_generator(fmri_generator(data, iterable=iterable)): model_args = model_params(i) # model may depend on i rmodel = model_type(formula.design(volume_start_times), *model_args) yield i, d, rmodel
def test_iter(): img = load_image(funcfile) img_shape = img.shape exp_shape = (img_shape[0],) + img_shape[2:] j = 0 for i, d in fmri_generator(img): j += 1 yield assert_equal(d.shape, exp_shape) del(i); gc.collect() yield assert_equal(j, img_shape[1])
def test_iter(): img = load_image(funcfile) # flip to time first version so this makes sense from nipy.core.reference.coordinate_map import reorder_input arr = np.asarray(img).T coordmap = reorder_input(img.coordmap) img_t1 = Image(arr, coordmap) slice_shape = (arr.shape[0],) + arr.shape[2:] j = 0 for i, d in fmri_generator(img_t1): j += 1 yield nose.tools.assert_equal, d.shape, slice_shape del(i); gc.collect() yield nose.tools.assert_equal, j, 3