@@ -36,9 +36,10 @@ def __init__(self, spike_data, y_label, controller=None, parent=None, backend="q
3636 ViewBase .__init__ (self , controller = controller , parent = parent , backend = backend )
3737
3838
39- def get_unit_data (self , unit_id , seg_index = 0 ):
40- inds = self .controller .get_spike_indices (unit_id , seg_index = seg_index )
41- spike_times = self .controller .spikes ["sample_index" ][inds ] / self .controller .sampling_frequency
39+ def get_unit_data (self , unit_id , segment_index = 0 ):
40+ inds = self .controller .get_spike_indices (unit_id , segment_index = segment_index )
41+ spike_indices = self .controller .spikes ["sample_index" ][inds ]
42+ spike_times = self .controller .sample_index_to_time (spike_indices )
4243 spike_data = self .spike_data [inds ]
4344 ptp = np .ptp (spike_data )
4445 hist_min , hist_max = [np .min (spike_data ) - 0.2 * ptp , np .max (spike_data ) + 0.2 * ptp ]
@@ -53,8 +54,8 @@ def get_unit_data(self, unit_id, seg_index=0):
5354
5455 return spike_times , spike_data , hist_count , hist_bins , inds
5556
56- def get_selected_spikes_data (self , seg_index = 0 , visible_inds = None ):
57- sl = self .controller .segment_slices [seg_index ]
57+ def get_selected_spikes_data (self , segment_index = 0 , visible_inds = None ):
58+ sl = self .controller .segment_slices [segment_index ]
5859 spikes_in_seg = self .controller .spikes [sl ]
5960 selected_indices = self .controller .get_indices_spike_selected ()
6061 if visible_inds is not None :
@@ -85,7 +86,7 @@ def select_all_spikes_from_lasso(self, keep_already_selected=False):
8586 for segment_index , vertices in self ._lasso_vertices .items ():
8687 if vertices is None :
8788 continue
88- spike_inds = self .controller .get_spike_indices (visible_unit_id , seg_index = segment_index )
89+ spike_inds = self .controller .get_spike_indices (visible_unit_id , segment_index = segment_index )
8990 spike_times = self .controller .spikes ["sample_index" ][spike_inds ] / fs
9091 spike_data = self .spike_data [spike_inds ]
9192
@@ -119,7 +120,7 @@ def split(self):
119120
120121 if self .controller .num_segments > 1 :
121122 # check that lasso vertices are defined for all segments
122- if not all (self ._lasso_vertices [seg_index ] is not None for seg_index in range (self .controller .num_segments )):
123+ if not all (self ._lasso_vertices [segment_index ] is not None for segment_index in range (self .controller .num_segments )):
123124 # Use the new continue_from_user pattern
124125 self .continue_from_user (
125126 "Not all segments have lasso selection. "
@@ -163,6 +164,12 @@ def on_unit_visibility_changed(self):
163164 self ._current_selected = self .controller .get_indices_spike_selected ().size
164165 self .refresh ()
165166
167+ def on_time_info_updated (self ):
168+ return self .refresh ()
169+
170+ def on_use_times_updated (self ):
171+ return self .refresh ()
172+
166173 ## QT zone ##
167174 def _qt_make_layout (self ):
168175 from .myqt import QT
@@ -174,8 +181,8 @@ def _qt_make_layout(self):
174181 tb = self .qt_widget .view_toolbar
175182 self .combo_seg = QT .QComboBox ()
176183 tb .addWidget (self .combo_seg )
177- self .combo_seg .addItems ([ f'Segment { seg_index } ' for seg_index in range (self .controller .num_segments ) ])
178- self .combo_seg .currentIndexChanged .connect (self .refresh )
184+ self .combo_seg .addItems ([ f'Segment { segment_index } ' for segment_index in range (self .controller .num_segments ) ])
185+ self .combo_seg .currentIndexChanged .connect (self ._qt_change_segment )
179186 add_stretch_to_qtoolbar (tb )
180187 self .lasso_but = QT .QPushButton ("select" , checkable = True )
181188 tb .addWidget (self .lasso_but )
@@ -235,6 +242,12 @@ def _qt_initialize_plot(self):
235242 def _qt_on_spike_selection_changed (self ):
236243 self .refresh ()
237244
245+ def _qt_change_segment (self ):
246+ segment_index = self .combo_seg .currentIndex ()
247+ self .controller .set_time (segment_index = segment_index )
248+ self .refresh ()
249+ self .notify_time_info_updated ()
250+
238251 def _qt_refresh (self ):
239252 from .myqt import QT
240253 import pyqtgraph as pg
@@ -246,13 +259,18 @@ def _qt_refresh(self):
246259 if self .spike_data is None :
247260 return
248261
262+ segment_index = self .controller .get_time ()[1 ]
263+ # Update combo_seg if it doesn't match the current segment index
264+ if self .combo_seg .currentIndex () != segment_index :
265+ self .combo_seg .setCurrentIndex (segment_index )
266+
249267 max_count = 1
250268 all_inds = []
251269 for unit_id in self .controller .get_visible_unit_ids ():
252270
253271 spike_times , spike_data , hist_count , hist_bins , inds = self .get_unit_data (
254272 unit_id ,
255- seg_index = self . combo_seg . currentIndex ()
273+ segment_index = segment_index
256274 )
257275
258276 # make a copy of the color
@@ -276,7 +294,7 @@ def _qt_refresh(self):
276294 y_range_plot_1 = self .plot .getViewBox ().viewRange ()
277295 self .viewBox2 .setYRange (y_range_plot_1 [1 ][0 ], y_range_plot_1 [1 ][1 ], padding = 0.0 )
278296
279- spike_times , spike_data = self .get_selected_spikes_data (seg_index = self .combo_seg .currentIndex (), visible_inds = all_inds )
297+ spike_times , spike_data = self .get_selected_spikes_data (segment_index = self .combo_seg .currentIndex (), visible_inds = all_inds )
280298
281299 self .scatter_select .setData (spike_times , spike_data )
282300
@@ -296,8 +314,8 @@ def _qt_on_lasso_finished(self, points, shift_held=False):
296314 self .lasso .setData ([], [])
297315 vertices = np .array (points )
298316
299- seg_index = self .combo_seg .currentIndex ()
300- sl = self .controller .segment_slices [seg_index ]
317+ segment_index = self .combo_seg .currentIndex ()
318+ sl = self .controller .segment_slices [segment_index ]
301319 spikes_in_seg = self .controller .spikes [sl ]
302320
303321 # Create mask for visible units
@@ -315,16 +333,16 @@ def _qt_on_lasso_finished(self, points, shift_held=False):
315333 self .notify_spike_selection_changed ()
316334 return
317335
318- if self ._lasso_vertices [seg_index ] is None :
319- self ._lasso_vertices [seg_index ] = []
336+ if self ._lasso_vertices [segment_index ] is None :
337+ self ._lasso_vertices [segment_index ] = []
320338
321339 if shift_held :
322340 # If shift is held, append the vertices to the current lasso vertices
323- self ._lasso_vertices [seg_index ].append (vertices )
341+ self ._lasso_vertices [segment_index ].append (vertices )
324342 keep_already_selected = True
325343 else :
326344 # If shift is not held, clear the existing lasso vertices for this segment
327- self ._lasso_vertices [seg_index ] = [vertices ]
345+ self ._lasso_vertices [segment_index ] = [vertices ]
328346 keep_already_selected = False
329347
330348 self .select_all_spikes_from_lasso (keep_already_selected = keep_already_selected )
@@ -445,11 +463,13 @@ def _panel_refresh(self):
445463 ys = []
446464 colors = []
447465
466+ segment_index = self .controller .get_time ()[1 ]
467+
448468 visible_unit_ids = self .controller .get_visible_unit_ids ()
449469 for unit_id in visible_unit_ids :
450470 spike_times , spike_data , hist_count , hist_bins , inds = self .get_unit_data (
451471 unit_id ,
452- seg_index = self . segment_index
472+ segment_index = segment_index
453473 )
454474 color = self .get_unit_color (unit_id )
455475 xs .extend (spike_times )
@@ -504,9 +524,12 @@ def _panel_on_select_button(self, event):
504524 def _panel_change_segment (self , event ):
505525 self ._current_selected = 0
506526 self .segment_index = int (self .segment_selector .value .split ()[- 1 ])
507- time_max = self .controller .get_num_samples (self .segment_index ) / self .controller .sampling_frequency
508- self .scatter_fig .x_range .end = time_max
527+ self .controller .set_time (segment_index = self .segment_index )
528+ t_start , t_end = self .controller .get_t_start_t_end ()
529+ self .scatter_fig .x_range .start = t_start
530+ self .scatter_fig .x_range .end = t_end
509531 self .refresh ()
532+ self .notify_time_info_updated ()
510533
511534 def _on_panel_selection_geometry (self , event ):
512535 """
@@ -524,16 +547,16 @@ def _on_panel_selection_geometry(self, event):
524547 return
525548
526549 # Append the current polygon to the lasso vertices if shift is held
527- seg_index = self .segment_index
528- if self ._lasso_vertices [seg_index ] is None :
529- self ._lasso_vertices [seg_index ] = []
550+ segment_index = self .segment_index
551+ if self ._lasso_vertices [segment_index ] is None :
552+ self ._lasso_vertices [segment_index ] = []
530553 if len (selected ) > self ._current_selected :
531554 self ._current_selected = len (selected )
532555 # Store the current polygon for the current segment
533- self ._lasso_vertices [seg_index ].append (polygon )
556+ self ._lasso_vertices [segment_index ].append (polygon )
534557 keep_already_selected = True
535558 else :
536- self ._lasso_vertices [seg_index ] = [polygon ]
559+ self ._lasso_vertices [segment_index ] = [polygon ]
537560 keep_already_selected = False
538561
539562 self .select_all_spikes_from_lasso (keep_already_selected )
0 commit comments