wip multi layer on timeseries
import numpy as np
+from ..core import BaseRecording
from .base import BaseWidget, define_widget_function_from_class
from .utils import get_unit_colors
from ..postprocessing import get_template_channel_sparsity
@@ -13,16 +14,16 @@ class TimeseriesWidget(BaseWidget):
def __init__(self, recording, segment_index=None, channel_ids=None, order_channel_by_depth=False,
time_range=None, mode='auto', cmap='RdBu', show_channel_ids=False,
color_groups=False, color=None, clim=None, with_colorbar=True,
-
backend=None, **backend_kwargs):
- #~ figure=None, ax=None, **plot_kwargs):
"""
Plots recording timeseries.
Parameters
----------
- recording: RecordingExtractor
+ recording: RecordingExtractor or dict or list
The recording extractor object
+ If dict (or list) then it is a multi layer display to compare some processing
+ for instance
segment_index: None or int
The segment index.
channel_ids: list
@@ -54,6 +55,16 @@ class TimeseriesWidget(BaseWidget):
W: TimeseriesWidget
The output widget
"""
+ if isinstance(recording, BaseRecording):
+ recordings = {'rec': recording}
+ elif isinstance(recording, dict):
+ recordings = recording
+ recording = next(recordings.values())
+ elif isinstance(recording, list):
+ recordings = {f'rec{i}': rec for i, rec in enumerate(recording)}
+ recording = recordings[0]
+ else:
+ raise ValueeError('plot_timeseries recording must be recording or dict')
if segment_index is None:
if recording.get_num_segments() != 1:
@@ -75,7 +86,6 @@ class TimeseriesWidget(BaseWidget):
else:
order = None
-
fs = recording.get_sampling_frequency()
if time_range is None:
time_range = (0, 1.)
@@ -96,8 +106,9 @@ class TimeseriesWidget(BaseWidget):
time_range = frame_range / fs
times = np.arange(frame_range[0], frame_range[1]) / fs
-
- traces = recording.get_traces(
+ list_traces = []
+ for rec in recordings:
+ traces = rec.get_traces(
segment_index=segment_index,
channel_ids=channel_ids,
start_frame=frame_range[0],
@@ -108,9 +119,12 @@ class TimeseriesWidget(BaseWidget):
traces = traces[:, order]
channel_ids = np.asarray(channel_ids)[order]
- # stat for auto scaling
- mean_channel_std = np.mean(np.std(traces, axis=0))
- max_channel_amp = np.max(np.max(np.abs(traces), axis=0))
+ list_traces.append(traces)
+
+ # stat for auto scaling done on the first layer
+ traces0 = list_traces[0]
+ mean_channel_std = np.mean(np.std(traces0, axis=0))
+ max_channel_amp = np.max(np.max(np.abs(traces0), axis=0))
vspacing = max_channel_amp * 1.5
if recording.get_channel_groups() is None:
@@ -138,7 +152,7 @@ class TimeseriesWidget(BaseWidget):
time_range=time_range,
frame_range=frame_range,
times=times,
- traces=traces,
+ list_traces=list_traces,
mode = mode,
cmap = cmap,
clim = clim,
