Skip to content

Commit 46fdb31

Browse files
authored
Merge pull request #103 from VinceBaz/master
Added plot_fslr() function and a yerkes19 fetcher
2 parents 258fa0f + 2202b33 commit 46fdb31

File tree

5 files changed

+160
-10
lines changed

5 files changed

+160
-10
lines changed

netneurotools/data/osf.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@
7676
],
7777
"md5": "bd944e3f9f343e0e51e562b440960529"
7878
},
79+
"tpl-yerkes19": {
80+
"url": [
81+
"mb37e",
82+
"60ae93d504e91a005f1761ab"
83+
],
84+
"md5": "9ee4f1605fb690a85b04b61549d62925"
85+
},
7986
"tpl-fsaverage": {
8087
"fsaverage": {
8188
"url": [

netneurotools/datasets/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
]
1111

1212
from .fetchers import (fetch_cammoun2012, fetch_pauli2018, fetch_fsaverage,
13-
fetch_conte69, fetch_connectome, available_connectomes,
14-
fetch_vazquez_rodriguez2019, fetch_schaefer2018,
15-
fetch_hcp_standards, fetch_voneconomo, fetch_mmpall,
16-
fetch_civet)
13+
fetch_conte69, fetch_yerkes19, fetch_connectome,
14+
available_connectomes, fetch_vazquez_rodriguez2019,
15+
fetch_schaefer2018, fetch_hcp_standards,
16+
fetch_voneconomo, fetch_mmpall, fetch_civet)
1717
from .generators import (make_correlated_xy)
1818
from .mirchi import (fetch_mirchi2018)

netneurotools/datasets/fetchers.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,75 @@ def fetch_conte69(data_dir=None, url=None, resume=True, verbose=1):
217217
return Bunch(**dict(zip(keys + ['info'], data)))
218218

219219

220+
def fetch_yerkes19(data_dir=None, url=None, resume=None, verbose=1):
221+
"""
222+
Downloads files for Donahue et al., 2016 Yerkes19 template
223+
224+
Parameters
225+
----------
226+
data_dir : str, optional
227+
Path to use as data directory. If not specified, will check for
228+
environmental variable 'NNT_DATA'; if that is not set, will use
229+
`~/nnt-data` instead. Default: None
230+
url : str, optional
231+
URL from which to download data. Default: None
232+
resume : bool, optional
233+
Whether to attempt to resume partial download, if possible. Default:
234+
True
235+
verbose : int, optional
236+
Modifies verbosity of download, where higher numbers mean more updates.
237+
Default: 1
238+
239+
Returns
240+
-------
241+
filenames : :class:`sklearn.utils.Bunch`
242+
Dictionary-like object with keys ['midthickness', 'inflated',
243+
'vinflated'], where corresponding values are lists of filepaths to
244+
downloaded template files.
245+
246+
References
247+
----------
248+
https://balsa.wustl.edu/reference/show/976nz
249+
250+
Donahue, C. J., Sotiropoulos, S. N., Jbabdi, S., Hernandez-Fernandez, M.,
251+
Behrens, T. E., Dyrby, T. B., ... & Glasser, M. F. (2016). Using diffusion
252+
tractography to predict cortical connection strength and distance: a
253+
quantitative comparison with tracers in the monkey. Journal of
254+
Neuroscience, 36(25), 6758-6770.
255+
256+
Notes
257+
-----
258+
License: ???
259+
"""
260+
261+
dataset_name = 'tpl-yerkes19'
262+
keys = ['midthickness', 'inflated', 'vinflated']
263+
264+
data_dir = _get_data_dir(data_dir=data_dir)
265+
info = _get_dataset_info(dataset_name)
266+
if url is None:
267+
url = info['url']
268+
269+
opts = {
270+
'uncompress': True,
271+
'md5sum': info['md5'],
272+
'move': '{}.tar.gz'.format(dataset_name)
273+
}
274+
275+
filenames = [
276+
'tpl-yerkes19/tpl-yerkes19_space-fsLR32k_{}.{}.surf.gii'
277+
.format(res, hemi) for res in keys for hemi in ['L', 'R']
278+
]
279+
280+
data = _fetch_files(data_dir, files=[(f, url, opts) for f in filenames],
281+
resume=resume, verbose=verbose)
282+
283+
# bundle hemispheres together
284+
data = [SURFACE(*data[i:i + 2]) for i in range(0, 6, 2)]
285+
286+
return Bunch(**dict(zip(keys + ['info'], data)))
287+
288+
220289
def fetch_pauli2018(data_dir=None, url=None, resume=True, verbose=1):
221290
"""
222291
Downloads files for Pauli et al., 2018 subcortical parcellation

netneurotools/plotting.py

Lines changed: 74 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -258,37 +258,105 @@ def plot_conte69(data, lhlabel, rhlabel, surf='midthickness',
258258
Default: (0, 0, 0)
259259
kwargs : key-value mapping
260260
Keyword arguments for `mayavi.mlab.triangular_mesh()`
261+
Returns
262+
-------
263+
scene : mayavi.Scene
264+
Scene object containing plot
265+
"""
266+
267+
return plot_fslr(data, lhlabel, rhlabel, surf_atlas='conte69',
268+
surf_type=surf, vmin=vmin, vmax=vmax, colormap=colormap,
269+
colorbar=colorbar, num_labels=num_labels,
270+
orientation=orientation, colorbartitle=colorbartitle,
271+
backgroundcolor=backgroundcolor,
272+
foregroundcolor=foregroundcolor, **kwargs)
273+
274+
275+
def plot_fslr(data, lhlabel, rhlabel, surf_atlas='conte69',
276+
surf_type='midthickness', vmin=None, vmax=None,
277+
colormap='viridis', colorbar=True, num_labels=4,
278+
orientation='horizontal', colorbartitle=None,
279+
backgroundcolor=(1, 1, 1), foregroundcolor=(0, 0, 0),
280+
**kwargs):
281+
282+
"""
283+
Plots surface `data` on a given fsLR32k atlas
284+
285+
Parameters
286+
----------
287+
data : (N,) array_like
288+
Surface data for N parcels
289+
lhlabel : str
290+
Path to .gii file (generic GIFTI file) containing labels to N/2 parcels
291+
on the left hemisphere
292+
rhlabel : str
293+
Path to .gii file (generic GIFTI file) containing labels to N/2 parcels
294+
on the right hemisphere
295+
surf_atlas: {'conte69', 'yerkes19'}, optional
296+
Surface atlas on which to plot 'data'. Default: 'conte69'
297+
surf_type : {'midthickness', 'inflated', 'vinflated'}, optional
298+
Type of brain surface. Default: 'midthickness'
299+
vmin : float, optional
300+
Minimum value to scale the colormap. If None, the min of the data will
301+
be used. Default: None
302+
vmax : float, optional
303+
Maximum value to scale the colormap. If None, the max of the data will
304+
be used. Default: None
305+
colormap : str, optional
306+
Any colormap from matplotlib. Default: 'viridis'
307+
colorbar : bool, optional
308+
Wheter to display a colorbar. Default: True
309+
num_labels : int, optional
310+
The number of labels to display on the colorbar.
311+
Available only if colorbar=True. Default: 4
312+
orientation : str, optional
313+
Defines the orientation of colorbar. Can be 'horizontal' or 'vertical'.
314+
Available only if colorbar=True. Default: 'horizontal'
315+
colorbartitle : str, optional
316+
The title of colorbar. Available only if colorbar=True. Default: None
317+
backgroundcolor : tuple of float values with RGB code in [0, 1], optional
318+
Defines the background color. Default: (1, 1, 1)
319+
foregroundcolor : tuple of float values with RGB code in [0, 1], optional
320+
Defines the foreground color (e.g., colorbartitle color).
321+
Default: (0, 0, 0)
322+
kwargs : key-value mapping
323+
Keyword arguments for `mayavi.mlab.triangular_mesh()`
261324
262325
Returns
263326
-------
264327
scene : mayavi.Scene
265328
Scene object containing plot
266329
"""
267330

268-
from .datasets import fetch_conte69
331+
from .datasets import fetch_conte69, fetch_yerkes19
269332
try:
270333
from mayavi import mlab
271334
except ImportError:
272-
raise ImportError('Cannot use plot_conte69() if mayavi is not '
335+
raise ImportError('Cannot use plot_fslr() if mayavi is not '
273336
'installed. Please install mayavi and try again.')
274337

275338
opts = dict()
276339
opts.update(**kwargs)
277340

278341
try:
279-
surface = fetch_conte69()[surf]
342+
if surf_atlas == 'conte69':
343+
surface = fetch_conte69()[surf_type]
344+
elif surf_atlas == 'yerkes19':
345+
surface = fetch_yerkes19()[surf_type]
346+
280347
except KeyError:
281348
raise ValueError('Provided surf "{}" is not valid. Must be one of '
282349
'[\'midthickness\', \'inflated\', \'vinflated\']'
283-
.format(surf))
350+
.format(surf_type))
351+
284352
lhsurface, rhsurface = [nib.load(s) for s in surface]
285353

286354
lhlabels = nib.load(lhlabel).darrays[0].data
287355
rhlabels = nib.load(rhlabel).darrays[0].data
288356
lhvert, lhface = [d.data for d in lhsurface.darrays]
289357
rhvert, rhface = [d.data for d in rhsurface.darrays]
290358

291-
# add NaNs for subcortex
359+
# add NaNs for medial wall
292360
data = np.append(np.nan, data)
293361

294362
# get lh and rh data
@@ -510,7 +578,7 @@ def plot_fsaverage(data, *, lhannot, rhannot, order='lr', mask=None,
510578

511579
vtx_data.append(vtx)
512580

513-
brain = plot_fsvertex(np.hstack(vtx_data), order=order, mask=None,
581+
brain = plot_fsvertex(np.hstack(vtx_data), order='lr', mask=None,
514582
subject_id=subject_id, subjects_dir=subjects_dir,
515583
vmin=vmin, vmax=vmax, **kwargs)
516584

netneurotools/tests/test_datasets.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ def test_fetch_conte69(tmpdir):
5252
['midthickness', 'inflated', 'vinflated', 'info'])
5353

5454

55+
def test_fetch_yerkes19(tmpdir):
56+
conte = datasets.fetch_yerkes19(data_dir=tmpdir, verbose=0)
57+
assert all(hasattr(conte, k) for k in
58+
['midthickness', 'inflated', 'vinflated'])
59+
60+
5561
def test_fetch_pauli2018(tmpdir):
5662
pauli = datasets.fetch_pauli2018(data_dir=tmpdir, verbose=0)
5763
assert all(hasattr(pauli, k) and os.path.isfile(pauli[k]) for k in

0 commit comments

Comments
 (0)