Skip to content

Commit 358b9a7

Browse files
committed
Fix channel ordering in map and avoid refreshing in gain zoom and auto scale
1 parent 522a1b9 commit 358b9a7

File tree

3 files changed

+162
-73
lines changed

3 files changed

+162
-73
lines changed

spikeinterface_gui/tracemapview.py

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,6 @@ def __init__(self, controller=None, parent=None, backend="qt"):
4040

4141
self.make_color_lut()
4242

43-
44-
def apply_gain_zoom(self, factor_ratio):
45-
if self.color_limit is None:
46-
return
47-
self.color_limit = self.color_limit * factor_ratio
48-
self.refresh()
49-
50-
def auto_scale(self):
51-
if self.last_data_curves is not None:
52-
self.color_limit = np.max(np.abs(self.last_data_curves))
53-
self.refresh()
54-
5543
def make_color_lut(self):
5644
N = 512
5745
cmap_name = self.settings['colormap']
@@ -65,8 +53,7 @@ def make_color_lut(self):
6553
self.lut = self.lut[::-1]
6654

6755
def get_visible_channel_inds(self):
68-
return np.arange(self.controller.analyzer.get_num_channels())
69-
56+
return self.channel_order
7057

7158
## Qt ##
7259
def _qt_make_layout(self, **kargs):
@@ -99,7 +86,17 @@ def _qt_make_layout(self, **kargs):
9986
# self.on_params_changed(do_refresh=False)
10087
#this do refresh
10188
self._qt_change_segment(0)
102-
89+
90+
def _qt_gain_zoom(self, factor_ratio):
91+
if self.color_limit is None:
92+
return
93+
self.color_limit = self.color_limit * factor_ratio
94+
self.image.setLevels([-self.color_limit, self.color_limit])
95+
96+
def _qt_auto_scale(self):
97+
if self.last_data_curves is not None:
98+
self.color_limit = np.max(np.abs(self.last_data_curves))
99+
self._qt_gain_zoom(1.0)
103100

104101
def _qt_on_settings_changed(self, do_refresh=True):
105102

@@ -147,10 +144,10 @@ def _qt_seek(self, t):
147144
self.scroll_time.valueChanged.connect(self._qt_on_scroll_time)
148145

149146
seg_index = self.controller.get_time()[1]
150-
times_chunk, data_curves, scatter_x, scatter_y, scatter_colors, scatter_unit_ids = \
147+
times_chunk, data_curves, scatter_x, scatter_y, scatter_colors = \
151148
self.get_data_in_chunk(t1, t2, seg_index)
152-
self.last_data_curves = data_curves
153-
149+
data_curves = data_curves.T
150+
154151
if self.color_limit is None:
155152
self.color_limit = np.max(np.abs(data_curves))
156153

@@ -163,8 +160,8 @@ def _qt_seek(self, t):
163160
# self.scatter.clear()
164161
self.scatter.setData(x=scatter_x, y=scatter_y, brush=scatter_colors)
165162

166-
self.plot.setXRange( t1, t2, padding = 0.0)
167-
self.plot.setYRange(0, num_chans, padding = 0.0)
163+
self.plot.setXRange(t1, t2, padding=0.0)
164+
self.plot.setYRange(0, num_chans, padding=0.0)
168165

169166
def _qt_on_time_info_updated(self):
170167
# Update segment and time slider range
@@ -226,7 +223,7 @@ def _panel_make_layout(self):
226223
# Add data sources
227224
self.image_source = ColumnDataSource({"image": [], "x": [], "y": [], "dw": [], "dh": []})
228225

229-
self.spike_source = ColumnDataSource({"x": [], "y": [], "color": [], "unit_id": []})
226+
self.spike_source = ColumnDataSource({"x": [], "y": [], "color": []})
230227

231228
# Create color mapper
232229
self.color_mapper = LinearColorMapper(palette="Greys256", low=-1, high=1)
@@ -268,8 +265,9 @@ def _panel_refresh(self):
268265
else:
269266
auto_scale = False
270267

271-
times_chunk, data_curves, scatter_x, scatter_y, scatter_colors, scatter_unit_ids = \
268+
times_chunk, data_curves, scatter_x, scatter_y, scatter_colors = \
272269
self.get_data_in_chunk(t1, t2, seg_index)
270+
data_curves = data_curves.T
273271

274272
if self.color_limit is None:
275273
self.color_limit = np.max(np.abs(data_curves))
@@ -286,7 +284,6 @@ def _panel_refresh(self):
286284
"x": scatter_x,
287285
"y": scatter_y,
288286
"color": scatter_colors,
289-
"unit_id": scatter_unit_ids,
290287
})
291288

292289
if auto_scale:
@@ -301,7 +298,7 @@ def _panel_refresh(self):
301298
# TODO: if from a different unit, change unit visibility
302299
def _panel_on_tap(self, event):
303300
seg_index = self.controller.get_time()[1]
304-
ind_spike_nearest = self.find_nearest_spike(self.controller, event.x, seg_index)
301+
ind_spike_nearest = find_nearest_spike(self.controller, event.x, seg_index)
305302
if ind_spike_nearest is not None:
306303
self.controller.set_indices_spike_selected([ind_spike_nearest])
307304
self._panel_seek_with_selected_spike()
@@ -315,15 +312,15 @@ def _panel_on_spike_selection_changed(self):
315312
self._panel_seek_with_selected_spike()
316313

317314
def _panel_gain_zoom(self, event):
318-
factor = 1.3 if event.delta > 0 else 1 / 1.3
319-
self.color_mapper.high = self.color_mapper.high * factor
315+
if event is None:
316+
factor_ratio = 1.0
317+
else:
318+
factor_ratio = 1.3 if event.delta > 0 else 1 / 1.3
319+
self.color_mapper.high = self.color_mapper.high * factor_ratio
320320
self.color_mapper.low = -self.color_mapper.high
321321

322322
def _panel_auto_scale(self, event):
323-
if self.last_data_curves is not None:
324-
self.color_limit = np.max(np.abs(self.last_data_curves))
325-
self.color_mapper.high = self.color_limit
326-
self.color_mapper.low = -self.color_limit
323+
self._panel_gain_zoom(None)
327324

328325
def _panel_on_time_info_updated(self):
329326
# Update segment and time slider range

0 commit comments

Comments
 (0)