From c33fbd57b4fc7e95edd8a3680ab40a5f291617e0 Mon Sep 17 00:00:00 2001 From: Alessio Buccino Date: Mon, 16 Sep 2024 10:00:34 +0200 Subject: [PATCH 1/3] Fix plot motion for multi-segment --- src/spikeinterface/widgets/motion.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/spikeinterface/widgets/motion.py b/src/spikeinterface/widgets/motion.py index 81cda212b2..06c0305351 100644 --- a/src/spikeinterface/widgets/motion.py +++ b/src/spikeinterface/widgets/motion.py @@ -340,8 +340,11 @@ def __init__( raise ValueError( "plot drift map : the Motion object is multi-segment you must provide segment_index=XX" ) + assert recording.get_num_segments() == len( + motion.displacement + ), "The number of segments in the recording must be the same as the number of segments in the motion object" - times = recording.get_times() if recording is not None else None + times = recording.get_times(segment_index=segment_index) if recording is not None else None plot_data = dict( sampling_frequency=motion_info["parameters"]["sampling_frequency"], From 3d41aca67dbfcd01e74eb3bda0ccf7fa59e4c56a Mon Sep 17 00:00:00 2001 From: Alessio Buccino Date: Mon, 16 Sep 2024 11:25:54 +0200 Subject: [PATCH 2/3] Recording cannot be Nonw --- src/spikeinterface/widgets/motion.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/spikeinterface/widgets/motion.py b/src/spikeinterface/widgets/motion.py index 06c0305351..7c8389cae8 100644 --- a/src/spikeinterface/widgets/motion.py +++ b/src/spikeinterface/widgets/motion.py @@ -344,7 +344,7 @@ def __init__( motion.displacement ), "The number of segments in the recording must be the same as the number of segments in the motion object" - times = recording.get_times(segment_index=segment_index) if recording is not None else None + times = recording.get_times(segment_index=segment_index) plot_data = dict( sampling_frequency=motion_info["parameters"]["sampling_frequency"], From 36251ef49b9c61582de2f84bd81d76d00be34b3e Mon Sep 17 00:00:00 2001 From: Alessio Buccino Date: Mon, 16 Sep 2024 11:33:56 +0200 Subject: [PATCH 3/3] Let recording handle times --- src/spikeinterface/widgets/motion.py | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/src/spikeinterface/widgets/motion.py b/src/spikeinterface/widgets/motion.py index 7c8389cae8..42e9a20f3c 100644 --- a/src/spikeinterface/widgets/motion.py +++ b/src/spikeinterface/widgets/motion.py @@ -200,18 +200,11 @@ def __init__( if peak_amplitudes is not None: peak_amplitudes = peak_amplitudes[peak_mask] - if recording is not None: - sampling_frequency = recording.sampling_frequency - times = recording.get_times(segment_index=segment_index) - else: - times = None - plot_data = dict( peaks=peaks, peak_locations=peak_locations, peak_amplitudes=peak_amplitudes, direction=direction, - times=times, sampling_frequency=sampling_frequency, segment_index=segment_index, depth_lim=depth_lim, @@ -238,10 +231,10 @@ def plot_matplotlib(self, data_plot, **backend_kwargs): self.figure, self.axes, self.ax = make_mpl_figure(**backend_kwargs) - if dp.times is None: + if dp.recording is None: peak_times = dp.peaks["sample_index"] / dp.sampling_frequency else: - peak_times = dp.times[dp.peaks["sample_index"]] + peak_times = dp.recording.sample_index_to_time(dp.peaks["sample_index"], segment_index=dp.segment_index) peak_locs = dp.peak_locations[dp.direction] if dp.scatter_decimate is not None: @@ -344,11 +337,8 @@ def __init__( motion.displacement ), "The number of segments in the recording must be the same as the number of segments in the motion object" - times = recording.get_times(segment_index=segment_index) - plot_data = dict( sampling_frequency=motion_info["parameters"]["sampling_frequency"], - times=times, segment_index=segment_index, depth_lim=depth_lim, motion_lim=motion_lim,