11import numpy as np
2- import scipy .signal
32
43from spikeinterface .core .core_tools import define_function_handling_dict_from_class
54from .basepreprocessor import BasePreprocessor , BasePreprocessorSegment
@@ -34,8 +33,8 @@ class SilencedPeriodsRecording(BasePreprocessor):
3433 - "noise": The periods are filled with a gaussion noise that has the
3534 same variance that the one in the recordings, on a per channel
3635 basis
37- - "apodization": The periods zeroed, but are apodized with a cosine taper (using `apodization_factor `)
38- apodization_factor : int, default: 7
36+ - "apodization": The periods zeroed, but are apodized with a cosine taper (using `apodization_samples `)
37+ apodization_samples : int, default: 7
3938 The factor used for the cosine taper when mode is "apodization". Higher values create a wider taper.
4039 noise_levels : array
4140 Noise levels if already computed
@@ -57,7 +56,7 @@ def __init__(
5756 # this is kept for backward compatibility
5857 list_periods = None ,
5958 mode = "zeros" ,
60- apodization_factor = 7 ,
59+ apodization_samples = 7 ,
6160 noise_levels = None ,
6261 seed = None ,
6362 ** noise_levels_kwargs ,
@@ -120,7 +119,7 @@ def __init__(
120119 mode ,
121120 noise_generator ,
122121 seg_index ,
123- apodization_factor = apodization_factor ,
122+ apodization_samples = apodization_samples ,
124123 )
125124 self .add_recording_segment (rec_segment )
126125
@@ -130,7 +129,7 @@ def __init__(
130129 mode = mode ,
131130 seed = seed ,
132131 noise_levels = noise_levels ,
133- apodization_factor = apodization_factor ,
132+ apodization_samples = apodization_samples ,
134133 )
135134
136135
@@ -173,13 +172,13 @@ def _check_periods(periods, num_seg):
173172
174173
175174class SilencedPeriodsRecordingSegment (BasePreprocessorSegment ):
176- def __init__ (self , parent_recording_segment , periods , mode , noise_generator , seg_index , apodization_factor = 7 ):
175+ def __init__ (self , parent_recording_segment , periods , mode , noise_generator , seg_index , apodization_samples = 7 ):
177176 BasePreprocessorSegment .__init__ (self , parent_recording_segment )
178177 self .periods = periods
179178 self .mode = mode
180179 self .seg_index = seg_index
181180 self .noise_generator = noise_generator
182- self .apodization_factor = apodization_factor
181+ self .apodization_samples = apodization_samples
183182
184183 def get_traces (self , start_frame , end_frame , channel_indices ):
185184 traces = self .parent_recording_segment .get_traces (start_frame , end_frame , channel_indices )
@@ -206,10 +205,12 @@ def get_traces(self, start_frame, end_frame, channel_indices):
206205 ]
207206 traces [onset :offset , :] = noise [onset :offset ]
208207 elif self .mode == "apodization" :
208+ import scipy .signal
209+
209210 # apply a cosine taper to the saturation to create a mute function
210211 mute = np .zeros (traces .shape [0 ], dtype = np .float32 )
211212 mute [onset :offset ] = 1
212- win = scipy .signal .windows .cosine (self .apodization_factor )
213+ win = scipy .signal .windows .cosine (self .apodization_samples )
213214 mute = np .maximum (0 , 1 - scipy .signal .convolve (mute , win , mode = "same" ))
214215 traces = (traces .astype (np .float32 ) * mute [:, np .newaxis ]).astype (traces .dtype )
215216 return traces
0 commit comments