@@ -1619,6 +1619,8 @@ def _mt_spectrum_proc(
16191619 if filter_length is None :
16201620 filter_length = x .shape [- 1 ]
16211621 filter_length = min (_to_samples (filter_length , sfreq , "" , "" ), x .shape [- 1 ])
1622+ pick_mask = np .zeros (len (x ), dtype = bool )
1623+ pick_mask [picks ] = True
16221624 get_wt = partial (
16231625 _get_window_thresh , sfreq = sfreq , mt_bandwidth = mt_bandwidth , p_value = p_value
16241626 )
@@ -1627,7 +1629,7 @@ def _mt_spectrum_proc(
16271629 if n_jobs == 1 :
16281630 freq_list = list ()
16291631 for ii , x_ in enumerate (x ):
1630- if ii in picks :
1632+ if pick_mask [ ii ] :
16311633 x [ii ], f = _mt_spectrum_remove_win (
16321634 x_ , sfreq , line_freqs , notch_widths , window_fun , threshold , get_wt
16331635 )
@@ -1636,7 +1638,7 @@ def _mt_spectrum_proc(
16361638 data_new = parallel (
16371639 p_fun (x_ , sfreq , line_freqs , notch_widths , window_fun , threshold , get_wt )
16381640 for xi , x_ in enumerate (x )
1639- if xi in picks
1641+ if pick_mask [ xi ]
16401642 )
16411643 freq_list = [d [1 ] for d in data_new ]
16421644 data_new = np .array ([d [0 ] for d in data_new ])
@@ -1748,17 +1750,16 @@ def _mt_spectrum_remove(
17481750 indices = np .unique (np .r_ [indices_1 , indices_2 ])
17491751 rm_freqs = freqs [indices ]
17501752
1751- fits = list ()
1752- for ind in indices :
1753- c = 2 * A [0 , ind ]
1754- fit = np .abs (c ) * np .cos (freqs [ind ] * rads + np .angle (c ))
1755- fits .append (fit )
1756-
1757- if len (fits ) == 0 :
1753+ if len (indices ) == 0 :
17581754 datafit = 0.0
17591755 else :
1756+ c = 2 * A [0 , indices ]
17601757 # fitted sinusoids are summed, and subtracted from data
1761- datafit = np .sum (fits , axis = 0 )
1758+ datafit = np .sum (
1759+ np .abs (c )[:, np .newaxis ]
1760+ * np .cos (freqs [indices , np .newaxis ] * rads + np .angle (c )[:, np .newaxis ]),
1761+ axis = 0 ,
1762+ )
17621763
17631764 return x - datafit , rm_freqs
17641765
0 commit comments