Skip to content

Commit 957556e

Browse files
MRG: Plot label time course with Brain (#8335)
* Follow Brain update * Upload prototype * Remove 'tube' borders * Rename variables * Update clear_glyphs() * Use _brain_color * Fix docstring * Improve support of traces and update tests * Introduce _configure_label_time_course * Add label tool bar * Add support for max mode * Refactor _update * Add support for src * Remove GFP in label picking mode * Plot time line * Fetch src when possible * Update overview table * Use only src_vol * TST: refactor _triage_stc out * Use _check_stc * Fix test_brain_init[mayavi] * Fix test_brain_traces[pyvista-mixed] * Disable annot traces for volume/mixed * Uncomment stc ValueError * Improve testing and fix label_name * Improve API * Improve testing * Improve testing * Fix add_data parameter * Improve coverage * Use dict for label_data * Prototype with show_traces * Add _read_annot_cands * Configure UI for traces mode toggle * Organize signals, clear memory and update tests * Switch to simplified interface * Exclude .ctab files * Improve coverage * Update overview table * Improve coverage * Remove cruft * Improve coverage * Improve coverage * Improve coverage * Improve coverage * Remove cruft * Improve coverage * Improve coverage * TST: Hide app window during testing * Revert "TST: Hide app window during testing" This reverts commit f513448. * Refactor tests * Fix default annot bug * Fix renderer bug * Test GHA skipping [skip ci] * Synchronize branch * Fix test_resolution_matrix * Add _configure_trace_mode * Improve read_annot_cands * Simplify annot mode color * Remove cruft * Add _check_stc_src * Cast to int64 * Add support for vec * Add support for mixed * Do not show trace mode for volumes * Update tests * Fix vec * Test mixed too * Update tests * Cleanup * Trigger Circle [circle front] * Cover vol as well * Update tests * Add vector to the list * Fix style * Restore label name * Exclude pca_flip * DRY * Update _add_vertex_glyph with render parameter
1 parent 894606e commit 957556e

File tree

7 files changed

+456
-143
lines changed

7 files changed

+456
-143
lines changed

mne/label.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1880,7 +1880,8 @@ def _read_annot_cands(dir_name):
18801880
raise IOError('Directory for annotation does not exist: %s',
18811881
dir_name)
18821882
cands = os.listdir(dir_name)
1883-
cands = sorted(set(c.lstrip('lh.').lstrip('rh.').rstrip('.annot')
1883+
cands = sorted(set(c.replace('lh.', '').replace('rh.', '').replace(
1884+
'.annot', '')
18841885
for c in cands if '.annot' in c),
18851886
key=lambda x: x.lower())
18861887
# exclude .ctab files

mne/source_estimate.py

+33-18
Original file line numberDiff line numberDiff line change
@@ -2860,6 +2860,16 @@ def _temporary_vertices(src, vertices):
28602860
s['vertno'] = v
28612861

28622862

2863+
def _check_stc_src(stc, src):
2864+
if stc is not None and src is not None:
2865+
for s, v, hemi in zip(src, stc.vertices, ('left', 'right')):
2866+
n_missing = (~np.in1d(v, s['vertno'])).sum()
2867+
if n_missing:
2868+
raise ValueError('%d/%d %s hemisphere stc vertices '
2869+
'missing from the source space, likely '
2870+
'mismatch' % (n_missing, len(v), hemi))
2871+
2872+
28632873
def _prepare_label_extraction(stc, labels, src, mode, allow_empty, use_sparse):
28642874
"""Prepare indices and flips for extract_label_time_course."""
28652875
# If src is a mixed src space, the first 2 src spaces are surf type and
@@ -2872,18 +2882,8 @@ def _prepare_label_extraction(stc, labels, src, mode, allow_empty, use_sparse):
28722882

28732883
# if source estimate provided in stc, get vertices from source space and
28742884
# check that they are the same as in the stcs
2875-
if stc is not None:
2876-
vertno = stc.vertices
2877-
2878-
for s, v, hemi in zip(src, stc.vertices, ('left', 'right')):
2879-
n_missing = (~np.in1d(v, s['vertno'])).sum()
2880-
if n_missing:
2881-
raise ValueError('%d/%d %s hemisphere stc vertices missing '
2882-
'from the source space, likely mismatch'
2883-
% (n_missing, len(v), hemi))
2884-
else:
2885-
vertno = [s['vertno'] for s in src]
2886-
2885+
_check_stc_src(stc, src)
2886+
vertno = [s['vertno'] for s in src] if stc is None else stc.vertices
28872887
nvert = [len(vn) for vn in vertno]
28882888

28892889
# initialization
@@ -3059,15 +3059,30 @@ def _dep_trans(trans):
30593059
'pass it as an argument', DeprecationWarning)
30603060

30613061

3062+
def _get_default_label_modes():
3063+
return sorted(_label_funcs.keys()) + ['auto']
3064+
3065+
3066+
def _get_allowed_label_modes(stc):
3067+
if isinstance(stc, (_BaseVolSourceEstimate,
3068+
_BaseVectorSourceEstimate)):
3069+
return ('mean', 'max', 'auto')
3070+
else:
3071+
return _get_default_label_modes()
3072+
3073+
30623074
def _gen_extract_label_time_course(stcs, labels, src, mode='mean',
30633075
allow_empty=False, trans=None,
30643076
mri_resolution=True, verbose=None):
30653077
# loop through source estimates and extract time series
3078+
if src is None and mode in ['mean', 'max']:
3079+
kind = 'surface'
3080+
else:
3081+
_validate_type(src, SourceSpaces)
3082+
kind = src.kind
30663083
_dep_trans(trans)
3067-
_validate_type(src, SourceSpaces)
3068-
_check_option('mode', mode, sorted(_label_funcs.keys()) + ['auto'])
3084+
_check_option('mode', mode, _get_default_label_modes())
30693085

3070-
kind = src.kind
30713086
if kind in ('surface', 'mixed'):
30723087
if not isinstance(labels, list):
30733088
labels = [labels]
@@ -3082,11 +3097,11 @@ def _gen_extract_label_time_course(stcs, labels, src, mode='mean',
30823097
for si, stc in enumerate(stcs):
30833098
_validate_type(stc, _BaseSourceEstimate, 'stcs[%d]' % (si,),
30843099
'source estimate')
3100+
_check_option(
3101+
'mode', mode, _get_allowed_label_modes(stc),
3102+
'when using a vector and/or volume source estimate')
30853103
if isinstance(stc, (_BaseVolSourceEstimate,
30863104
_BaseVectorSourceEstimate)):
3087-
_check_option(
3088-
'mode', mode, ('mean', 'max', 'auto'),
3089-
'when using a vector and/or volume source estimate')
30903105
mode = 'mean' if mode == 'auto' else mode
30913106
else:
30923107
mode = 'mean_flip' if mode == 'auto' else mode

mne/viz/_3d.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1789,7 +1789,8 @@ def plot_source_estimates(stc, subject=None, surface='inflated', hemi='lh',
17891789
- https://openwetware.org/wiki/Beauchamp:FreeSurfer
17901790
""" # noqa: E501
17911791
from .backends.renderer import _get_3d_backend, set_3d_backend
1792-
from ..source_estimate import _BaseSourceEstimate
1792+
from ..source_estimate import _BaseSourceEstimate, _check_stc_src
1793+
_check_stc_src(stc, src)
17931794
_validate_type(stc, _BaseSourceEstimate, 'stc', 'source estimate')
17941795
subjects_dir = get_subjects_dir(subjects_dir=subjects_dir,
17951796
raise_error=True)
@@ -1989,7 +1990,8 @@ def _plot_stc(stc, subject, surface, hemi, colormap, time_label,
19891990
_check_option('time_viewer', time_viewer, (True, False, 'auto'))
19901991
_validate_type(show_traces, (str, bool, 'numeric'), 'show_traces')
19911992
if isinstance(show_traces, str):
1992-
_check_option('show_traces', show_traces, ('auto', 'separate'),
1993+
_check_option('show_traces', show_traces,
1994+
('auto', 'separate', 'vertex', 'label'),
19931995
extra='when a string')
19941996
if time_viewer == 'auto':
19951997
time_viewer = not using_mayavi

0 commit comments

Comments
 (0)