@@ -933,8 +933,9 @@ def __setitem__(self, item, value):
933
933
# set the data
934
934
self ._data [sel , start :stop ] = value
935
935
936
+ @verbose
936
937
def get_data (self , picks = None , start = 0 , stop = None ,
937
- reject_by_annotation = None , return_times = False ):
938
+ reject_by_annotation = None , return_times = False , verbose = None ):
938
939
"""Get data in the given range.
939
940
940
941
Parameters
@@ -953,6 +954,10 @@ def get_data(self, picks=None, start=0, stop=None,
953
954
'bad' are omitted. If 'NaN', the bad samples are filled with NaNs.
954
955
return_times : bool
955
956
Whether to return times as well. Defaults to False.
957
+ verbose : bool, str, int, or None
958
+ If not None, override default verbose level (see
959
+ :func:`mne.verbose` and :ref:`Logging documentation <tut_logging>`
960
+ for more). Defaults to self.verbose.
956
961
957
962
Returns
958
963
-------
@@ -985,29 +990,43 @@ def get_data(self, picks=None, start=0, stop=None,
985
990
if return_times :
986
991
return data , times
987
992
return data
988
-
989
- used = np .ones (stop - start , bool )
993
+ n_samples = stop - start # total number of samples
994
+ used = np .ones (n_samples , bool )
990
995
for onset , end in zip (onsets , ends ):
991
996
if onset >= end :
992
997
continue
993
998
used [onset - start : end - start ] = False
994
999
used = np .concatenate ([[False ], used , [False ]])
995
1000
starts = np .where (~ used [:- 1 ] & used [1 :])[0 ] + start
996
1001
stops = np .where (used [:- 1 ] & ~ used [1 :])[0 ] + start
997
- if reject_by_annotation == 'omit' :
998
-
999
- data = np .zeros ((len (picks ), (stops - starts ).sum ()))
1000
- times = np .zeros (data .shape [1 ])
1001
- idx = 0
1002
- for start , stop in zip (starts , stops ): # get the data
1003
- if start == stop :
1004
- continue
1005
- end = idx + stop - start
1006
- data [:, idx :end ], times [idx :end ] = self [picks , start :stop ]
1007
- idx = end
1002
+ n_kept = (stops - starts ).sum () # kept samples
1003
+ n_rejected = n_samples - n_kept # rejected samples
1004
+ if n_rejected > 0 :
1005
+ if reject_by_annotation == 'omit' :
1006
+ msg = ("Omitting {} of {} ({:.2%}) samples, retaining {}"
1007
+ " ({:.2%}) samples." )
1008
+ logger .info (msg .format (n_rejected , n_samples ,
1009
+ n_rejected / n_samples ,
1010
+ n_kept , n_kept / n_samples ))
1011
+ data = np .zeros ((len (picks ), n_kept ))
1012
+ times = np .zeros (data .shape [1 ])
1013
+ idx = 0
1014
+ for start , stop in zip (starts , stops ): # get the data
1015
+ if start == stop :
1016
+ continue
1017
+ end = idx + stop - start
1018
+ data [:, idx :end ], times [idx :end ] = self [picks , start :stop ]
1019
+ idx = end
1020
+ else :
1021
+ msg = ("Setting {} of {} ({:.2%}) samples to NaN, retaining {}"
1022
+ " ({:.2%}) samples." )
1023
+ logger .info (msg .format (n_rejected , n_samples ,
1024
+ n_rejected / n_samples ,
1025
+ n_kept , n_kept / n_samples ))
1026
+ data , times = self [picks , start :stop ]
1027
+ data [:, ~ used [1 :- 1 ]] = np .nan
1008
1028
else :
1009
1029
data , times = self [picks , start :stop ]
1010
- data [:, ~ used [1 :- 1 ]] = np .nan
1011
1030
1012
1031
if return_times :
1013
1032
return data , times
0 commit comments