12
12
from collections .abc import Iterable
13
13
from logging import getLogger
14
14
15
- from numpy import (arange , array , asarray , diff , empty , hstack , inf ,
16
- issubsctype , linspace , nan_to_num , ndarray , ones , ravel ,
15
+ from numpy import (arange , array , asarray , diff , empty , hstack , inf ,
16
+ linspace , nan_to_num , ndarray , ones , ravel ,
17
17
setdiff1d , floor )
18
18
from numpy .lib .stride_tricks import as_strided
19
19
from math import isclose
@@ -78,7 +78,7 @@ def read_data(self, chan=[], ref_chan=[], grp_name=None, concat_chan=False,
78
78
concat_chan : bool
79
79
if True, data from all channels will be concatenated
80
80
average_channels : bool
81
- if True, all channels will be averaged into a single virtual
81
+ if True, all channels will be averaged into a single virtual
82
82
channel with label 'avg_chan'
83
83
max_s_freq: : int
84
84
maximum sampling frequency
@@ -121,7 +121,7 @@ def read_data(self, chan=[], ref_chan=[], grp_name=None, concat_chan=False,
121
121
t0 , t1 ))
122
122
active_chan = chan if chan else [seg ['chan' ].split (' (' )[0 ]]
123
123
if isinstance (active_chan , str ):
124
- active_chan = [active_chan ]
124
+ active_chan = [active_chan ]
125
125
chan_to_read = active_chan + ref_chan
126
126
127
127
data = self .dataset .read_data (chan = chan_to_read , begtime = t0 ,
@@ -154,7 +154,7 @@ def read_data(self, chan=[], ref_chan=[], grp_name=None, concat_chan=False,
154
154
[x (chan = ch )[0 ] for x in subseg ])
155
155
156
156
if average_channels :
157
- one_segment .data [0 ] = one_segment .data [0 ].mean (0 ,
157
+ one_segment .data [0 ] = one_segment .data [0 ].mean (0 ,
158
158
keepdims = True )
159
159
one_segment .axis ['chan' ][0 ] = array (['avg_chan' ], dtype = '<U2' )
160
160
active_chan = ['avg_chan' ]
@@ -248,7 +248,7 @@ def select(data, trial=None, invert=False, **axes_to_select):
248
248
selected_values = asarray (values_to_select , dtype = 'U' )
249
249
250
250
else :
251
- if isinstance (values_to_select , ndarray ) and issubsctype (values_to_select .dtype , bool ):
251
+ if isinstance (values_to_select , ndarray ) and issubclass (values_to_select .dtype , bool ):
252
252
bool_values = values_to_select
253
253
elif (values_to_select [0 ] is None and
254
254
values_to_select [1 ] is None ):
@@ -325,7 +325,7 @@ def resample(data, s_freq, axis='time'):
325
325
return output
326
326
327
327
328
- def smart_chan (dataset , simple_chan_name , test_chan = None ):
328
+ def smart_chan (dataset , simple_chan_name , test_chan = None ):
329
329
"""From a list of simple channel names, attempts to find the corresponding
330
330
channel names in the dataset and returns a list (with same order).
331
331
Parameters
@@ -334,19 +334,19 @@ def smart_chan(dataset, simple_chan_name, test_chan=None):
334
334
info about record
335
335
simple_chan_name : list of str
336
336
simple names for channels, e.g. ['F3', 'Fp2', 'ECG']
337
-
337
+
338
338
Returns
339
339
-------
340
340
list
341
341
corresponding channel labels as they appear in dataset
342
342
"""
343
343
chan_key = {}
344
-
344
+
345
345
if test_chan is None :
346
346
orig_chan_name = dataset .header ['chan_name' ]
347
347
else :
348
348
orig_chan_name = test_chan
349
-
349
+
350
350
for s in simple_chan_name :
351
351
# look for exact matches
352
352
candidates = [x for x in orig_chan_name if s == x ]
@@ -356,9 +356,9 @@ def smart_chan(dataset, simple_chan_name, test_chan=None):
356
356
elif len (candidates ) > 1 :
357
357
raise ValueError ( f'The record contains { len (candidates )} '
358
358
f'duplicates of channel label { s } ' )
359
-
359
+
360
360
# look for s in first position
361
- candidates = [x for x in orig_chan_name if s == x [:min (len (s ),
361
+ candidates = [x for x in orig_chan_name if s == x [:min (len (s ),
362
362
len (x ))]]
363
363
if len (candidates ) == 1 :
364
364
chan_key [s ] = candidates [0 ]
@@ -367,7 +367,7 @@ def smart_chan(dataset, simple_chan_name, test_chan=None):
367
367
# s appears in first position more than once
368
368
raise ValueError (
369
369
f'Too many candidates corresponding to { s } : { candidates } ' )
370
-
370
+
371
371
# look for unique occurrences of s somewhere in chan label
372
372
candidates = [x for x in orig_chan_name if s in x ]
373
373
if len (candidates ) == 1 :
@@ -383,7 +383,7 @@ def smart_chan(dataset, simple_chan_name, test_chan=None):
383
383
raise ValueError (
384
384
f'Too many candidates corresponding to { s } : { candidates } ' )
385
385
raise ValueError (f'Unable to find channel containing { s } ' )
386
-
386
+
387
387
return [chan_key [x ] for x in simple_chan_name ]
388
388
389
389
0 commit comments