Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENH] Add BigBrain atlas and transformations #150

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions neuromaps/datasets/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
"""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
import warnings
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
Expand Down
27 changes: 26 additions & 1 deletion neuromaps/datasets/atlases.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
)


Expand Down Expand Up @@ -197,6 +198,30 @@
""".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
)


Check warning on line 207 in neuromaps/datasets/atlases.py

View check run for this annotation

Codecov / codecov/patch

neuromaps/datasets/atlases.py#L206-L207

Added lines #L206 - L207 were not covered by tests
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',
Expand Down
9 changes: 9 additions & 0 deletions neuromaps/datasets/data/osf.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
{
"BigBrain": {
"164k": {
"url": [
"4mw3a",
"65c2aa433280d809e3a3aead"
],
"md5": "af5e44a36f3d6d0e58d43f0822998c49"
}
},
"civet": {
"41k": {
"url": [
Expand Down
115 changes: 115 additions & 0 deletions neuromaps/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,3 +619,118 @@
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)

Check warning on line 649 in neuromaps/transforms.py

View check run for this annotation

Codecov / codecov/patch

neuromaps/transforms.py#L646-L649

Added lines #L646 - L649 were not covered by tests


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)

Check warning on line 678 in neuromaps/transforms.py

View check run for this annotation

Codecov / codecov/patch

neuromaps/transforms.py#L675-L678

Added lines #L675 - L678 were not covered by tests


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,

Check warning on line 706 in neuromaps/transforms.py

View check run for this annotation

Codecov / codecov/patch

neuromaps/transforms.py#L704-L706

Added lines #L704 - L706 were not covered by tests
trg='_space-fsaverage')
return _surf_to_surf(data, srcparams, trgparams, method, hemi)

Check warning on line 708 in neuromaps/transforms.py

View check run for this annotation

Codecov / codecov/patch

neuromaps/transforms.py#L708

Added line #L708 was not covered by tests


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)

Check warning on line 736 in neuromaps/transforms.py

View check run for this annotation

Codecov / codecov/patch

neuromaps/transforms.py#L733-L736

Added lines #L733 - L736 were not covered by tests
Loading