22
33import numpy as np
44
5+ import warnings
6+
57from .base import BaseWidget , to_attr
68
79from .amplitudes import AmplitudesWidget
1416from ..core import SortingAnalyzer
1517
1618
19+ _default_displayed_unit_properties = ["firing_rate" , "num_spikes" , "x" , "y" , "amplitude_median" , "snr" , "rp_violation" ]
20+
21+
1722class SortingSummaryWidget (BaseWidget ):
1823 """
1924 Plots spike sorting summary.
@@ -42,14 +47,24 @@ class SortingSummaryWidget(BaseWidget):
4247 label_choices : list or None, default: None
4348 List of labels to be added to the curation table
4449 (sortingview backend)
45- unit_table_properties : list or None, default: None
50+ displayed_unit_properties : list or None, default: None
4651 List of properties to be added to the unit table.
4752 These may be drawn from the sorting extractor, and, if available,
48- the quality_metrics and template_metrics extensions of the SortingAnalyzer.
53+ the quality_metrics/ template_metrics/unit_locations extensions of the SortingAnalyzer.
4954 See all properties available with sorting.get_property_keys(), and, if available,
5055 analyzer.get_extension("quality_metrics").get_data().columns and
5156 analyzer.get_extension("template_metrics").get_data().columns.
52- (sortingview backend)
57+ extra_unit_properties : dict or None, default: None
58+ A dict with extra units properties to display.
59+ curation_dict : dict or None, default: None
60+ When curation is True, optionaly the viewer can get a previous 'curation_dict'
61+ to continue/check previous curations on this analyzer.
62+ In this case label_definitions must be None beacuse it is already included in the curation_dict.
63+ (spikeinterface_gui backend)
64+ label_definitions : dict or None, default: None
65+ When curation is True, optionaly the user can provide a label_definitions dict.
66+ This replaces the label_choices in the curation_format.
67+ (spikeinterface_gui backend)
5368 """
5469
5570 def __init__ (
@@ -60,11 +75,24 @@ def __init__(
6075 max_amplitudes_per_unit = None ,
6176 min_similarity_for_correlograms = 0.2 ,
6277 curation = False ,
63- unit_table_properties = None ,
78+ displayed_unit_properties = None ,
79+ extra_unit_properties = None ,
6480 label_choices = None ,
81+ curation_dict = None ,
82+ label_definitions = None ,
6583 backend = None ,
84+ unit_table_properties = None ,
6685 ** backend_kwargs ,
6786 ):
87+
88+ if unit_table_properties is not None :
89+ warnings .warn (
90+ "plot_sorting_summary() : unit_table_properties is deprecated, use displayed_unit_properties instead" ,
91+ category = DeprecationWarning ,
92+ stacklevel = 2 ,
93+ )
94+ displayed_unit_properties = unit_table_properties
95+
6896 sorting_analyzer = self .ensure_sorting_analyzer (sorting_analyzer )
6997 self .check_extensions (
7098 sorting_analyzer , ["correlograms" , "spike_amplitudes" , "unit_locations" , "template_similarity" ]
@@ -74,18 +102,29 @@ def __init__(
74102 if unit_ids is None :
75103 unit_ids = sorting .get_unit_ids ()
76104
77- plot_data = dict (
105+ if curation_dict is not None and label_definitions is not None :
106+ raise ValueError ("curation_dict and label_definitions are mutualy exclusive, they cannot be not None both" )
107+
108+ if displayed_unit_properties is None :
109+ displayed_unit_properties = list (_default_displayed_unit_properties )
110+ if extra_unit_properties is not None :
111+ displayed_unit_properties += list (extra_unit_properties .keys ())
112+
113+ data_plot = dict (
78114 sorting_analyzer = sorting_analyzer ,
79115 unit_ids = unit_ids ,
80116 sparsity = sparsity ,
81117 min_similarity_for_correlograms = min_similarity_for_correlograms ,
82- unit_table_properties = unit_table_properties ,
118+ displayed_unit_properties = displayed_unit_properties ,
119+ extra_unit_properties = extra_unit_properties ,
83120 curation = curation ,
84121 label_choices = label_choices ,
85122 max_amplitudes_per_unit = max_amplitudes_per_unit ,
123+ curation_dict = curation_dict ,
124+ label_definitions = label_definitions ,
86125 )
87126
88- BaseWidget .__init__ (self , plot_data , backend = backend , ** backend_kwargs )
127+ BaseWidget .__init__ (self , data_plot , backend = backend , ** backend_kwargs )
89128
90129 def plot_sortingview (self , data_plot , ** backend_kwargs ):
91130 import sortingview .views as vv
@@ -156,7 +195,7 @@ def plot_sortingview(self, data_plot, **backend_kwargs):
156195
157196 # unit ids
158197 v_units_table = generate_unit_table_view (
159- dp .sorting_analyzer , dp .unit_table_properties , similarity_scores = similarity_scores
198+ dp .sorting_analyzer , dp .displayed_unit_properties , similarity_scores = similarity_scores
160199 )
161200
162201 if dp .curation :
@@ -190,9 +229,14 @@ def plot_sortingview(self, data_plot, **backend_kwargs):
190229 def plot_spikeinterface_gui (self , data_plot , ** backend_kwargs ):
191230 sorting_analyzer = data_plot ["sorting_analyzer" ]
192231
193- import spikeinterface_gui
232+ from spikeinterface_gui import run_mainwindow
194233
195- app = spikeinterface_gui .mkQApp ()
196- win = spikeinterface_gui .MainWindow (sorting_analyzer , curation = data_plot ["curation" ])
197- win .show ()
198- app .exec_ ()
234+ run_mainwindow (
235+ sorting_analyzer ,
236+ with_traces = True ,
237+ curation = data_plot ["curation" ],
238+ curation_dict = data_plot ["curation_dict" ],
239+ label_definitions = data_plot ["label_definitions" ],
240+ extra_unit_properties = data_plot ["extra_unit_properties" ],
241+ displayed_unit_properties = data_plot ["displayed_unit_properties" ],
242+ )
0 commit comments