def test_fetch_oasis_vbm(): local_url = "file://" + datadir ids = np.asarray(['OAS1_%4d' % i for i in range(457)]) ids = ids.view(dtype=[('ID', 'S9')]) file_mock.add_csv('oasis_cross-sectional.csv', ids) # Disabled: cannot be tested without actually fetching covariates CSV file dataset = datasets.fetch_oasis_vbm(data_dir=tmpdir, url=local_url, verbose=0) assert_equal(len(dataset.gray_matter_maps), 403) assert_equal(len(dataset.white_matter_maps), 403) assert_true(isinstance(dataset.gray_matter_maps[0], _basestring)) assert_true(isinstance(dataset.white_matter_maps[0], _basestring)) assert_true(isinstance(dataset.ext_vars, np.recarray)) assert_true(isinstance(dataset.data_usage_agreement, _basestring)) assert_equal(len(url_request.urls), 3) dataset = datasets.fetch_oasis_vbm(data_dir=tmpdir, url=local_url, dartel_version=False, verbose=0) assert_equal(len(dataset.gray_matter_maps), 415) assert_equal(len(dataset.white_matter_maps), 415) assert_true(isinstance(dataset.gray_matter_maps[0], _basestring)) assert_true(isinstance(dataset.white_matter_maps[0], _basestring)) assert_true(isinstance(dataset.ext_vars, np.recarray)) assert_true(isinstance(dataset.data_usage_agreement, _basestring)) assert_equal(len(url_request.urls), 4)
Note that more power would be obtained from using a larger sample of subjects. """ # Authors: Bertrand Thirion, <*****@*****.**>, July 2018 # Elvis Dhomatob, <*****@*****.**>, Apr. 2014 # Virgile Fritsch, <*****@*****.**>, Apr 2014 # Gael Varoquaux, Apr 2014 n_subjects = 100 # more subjects requires more memory ############################################################################ # Load Oasis dataset # ------------------ from nilearn import datasets oasis_dataset = datasets.fetch_oasis_vbm(n_subjects=n_subjects) gray_matter_map_filenames = oasis_dataset.gray_matter_maps age = oasis_dataset.ext_vars['age'].astype(float) ############################################################################### # Sex is encoded as 'M' or 'F'. make it a binary variable sex = oasis_dataset.ext_vars['mf'] == b'F' ############################################################################### # Print basic information on the dataset print('First gray-matter anatomy image (3D) is located at: %s' % oasis_dataset.gray_matter_maps[0]) # 3D data print('First white-matter anatomy image (3D) is located at: %s' % oasis_dataset.white_matter_maps[0]) # 3D data ###############################################################################
____ """ # Authors: Elvis Dhomatob, <*****@*****.**>, Apr. 2014 # Virgile Fritsch, <*****@*****.**>, Apr 2014 # Gael Varoquaux, Apr 2014 import numpy as np import matplotlib.pyplot as plt import nibabel from nilearn import datasets from nilearn.input_data import NiftiMasker n_subjects = 100 # more subjects requires more memory ### Load Oasis dataset ######################################################## dataset_files = datasets.fetch_oasis_vbm(n_subjects=n_subjects) age = dataset_files.ext_vars['age'].astype(float) ### Preprocess data ########################################################### nifti_masker = NiftiMasker( standardize=False, smoothing_fwhm=2, memory='nilearn_cache') # cache options # remove features with too low between-subject variance gm_maps_masked = nifti_masker.fit_transform(dataset_files.gray_matter_maps) gm_maps_masked[:, gm_maps_masked.var(0) < 0.01] = 0. # final masking new_images = nifti_masker.inverse_transform(gm_maps_masked) gm_maps_masked = nifti_masker.fit_transform(new_images) n_samples, n_features = gm_maps_masked.shape print n_samples, "subjects, ", n_features, "features"
import warnings import numpy as np from nilearn.datasets import fetch_oasis_vbm from sklearn.model_selection import ShuffleSplit from photonai.base import Hyperpipe, PipelineElement, OutputSettings from photonai_neuro import NeuroBranch warnings.filterwarnings("ignore", category=DeprecationWarning) # GET DATA FROM OASIS n_subjects = 50 dataset_files = fetch_oasis_vbm(n_subjects=n_subjects) age = dataset_files.ext_vars['age'].astype(float) y = np.array(age) X = np.array(dataset_files.gray_matter_maps) # DEFINE OUTPUT SETTINGS settings = OutputSettings(project_folder='./tmp/') # DESIGN YOUR PIPELINE pipe = Hyperpipe('GrayMatter', optimizer='grid_search', metrics=['mean_absolute_error'], best_config_metric='mean_absolute_error', outer_cv=ShuffleSplit(n_splits=1, test_size=0.2), inner_cv=ShuffleSplit(n_splits=1, test_size=0.2), verbosity=2, cache_folder="./cache", eval_final_performance=False, output_settings=settings)
""" # Authors: Elvis Dhomatob, <*****@*****.**>, Apr. 2014 # Virgile Fritsch, <*****@*****.**>, Apr 2014 # Gael Varoquaux, Apr 2014 import numpy as np import matplotlib.pyplot as plt from nilearn import datasets from nilearn.input_data import NiftiMasker n_subjects = 100 # more subjects requires more memory ############################################################################ # Load Oasis dataset # ------------------- oasis_dataset = datasets.fetch_oasis_vbm(n_subjects=n_subjects) gray_matter_map_filenames = oasis_dataset.gray_matter_maps age = oasis_dataset.ext_vars['age'].astype(float) # print basic information on the dataset print('First gray-matter anatomy image (3D) is located at: %s' % oasis_dataset.gray_matter_maps[0]) # 3D data print('First white-matter anatomy image (3D) is located at: %s' % oasis_dataset.white_matter_maps[0]) # 3D data ############################################################################# # Preprocess data # ---------------- nifti_masker = NiftiMasker( standardize=False, smoothing_fwhm=2,
# Virgile Fritsch, <*****@*****.**>, Apr 2014 # Gael Varoquaux, Apr 2014 # Andres Hoyos-Idrobo, Apr 2017 import numpy as np import matplotlib.pyplot as plt from nilearn import datasets from nilearn.maskers import NiftiMasker from nilearn.image import get_data n_subjects = 100 # more subjects requires more memory ############################################################################ # Load Oasis dataset # ------------------- oasis_dataset = datasets.fetch_oasis_vbm( n_subjects=n_subjects, legacy_format=False ) gray_matter_map_filenames = oasis_dataset.gray_matter_maps age = oasis_dataset.ext_vars['age'].values # Split data into training set and test set from sklearn.model_selection import train_test_split gm_imgs_train, gm_imgs_test, age_train, age_test = train_test_split( gray_matter_map_filenames, age, train_size=.6, random_state=0) # print basic information on the dataset print('First gray-matter anatomy image (3D) is located at: %s' % oasis_dataset.gray_matter_maps[0]) # 3D data print('First white-matter anatomy image (3D) is located at: %s' % oasis_dataset.white_matter_maps[0]) # 3D data