diff --git a/neuromaps/datasets/__init__.py b/neuromaps/datasets/__init__.py index 15efc3ae..2614dbc9 100644 --- a/neuromaps/datasets/__init__.py +++ b/neuromaps/datasets/__init__.py @@ -1,10 +1,10 @@ """Functions for fetching datasets.""" __all__ = [ - 'fetch_all_atlases', 'fetch_atlas', 'fetch_civet', 'fetch_fsaverage', - 'fetch_fslr', 'fetch_mni152', 'fetch_regfusion', 'get_atlas_dir', - 'DENSITIES', 'ALIAS', 'available_annotations', 'available_tags', - 'fetch_annotation' + 'fetch_all_atlases', 'fetch_atlas', 'fetch_bigbrain', 'fetch_civet', + 'fetch_fsaverage', 'fetch_fslr', 'fetch_mni152', 'fetch_regfusion', + 'get_atlas_dir', 'DENSITIES', 'ALIAS', 'available_annotations', + 'available_tags', 'fetch_annotation' ] # TODO: remove after nilearn v0.9 release @@ -12,7 +12,7 @@ warnings.filterwarnings('ignore', message='Fetchers from the nilearn.datasets', category=FutureWarning) -from .atlases import (fetch_all_atlases, fetch_atlas, fetch_civet, # noqa +from .atlases import (fetch_all_atlases, fetch_atlas, fetch_bigbrain, fetch_civet, # noqa fetch_fsaverage, fetch_fslr, fetch_mni152, fetch_regfusion, get_atlas_dir, DENSITIES, ALIAS) from .annotations import (available_annotations, available_tags, # noqa diff --git a/neuromaps/datasets/atlases.py b/neuromaps/datasets/atlases.py index 312cf190..2d7301f2 100644 --- a/neuromaps/datasets/atlases.py +++ b/neuromaps/datasets/atlases.py @@ -13,13 +13,14 @@ SURFACE = namedtuple('Surface', ('L', 'R')) ALIAS = dict( fslr='fsLR', fsavg='fsaverage', mni152='MNI152', mni='MNI152', - FSLR='fsLR', CIVET='civet' + FSLR='fsLR', CIVET='civet', bigbrain='BigBrain' ) DENSITIES = dict( civet=['41k', '164k'], fsaverage=['3k', '10k', '41k', '164k'], fsLR=['4k', '8k', '32k', '164k'], MNI152=['1mm', '2mm', '3mm'], + BigBrain=['164k'] ) @@ -197,6 +198,30 @@ def fetch_fslr(density='32k', url=None, data_dir=None, verbose=1): # noqa: D103 """.format(**_atlas_docs, densities="', '".join(DENSITIES['fsLR'])) +def fetch_bigbrain(density='164k', url=None, data_dir=None, verbose=1): + keys = ['white', 'pial'] + return _fetch_atlas( + 'BigBrain', density, keys, url=url, data_dir=data_dir, verbose=verbose + ) + + +fetch_bigbrain.__doc__ = """ +Fetch BigBrain surface atlas. + +Parameters +---------- +density : {{'{densities}'}}, optional + Density of BigBrain atlas to fetch. Default: '164k' +{url} +{data_dir} +{verbose} + +Returns +------- +{surfatlas} +""".format(**_atlas_docs, densities="', '".join(DENSITIES['BigBrain'])) + + def fetch_mni152(density='1mm', url=None, data_dir=None, verbose=1): # noqa: D103 keys = ['2009cAsym_T1w', '2009cAsym_T2w', '2009cAsym_PD', '2009cAsym_brainmask', '2009cAsym_CSF', '2009cAsym_GM', diff --git a/neuromaps/datasets/data/osf.json b/neuromaps/datasets/data/osf.json index 3f24dab6..021c47d0 100644 --- a/neuromaps/datasets/data/osf.json +++ b/neuromaps/datasets/data/osf.json @@ -1,4 +1,13 @@ { + "BigBrain": { + "164k": { + "url": [ + "4mw3a", + "65c2aa433280d809e3a3aead" + ], + "md5": "af5e44a36f3d6d0e58d43f0822998c49" + } + }, "civet": { "41k": { "url": [ diff --git a/neuromaps/transforms.py b/neuromaps/transforms.py index cddd03f2..e233efbe 100644 --- a/neuromaps/transforms.py +++ b/neuromaps/transforms.py @@ -619,3 +619,118 @@ def fsaverage_to_fsaverage(data, target_density='41k', hemi=None, srcparams = dict(space='fsaverage', den=density, trg='') trgparams = dict(space='fsaverage', den=target_density, trg='') return _surf_to_surf(data, srcparams, trgparams, method, hemi) + + +def bigbrain_to_fslr(data, target_density='164k', hemi=None, method='linear'): + """ + Resample `data` on the BigBrain surface to the fsLR surface. + + Parameters + ---------- + data : str or os.PathLike or nib.GiftiImage or tuple + Input BigBrain data to be resampled + target_density : {'4k', '8k', '32k', '164k'}, optional + Desired density of output surface. Default: '164k' + hemi : {'L', 'R'}, optional + If `data` is not a tuple this specifies the hemisphere the data are + representing. Default: None + method : {'nearest', 'linear'}, optional + Method for resampling. Specify 'nearest' if `data` are label images. + Default: 'linear' + + Returns + ------- + resampled : tuple-of-nib.GiftiImage + Input `data` resampled to new density + """ + density, = _estimate_density((data,), hemi=hemi) + srcparams = dict(space='BigBrain', den=density, trg='_space-fsLR') + trgparams = dict(space='fsLR', den=target_density, trg='') + return _surf_to_surf(data, srcparams, trgparams, method, hemi) + + +def bigbrain_to_fsaverage(data, target_density='164k', hemi=None, + method='linear'): + """ + Resample `data` on the BigBrain surface to the fsaverage surface. + + Parameters + ---------- + data : str or os.PathLike or nib.GiftiImage or tuple + Input BigBrain data to be resampled + target_density : {'3k', '10k', '41k', '164k'}, optional + Desired density of output surface. Default: '164k' + hemi : {'L', 'R'}, optional + If `data` is not a tuple this specifies the hemisphere the data are + representing. Default: None + method : {'nearest', 'linear'}, optional + Method for resampling. Specify 'nearest' if `data` are label images. + Default: 'linear' + + Returns + ------- + resampled : tuple-of-nib.GiftiImage + Input `data` resampled to new density + """ + density, = _estimate_density((data,), hemi=hemi) + srcparams = dict(space='BigBrain', den=density, trg='_space-fsaverage') + trgparams = dict(space='fsaverage', den=target_density, trg='') + return _surf_to_surf(data, srcparams, trgparams, method, hemi) + + +def fsaverage_to_bigbrain(data, target_density='164k', hemi=None, + method='linear'): + """ + Resample `data` on fsLR surface to new density. + + Parameters + ---------- + data : str or os.PathLike or nib.GiftiImage or tuple + Input BigBrain data to be resampled + target_density : {'164k'}, optional + Desired density of output surface. Default: '164k' + hemi : {'L', 'R'}, optional + If `data` is not a tuple this specifies the hemisphere the data are + representing. Default: None + method : {'nearest', 'linear'}, optional + Method for resampling. Specify 'nearest' if `data` are label images. + Default: 'linear' + + Returns + ------- + resampled : tuple-of-nib.GiftiImage + Input `data` resampled to new density + """ + density, = _estimate_density((data,), hemi=hemi) + srcparams = dict(space='fsaverage', den=density, trg='') + trgparams = dict(space='BigBrain', den=target_density, + trg='_space-fsaverage') + return _surf_to_surf(data, srcparams, trgparams, method, hemi) + + +def fslr_to_bigbrain(data, target_density='164k', hemi=None, method='linear'): + """ + Resample `data` on fsLR surface to new density. + + Parameters + ---------- + data : str or os.PathLike or nib.GiftiImage or tuple + Input BigBrain data to be resampled + target_density : {'164k'}, optional + Desired density of output surface. Default: '164k' + hemi : {'L', 'R'}, optional + If `data` is not a tuple this specifies the hemisphere the data are + representing. Default: None + method : {'nearest', 'linear'}, optional + Method for resampling. Specify 'nearest' if `data` are label images. + Default: 'linear' + + Returns + ------- + resampled : tuple-of-nib.GiftiImage + Input `data` resampled to new density + """ + density, = _estimate_density((data,), hemi=hemi) + srcparams = dict(space='fsLR', den=density, trg='') + trgparams = dict(space='BigBrain', den=target_density, trg='_space-fsLR') + return _surf_to_surf(data, srcparams, trgparams, method, hemi)