66
77from spikeinterface .core import BaseRecording , SortingAnalyzer
88from spikeinterface .sortingcomponents .motion import Motion
9+ from .rasters import BaseRasterWidget
910
1011
1112class MotionWidget (BaseWidget ):
@@ -97,7 +98,7 @@ def plot_matplotlib(self, data_plot, **backend_kwargs):
9798 ax .set_ylabel ("Depth [um]" )
9899
99100
100- class DriftRasterMapWidget (BaseWidget ):
101+ class DriftRasterMapWidget (BaseRasterWidget ):
101102 """
102103 Plot the drift raster map from peaks or a SortingAnalyzer.
103104 The drift raster map is a scatter plot of the estimated peak depth vs time and it is
@@ -200,56 +201,14 @@ def __init__(
200201 if peak_amplitudes is not None :
201202 peak_amplitudes = peak_amplitudes [peak_mask ]
202203
203- plot_data = dict (
204- peaks = peaks ,
205- peak_locations = peak_locations ,
206- peak_amplitudes = peak_amplitudes ,
207- direction = direction ,
208- sampling_frequency = sampling_frequency ,
209- segment_index = segment_index ,
210- depth_lim = depth_lim ,
211- color_amplitude = color_amplitude ,
212- color = color ,
213- scatter_decimate = scatter_decimate ,
214- cmap = cmap ,
215- clim = clim ,
216- alpha = alpha ,
217- recording = recording ,
218- )
219- BaseWidget .__init__ (self , plot_data , backend = backend , ** backend_kwargs )
220-
221- def plot_matplotlib (self , data_plot , ** backend_kwargs ):
222- import matplotlib .pyplot as plt
223- from matplotlib .colors import Normalize
224- from .utils_matplotlib import make_mpl_figure
204+ from matplotlib .pyplot import colormaps
225205
226- from spikeinterface .sortingcomponents .motion import correct_motion_on_peaks
227-
228- dp = to_attr (data_plot )
229-
230- assert backend_kwargs ["axes" ] is None , "axes argument is not allowed in DriftRasterMapWidget. Use ax instead."
231-
232- self .figure , self .axes , self .ax = make_mpl_figure (** backend_kwargs )
233-
234- if dp .recording is None :
235- peak_times = dp .peaks ["sample_index" ] / dp .sampling_frequency
236- else :
237- peak_times = dp .recording .sample_index_to_time (dp .peaks ["sample_index" ], segment_index = dp .segment_index )
238-
239- peak_locs = dp .peak_locations [dp .direction ]
240- if dp .scatter_decimate is not None :
241- peak_times = peak_times [:: dp .scatter_decimate ]
242- peak_locs = peak_locs [:: dp .scatter_decimate ]
243-
244- if dp .color_amplitude :
245- amps = dp .peak_amplitudes
206+ if color_amplitude :
207+ amps = peak_amplitudes
246208 amps_abs = np .abs (amps )
247209 q_95 = np .quantile (amps_abs , 0.95 )
248- if dp .scatter_decimate is not None :
249- amps = amps [:: dp .scatter_decimate ]
250- amps_abs = amps_abs [:: dp .scatter_decimate ]
251- cmap = plt .colormaps [dp .cmap ]
252- if dp .clim is None :
210+ cmap = colormaps [cmap ]
211+ if clim is None :
253212 amps = amps_abs
254213 amps /= q_95
255214 c = cmap (amps )
@@ -259,17 +218,26 @@ def plot_matplotlib(self, data_plot, **backend_kwargs):
259218 color_kwargs = dict (
260219 color = None ,
261220 c = c ,
262- alpha = dp . alpha ,
221+ alpha = alpha ,
263222 )
264223 else :
265- color_kwargs = dict (color = dp .color , c = None , alpha = dp .alpha )
266-
267- self .ax .scatter (peak_times , peak_locs , s = 1 , ** color_kwargs )
268- if dp .depth_lim is not None :
269- self .ax .set_ylim (* dp .depth_lim )
270- self .ax .set_title ("Peak depth" )
271- self .ax .set_xlabel ("Times [s]" )
272- self .ax .set_ylabel ("Depth [$\\ mu$m]" )
224+ color_kwargs = dict (color = color , c = None , alpha = alpha )
225+
226+ # convert data into format that `BaseRasterWidget` can take it in
227+ spike_train_data = {0 : peaks ["sample_index" ] / sampling_frequency }
228+ y_axis_data = {0 : peak_locations [direction ]}
229+
230+ plot_data = dict (
231+ spike_train_data = spike_train_data ,
232+ y_axis_data = y_axis_data ,
233+ y_lim = depth_lim ,
234+ color_kwargs = color_kwargs ,
235+ scatter_decimate = scatter_decimate ,
236+ title = "Peak depth" ,
237+ y_label = "Depth [um]" ,
238+ )
239+
240+ BaseRasterWidget .__init__ (self , ** plot_data , backend = backend , ** backend_kwargs )
273241
274242
275243class MotionInfoWidget (BaseWidget ):
0 commit comments