@@ -2860,6 +2860,16 @@ def _temporary_vertices(src, vertices):
2860
2860
s ['vertno' ] = v
2861
2861
2862
2862
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
+
2863
2873
def _prepare_label_extraction (stc , labels , src , mode , allow_empty , use_sparse ):
2864
2874
"""Prepare indices and flips for extract_label_time_course."""
2865
2875
# 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):
2872
2882
2873
2883
# if source estimate provided in stc, get vertices from source space and
2874
2884
# 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
2887
2887
nvert = [len (vn ) for vn in vertno ]
2888
2888
2889
2889
# initialization
@@ -3059,15 +3059,30 @@ def _dep_trans(trans):
3059
3059
'pass it as an argument' , DeprecationWarning )
3060
3060
3061
3061
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
+
3062
3074
def _gen_extract_label_time_course (stcs , labels , src , mode = 'mean' ,
3063
3075
allow_empty = False , trans = None ,
3064
3076
mri_resolution = True , verbose = None ):
3065
3077
# 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
3066
3083
_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 ())
3069
3085
3070
- kind = src .kind
3071
3086
if kind in ('surface' , 'mixed' ):
3072
3087
if not isinstance (labels , list ):
3073
3088
labels = [labels ]
@@ -3082,11 +3097,11 @@ def _gen_extract_label_time_course(stcs, labels, src, mode='mean',
3082
3097
for si , stc in enumerate (stcs ):
3083
3098
_validate_type (stc , _BaseSourceEstimate , 'stcs[%d]' % (si ,),
3084
3099
'source estimate' )
3100
+ _check_option (
3101
+ 'mode' , mode , _get_allowed_label_modes (stc ),
3102
+ 'when using a vector and/or volume source estimate' )
3085
3103
if isinstance (stc , (_BaseVolSourceEstimate ,
3086
3104
_BaseVectorSourceEstimate )):
3087
- _check_option (
3088
- 'mode' , mode , ('mean' , 'max' , 'auto' ),
3089
- 'when using a vector and/or volume source estimate' )
3090
3105
mode = 'mean' if mode == 'auto' else mode
3091
3106
else :
3092
3107
mode = 'mean_flip' if mode == 'auto' else mode
0 commit comments