def test_prepare_searchlight_mvpa_data(): images = io.load_images_from_dir(data_dir, suffix=suffix) conditions = io.load_labels(epoch_file) processed_data, labels = prepare_searchlight_mvpa_data(images, conditions) expected_searchlight_processed_data = np.load( expected_dir / 'expected_searchlight_processed_data.npy') for idx in range(len(processed_data)): assert np.allclose(processed_data[idx], expected_searchlight_processed_data[idx]), ( 'raw data do not match in test_prepare_searchlight_mvpa_data') assert np.array_equal(labels, expected_labels), \ 'the labels do not match in test_prepare_searchlight_mvpa_data' from brainiak.fcma.preprocessing import RandomType images = io.load_images_from_dir(data_dir, suffix=suffix) random_processed_data, _ = prepare_searchlight_mvpa_data( images, conditions, random=RandomType.REPRODUCIBLE) assert (len(random_processed_data) == len(expected_searchlight_processed_data)), ( 'numbers of epochs do not match in test_prepare_searchlight_mvpa_data') images = io.load_images_from_dir(data_dir, suffix=suffix) random_processed_data, _ = prepare_searchlight_mvpa_data( images, conditions, random=RandomType.UNREPRODUCIBLE) assert (len(random_processed_data) == len(expected_searchlight_processed_data)), ( 'numbers of epochs do not match in test_prepare_searchlight_mvpa_data')
def test_prepare_searchlight_mvpa_data(): images = io.load_images_from_dir(data_dir, suffix) conditions = io.load_labels(epoch_file) processed_data, labels = prepare_searchlight_mvpa_data(images, conditions) expected_searchlight_processed_data = np.load( expected_dir / 'expected_searchlight_processed_data.npy') for idx in range(len(processed_data)): assert np.allclose(processed_data[idx], expected_searchlight_processed_data[idx]), \ 'raw data do not match in test_prepare_searchlight_mvpa_data' assert np.array_equal(labels, expected_labels), \ 'the labels do not match in test_prepare_searchlight_mvpa_data'
mask_file = sys.argv[3] epoch_file = sys.argv[4] # all MPI processes read the mask; the mask file is small mask_image = nib.load(mask_file) mask = io.load_boolean_mask(mask_file) data = None labels = None if MPI.COMM_WORLD.Get_rank()==0: logger.info( 'mask size: %d' % np.sum(mask) ) images = io.load_images_from_dir(data_dir, suffix=suffix) conditions = io.load_labels(epoch_file) data, labels = prepare_searchlight_mvpa_data(images, conditions) # setting the random argument produces random voxel selection results # for non-parametric statistical analysis. # There are three random options: # RandomType.NORANDOM is the default # RandomType.REPRODUCIBLE permutes the voxels in the same way every run # RandomType.UNREPRODUCIBLE permutes the voxels differently across runs # example #from brainiak.fcma.preprocessing import RandomType #data, labels = prepare_searchlight_mvpa_data(images, conditions, # random=RandomType.UNREPRODUCIBLE) # the following line is an example to leaving a subject out #epoch_info = [x for x in epoch_info if x[1] != 0]