-
Notifications
You must be signed in to change notification settings - Fork 1
/
TraceSortChannel.py
30 lines (25 loc) · 1.02 KB
/
TraceSortChannel.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"""
Sort the channels in trace view
"""
import numpy as np
from phy.cluster.views import TraceView
from phy import IPlugin, connect
class TraceSortChannel(IPlugin):
def attach_to_controller(self, controller):
@connect
def on_view_attached(view, gui):
if isinstance(view, TraceView):
# Update channel order
idx = np.argsort(view.channel_y_ranks)
view.channel_y_ranks = view.channel_y_ranks[idx]
# Update drawing of traces
_traces = view.traces # Backup of original function
def _get_traces(interval):
tr = _traces(interval)
# tr.data = tr.data[:, idx] # Already sorted?
for wv in tr.waveforms:
sort_i = np.argsort(wv.channel_ids)
wv['data'] = wv['data'][:, sort_i]
wv['channel_ids'] = wv['channel_ids'][sort_i]
return tr
view.traces = _get_traces