From 04b4d552b2833c61485e8aa71cb4d1c88cd53190 Mon Sep 17 00:00:00 2001 From: Axoft Server Date: Mon, 22 Jul 2024 18:23:33 -0400 Subject: [PATCH 01/11] feat: Add extra args to UnitSummaryWidget for subwidgets --- src/spikeinterface/widgets/unit_summary.py | 43 +++++++++++++++++++++- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/src/spikeinterface/widgets/unit_summary.py b/src/spikeinterface/widgets/unit_summary.py index 0b2a348edf..40481ae61d 100644 --- a/src/spikeinterface/widgets/unit_summary.py +++ b/src/spikeinterface/widgets/unit_summary.py @@ -30,6 +30,16 @@ class UnitSummaryWidget(BaseWidget): sparsity : ChannelSparsity or None, default: None Optional ChannelSparsity to apply. If SortingAnalyzer is already sparse, the argument is ignored + unitlocationswidget_params : dict or None, default: None + Parameters for UnitLocationsWidget (see UnitLocationsWidget for details) + unitwaveformswidgets_params : dict or None, default: None + Parameters for UnitWaveformsWidget (see UnitWaveformsWidget for details) + unitwaveformdensitymapwidget_params : dict or None, default: None + Parameters for UnitWaveformDensityMapWidget (see UnitWaveformDensityMapWidget for details) + autocorrelogramswidget_params : dict or None, default: None + Parameters for AutoCorrelogramsWidget (see AutoCorrelogramsWidget for details) + amplitudeswidget_params : dict or None, default: None + Parameters for AmplitudesWidget (see AmplitudesWidget for details) """ # possible_backends = {} @@ -40,21 +50,40 @@ def __init__( unit_id, unit_colors=None, sparsity=None, - radius_um=100, + unitlocationswidget_params=None, + unitwaveformswidgets_params=None, + unitwaveformdensitymapwidget_params=None, + autocorrelogramswidget_params=None, + amplitudeswidget_params=None, backend=None, **backend_kwargs, ): - sorting_analyzer = self.ensure_sorting_analyzer(sorting_analyzer) if unit_colors is None: unit_colors = get_unit_colors(sorting_analyzer) + if unitlocationswidget_params is None: + unitlocationswidget_params = dict() + if unitwaveformswidgets_params is None: + unitwaveformswidgets_params = dict() + if unitwaveformdensitymapwidget_params is None: + unitwaveformdensitymapwidget_params = dict() + if autocorrelogramswidget_params is None: + autocorrelogramswidget_params = dict() + if amplitudeswidget_params is None: + amplitudeswidget_params = dict() + plot_data = dict( sorting_analyzer=sorting_analyzer, unit_id=unit_id, unit_colors=unit_colors, sparsity=sparsity, + unitlocationswidget_params=unitlocationswidget_params, + unitwaveformswidgets_params=unitwaveformswidgets_params, + unitwaveformdensitymapwidget_params=unitwaveformdensitymapwidget_params, + autocorrelogramswidget_params=autocorrelogramswidget_params, + amplitudeswidget_params=amplitudeswidget_params ) BaseWidget.__init__(self, plot_data, backend=backend, **backend_kwargs) @@ -69,6 +98,11 @@ def plot_matplotlib(self, data_plot, **backend_kwargs): sorting_analyzer = dp.sorting_analyzer unit_colors = dp.unit_colors sparsity = dp.sparsity + unitlocationswidget = dp.unitlocationswidget_params + unitwaveformswidgets = dp.unitwaveformswidgets_params + unitwaveformdensitymapwidget = dp.unitwaveformdensitymapwidget_params + autocorrelogramswidget = dp.autocorrelogramswidget_params + amplitudeswidget = dp.amplitudeswidget_params # force the figure without axes if "figsize" not in backend_kwargs: @@ -99,6 +133,7 @@ def plot_matplotlib(self, data_plot, **backend_kwargs): plot_legend=False, backend="matplotlib", ax=ax1, + **unitlocationswidget ) unit_locations = sorting_analyzer.get_extension("unit_locations").get_data(outputs="by_unit") @@ -121,6 +156,7 @@ def plot_matplotlib(self, data_plot, **backend_kwargs): sparsity=sparsity, backend="matplotlib", ax=ax2, + **unitwaveformswidgets ) ax2.set_title(None) @@ -134,6 +170,7 @@ def plot_matplotlib(self, data_plot, **backend_kwargs): same_axis=False, backend="matplotlib", ax=ax3, + **unitwaveformdensitymapwidget ) ax3.set_ylabel(None) @@ -145,6 +182,7 @@ def plot_matplotlib(self, data_plot, **backend_kwargs): unit_colors=unit_colors, backend="matplotlib", ax=ax4, + **autocorrelogramswidget ) ax4.set_title(None) @@ -162,6 +200,7 @@ def plot_matplotlib(self, data_plot, **backend_kwargs): plot_histograms=True, backend="matplotlib", axes=axes, + **amplitudeswidget ) fig.suptitle(f"unit_id: {dp.unit_id}") From fc0743e59412910e07f5c1355a58718ad6f9a4ed Mon Sep 17 00:00:00 2001 From: Axoft Server Date: Mon, 22 Jul 2024 18:29:38 -0400 Subject: [PATCH 02/11] fix: improve variable names --- src/spikeinterface/widgets/unit_summary.py | 28 +++++++++++----------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/spikeinterface/widgets/unit_summary.py b/src/spikeinterface/widgets/unit_summary.py index 40481ae61d..8313e6b9c7 100644 --- a/src/spikeinterface/widgets/unit_summary.py +++ b/src/spikeinterface/widgets/unit_summary.py @@ -51,7 +51,7 @@ def __init__( unit_colors=None, sparsity=None, unitlocationswidget_params=None, - unitwaveformswidgets_params=None, + unitwaveformswidget_params=None, unitwaveformdensitymapwidget_params=None, autocorrelogramswidget_params=None, amplitudeswidget_params=None, @@ -65,8 +65,8 @@ def __init__( if unitlocationswidget_params is None: unitlocationswidget_params = dict() - if unitwaveformswidgets_params is None: - unitwaveformswidgets_params = dict() + if unitwaveformswidget_params is None: + unitwaveformswidget_params = dict() if unitwaveformdensitymapwidget_params is None: unitwaveformdensitymapwidget_params = dict() if autocorrelogramswidget_params is None: @@ -80,7 +80,7 @@ def __init__( unit_colors=unit_colors, sparsity=sparsity, unitlocationswidget_params=unitlocationswidget_params, - unitwaveformswidgets_params=unitwaveformswidgets_params, + unitwaveformswidget_params=unitwaveformswidget_params, unitwaveformdensitymapwidget_params=unitwaveformdensitymapwidget_params, autocorrelogramswidget_params=autocorrelogramswidget_params, amplitudeswidget_params=amplitudeswidget_params @@ -98,11 +98,11 @@ def plot_matplotlib(self, data_plot, **backend_kwargs): sorting_analyzer = dp.sorting_analyzer unit_colors = dp.unit_colors sparsity = dp.sparsity - unitlocationswidget = dp.unitlocationswidget_params - unitwaveformswidgets = dp.unitwaveformswidgets_params - unitwaveformdensitymapwidget = dp.unitwaveformdensitymapwidget_params - autocorrelogramswidget = dp.autocorrelogramswidget_params - amplitudeswidget = dp.amplitudeswidget_params + unitlocationswidget_params = dp.unitlocationswidget_params + unitwaveformswidget_params = dp.unitwaveformswidget_params + unitwaveformdensitymapwidget_params = dp.unitwaveformdensitymapwidget_params + autocorrelogramswidget_params = dp.autocorrelogramswidget_params + amplitudeswidget_params = dp.amplitudeswidget_params # force the figure without axes if "figsize" not in backend_kwargs: @@ -133,7 +133,7 @@ def plot_matplotlib(self, data_plot, **backend_kwargs): plot_legend=False, backend="matplotlib", ax=ax1, - **unitlocationswidget + **unitlocationswidget_params ) unit_locations = sorting_analyzer.get_extension("unit_locations").get_data(outputs="by_unit") @@ -156,7 +156,7 @@ def plot_matplotlib(self, data_plot, **backend_kwargs): sparsity=sparsity, backend="matplotlib", ax=ax2, - **unitwaveformswidgets + **unitwaveformswidget_params ) ax2.set_title(None) @@ -170,7 +170,7 @@ def plot_matplotlib(self, data_plot, **backend_kwargs): same_axis=False, backend="matplotlib", ax=ax3, - **unitwaveformdensitymapwidget + **unitwaveformdensitymapwidget_params ) ax3.set_ylabel(None) @@ -182,7 +182,7 @@ def plot_matplotlib(self, data_plot, **backend_kwargs): unit_colors=unit_colors, backend="matplotlib", ax=ax4, - **autocorrelogramswidget + **autocorrelogramswidget_params ) ax4.set_title(None) @@ -200,7 +200,7 @@ def plot_matplotlib(self, data_plot, **backend_kwargs): plot_histograms=True, backend="matplotlib", axes=axes, - **amplitudeswidget + **amplitudeswidget_params ) fig.suptitle(f"unit_id: {dp.unit_id}") From d3c9eb0820109e69b5e973419e01531410abb19a Mon Sep 17 00:00:00 2001 From: florian6973 <70778912+florian6973@users.noreply.github.com> Date: Mon, 22 Jul 2024 18:31:33 -0400 Subject: [PATCH 03/11] fix: typo doc --- src/spikeinterface/widgets/unit_summary.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/spikeinterface/widgets/unit_summary.py b/src/spikeinterface/widgets/unit_summary.py index 8313e6b9c7..d41be2641f 100644 --- a/src/spikeinterface/widgets/unit_summary.py +++ b/src/spikeinterface/widgets/unit_summary.py @@ -32,7 +32,7 @@ class UnitSummaryWidget(BaseWidget): If SortingAnalyzer is already sparse, the argument is ignored unitlocationswidget_params : dict or None, default: None Parameters for UnitLocationsWidget (see UnitLocationsWidget for details) - unitwaveformswidgets_params : dict or None, default: None + unitwaveformswidget_params : dict or None, default: None Parameters for UnitWaveformsWidget (see UnitWaveformsWidget for details) unitwaveformdensitymapwidget_params : dict or None, default: None Parameters for UnitWaveformDensityMapWidget (see UnitWaveformDensityMapWidget for details) From 60f775f9e4bd9c75f6657532ccdf4a2e57701dbb Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 22 Jul 2024 22:31:55 +0000 Subject: [PATCH 04/11] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/spikeinterface/widgets/unit_summary.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/spikeinterface/widgets/unit_summary.py b/src/spikeinterface/widgets/unit_summary.py index d41be2641f..979e8c0398 100644 --- a/src/spikeinterface/widgets/unit_summary.py +++ b/src/spikeinterface/widgets/unit_summary.py @@ -83,7 +83,7 @@ def __init__( unitwaveformswidget_params=unitwaveformswidget_params, unitwaveformdensitymapwidget_params=unitwaveformdensitymapwidget_params, autocorrelogramswidget_params=autocorrelogramswidget_params, - amplitudeswidget_params=amplitudeswidget_params + amplitudeswidget_params=amplitudeswidget_params, ) BaseWidget.__init__(self, plot_data, backend=backend, **backend_kwargs) @@ -133,7 +133,7 @@ def plot_matplotlib(self, data_plot, **backend_kwargs): plot_legend=False, backend="matplotlib", ax=ax1, - **unitlocationswidget_params + **unitlocationswidget_params, ) unit_locations = sorting_analyzer.get_extension("unit_locations").get_data(outputs="by_unit") @@ -156,7 +156,7 @@ def plot_matplotlib(self, data_plot, **backend_kwargs): sparsity=sparsity, backend="matplotlib", ax=ax2, - **unitwaveformswidget_params + **unitwaveformswidget_params, ) ax2.set_title(None) @@ -170,7 +170,7 @@ def plot_matplotlib(self, data_plot, **backend_kwargs): same_axis=False, backend="matplotlib", ax=ax3, - **unitwaveformdensitymapwidget_params + **unitwaveformdensitymapwidget_params, ) ax3.set_ylabel(None) @@ -182,7 +182,7 @@ def plot_matplotlib(self, data_plot, **backend_kwargs): unit_colors=unit_colors, backend="matplotlib", ax=ax4, - **autocorrelogramswidget_params + **autocorrelogramswidget_params, ) ax4.set_title(None) @@ -200,7 +200,7 @@ def plot_matplotlib(self, data_plot, **backend_kwargs): plot_histograms=True, backend="matplotlib", axes=axes, - **amplitudeswidget_params + **amplitudeswidget_params, ) fig.suptitle(f"unit_id: {dp.unit_id}") From d5b3e0cb716c5b5a72e58ae53dd8c5eef2305db2 Mon Sep 17 00:00:00 2001 From: Axoft Server Date: Mon, 5 Aug 2024 15:45:21 -0400 Subject: [PATCH 05/11] feat: switch to nested dict --- src/spikeinterface/widgets/unit_summary.py | 54 ++++++++-------------- 1 file changed, 19 insertions(+), 35 deletions(-) diff --git a/src/spikeinterface/widgets/unit_summary.py b/src/spikeinterface/widgets/unit_summary.py index 8313e6b9c7..a22b17bb8a 100644 --- a/src/spikeinterface/widgets/unit_summary.py +++ b/src/spikeinterface/widgets/unit_summary.py @@ -1,4 +1,5 @@ from __future__ import annotations +from collections import defaultdict import numpy as np @@ -30,16 +31,13 @@ class UnitSummaryWidget(BaseWidget): sparsity : ChannelSparsity or None, default: None Optional ChannelSparsity to apply. If SortingAnalyzer is already sparse, the argument is ignored - unitlocationswidget_params : dict or None, default: None - Parameters for UnitLocationsWidget (see UnitLocationsWidget for details) - unitwaveformswidgets_params : dict or None, default: None - Parameters for UnitWaveformsWidget (see UnitWaveformsWidget for details) - unitwaveformdensitymapwidget_params : dict or None, default: None - Parameters for UnitWaveformDensityMapWidget (see UnitWaveformDensityMapWidget for details) - autocorrelogramswidget_params : dict or None, default: None - Parameters for AutoCorrelogramsWidget (see AutoCorrelogramsWidget for details) - amplitudeswidget_params : dict or None, default: None - Parameters for AmplitudesWidget (see AmplitudesWidget for details) + widget_params : dict or None, default: None + Parameters for the subwidgets in a nested dictionary + unitlocations_params: UnitLocationsWidget (see UnitLocationsWidget for details) + unitwaveforms_params: UnitWaveformsWidget (see UnitWaveformsWidget for details) + unitwaveformdensitymap_params : UnitWaveformDensityMapWidget (see UnitWaveformDensityMapWidget for details) + autocorrelograms_params : AutoCorrelogramsWidget (see AutoCorrelogramsWidget for details) + amplitudes_params : AmplitudesWidget (see AmplitudesWidget for details) """ # possible_backends = {} @@ -50,11 +48,7 @@ def __init__( unit_id, unit_colors=None, sparsity=None, - unitlocationswidget_params=None, - unitwaveformswidget_params=None, - unitwaveformdensitymapwidget_params=None, - autocorrelogramswidget_params=None, - amplitudeswidget_params=None, + widget_params=None, backend=None, **backend_kwargs, ): @@ -63,27 +57,15 @@ def __init__( if unit_colors is None: unit_colors = get_unit_colors(sorting_analyzer) - if unitlocationswidget_params is None: - unitlocationswidget_params = dict() - if unitwaveformswidget_params is None: - unitwaveformswidget_params = dict() - if unitwaveformdensitymapwidget_params is None: - unitwaveformdensitymapwidget_params = dict() - if autocorrelogramswidget_params is None: - autocorrelogramswidget_params = dict() - if amplitudeswidget_params is None: - amplitudeswidget_params = dict() + if widget_params is None: + widget_params = dict() plot_data = dict( sorting_analyzer=sorting_analyzer, unit_id=unit_id, unit_colors=unit_colors, sparsity=sparsity, - unitlocationswidget_params=unitlocationswidget_params, - unitwaveformswidget_params=unitwaveformswidget_params, - unitwaveformdensitymapwidget_params=unitwaveformdensitymapwidget_params, - autocorrelogramswidget_params=autocorrelogramswidget_params, - amplitudeswidget_params=amplitudeswidget_params + widget_params=widget_params, ) BaseWidget.__init__(self, plot_data, backend=backend, **backend_kwargs) @@ -98,11 +80,13 @@ def plot_matplotlib(self, data_plot, **backend_kwargs): sorting_analyzer = dp.sorting_analyzer unit_colors = dp.unit_colors sparsity = dp.sparsity - unitlocationswidget_params = dp.unitlocationswidget_params - unitwaveformswidget_params = dp.unitwaveformswidget_params - unitwaveformdensitymapwidget_params = dp.unitwaveformdensitymapwidget_params - autocorrelogramswidget_params = dp.autocorrelogramswidget_params - amplitudeswidget_params = dp.amplitudeswidget_params + + widget_params = defaultdict(lambda: dict(), dp.widget_params) + unitlocationswidget_params = widget_params['unitlocations_params'] + unitwaveformswidget_params = widget_params['unitwaveforms_params'] + unitwaveformdensitymapwidget_params = widget_params['unitwaveformdensitymap_params'] + autocorrelogramswidget_params = widget_params['autocorrelograms_params'] + amplitudeswidget_params = widget_params['amplitudes_params'] # force the figure without axes if "figsize" not in backend_kwargs: From 87956ccc2791883c98435f1a0ae3482ecce2d2d4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 5 Aug 2024 19:47:11 +0000 Subject: [PATCH 06/11] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/spikeinterface/widgets/unit_summary.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/spikeinterface/widgets/unit_summary.py b/src/spikeinterface/widgets/unit_summary.py index a61ebe2c86..75a399fab5 100644 --- a/src/spikeinterface/widgets/unit_summary.py +++ b/src/spikeinterface/widgets/unit_summary.py @@ -31,7 +31,7 @@ class UnitSummaryWidget(BaseWidget): sparsity : ChannelSparsity or None, default: None Optional ChannelSparsity to apply. If SortingAnalyzer is already sparse, the argument is ignored - widget_params : dict or None, default: None + widget_params : dict or None, default: None Parameters for the subwidgets in a nested dictionary unitlocations_params: UnitLocationsWidget (see UnitLocationsWidget for details) unitwaveforms_params: UnitWaveformsWidget (see UnitWaveformsWidget for details) @@ -58,7 +58,7 @@ def __init__( unit_colors = get_unit_colors(sorting_analyzer) if widget_params is None: - widget_params = dict() + widget_params = dict() plot_data = dict( sorting_analyzer=sorting_analyzer, @@ -82,11 +82,11 @@ def plot_matplotlib(self, data_plot, **backend_kwargs): sparsity = dp.sparsity widget_params = defaultdict(lambda: dict(), dp.widget_params) - unitlocationswidget_params = widget_params['unitlocations_params'] - unitwaveformswidget_params = widget_params['unitwaveforms_params'] - unitwaveformdensitymapwidget_params = widget_params['unitwaveformdensitymap_params'] - autocorrelogramswidget_params = widget_params['autocorrelograms_params'] - amplitudeswidget_params = widget_params['amplitudes_params'] + unitlocationswidget_params = widget_params["unitlocations_params"] + unitwaveformswidget_params = widget_params["unitwaveforms_params"] + unitwaveformdensitymapwidget_params = widget_params["unitwaveformdensitymap_params"] + autocorrelogramswidget_params = widget_params["autocorrelograms_params"] + amplitudeswidget_params = widget_params["amplitudes_params"] # force the figure without axes if "figsize" not in backend_kwargs: From 7ddf482056243e4f3198db163757251cd737bda5 Mon Sep 17 00:00:00 2001 From: Florent Pollet Date: Sat, 7 Sep 2024 19:05:27 -0400 Subject: [PATCH 07/11] fix: change naming convention --- src/spikeinterface/widgets/unit_summary.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/spikeinterface/widgets/unit_summary.py b/src/spikeinterface/widgets/unit_summary.py index 75a399fab5..f1f85b7dc3 100644 --- a/src/spikeinterface/widgets/unit_summary.py +++ b/src/spikeinterface/widgets/unit_summary.py @@ -33,11 +33,11 @@ class UnitSummaryWidget(BaseWidget): If SortingAnalyzer is already sparse, the argument is ignored widget_params : dict or None, default: None Parameters for the subwidgets in a nested dictionary - unitlocations_params: UnitLocationsWidget (see UnitLocationsWidget for details) - unitwaveforms_params: UnitWaveformsWidget (see UnitWaveformsWidget for details) - unitwaveformdensitymap_params : UnitWaveformDensityMapWidget (see UnitWaveformDensityMapWidget for details) - autocorrelograms_params : AutoCorrelogramsWidget (see AutoCorrelogramsWidget for details) - amplitudes_params : AmplitudesWidget (see AmplitudesWidget for details) + unit_locations: UnitLocationsWidget (see UnitLocationsWidget for details) + unit_waveforms: UnitWaveformsWidget (see UnitWaveformsWidget for details) + unit_waveform_density_map: UnitWaveformDensityMapWidget (see UnitWaveformDensityMapWidget for details) + autocorrelograms: AutoCorrelogramsWidget (see AutoCorrelogramsWidget for details) + amplitudes: AmplitudesWidget (see AmplitudesWidget for details) """ # possible_backends = {} @@ -82,11 +82,11 @@ def plot_matplotlib(self, data_plot, **backend_kwargs): sparsity = dp.sparsity widget_params = defaultdict(lambda: dict(), dp.widget_params) - unitlocationswidget_params = widget_params["unitlocations_params"] - unitwaveformswidget_params = widget_params["unitwaveforms_params"] - unitwaveformdensitymapwidget_params = widget_params["unitwaveformdensitymap_params"] - autocorrelogramswidget_params = widget_params["autocorrelograms_params"] - amplitudeswidget_params = widget_params["amplitudes_params"] + unitlocationswidget_params = widget_params["unit_locations"] + unitwaveformswidget_params = widget_params["unit_waveforms"] + unitwaveformdensitymapwidget_params = widget_params["unit_waveform_density_map"] + autocorrelogramswidget_params = widget_params["autocorrelograms"] + amplitudeswidget_params = widget_params["amplitudes"] # force the figure without axes if "figsize" not in backend_kwargs: From 15c51f96ef593b73b35eb1691168b3464bb9128e Mon Sep 17 00:00:00 2001 From: Florent Pollet Date: Tue, 10 Sep 2024 20:25:41 -0400 Subject: [PATCH 08/11] feat: renaming to kwargs + clearer error msg --- src/spikeinterface/widgets/unit_summary.py | 46 ++++++++++++---------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/src/spikeinterface/widgets/unit_summary.py b/src/spikeinterface/widgets/unit_summary.py index f1f85b7dc3..fd7dafd5d6 100644 --- a/src/spikeinterface/widgets/unit_summary.py +++ b/src/spikeinterface/widgets/unit_summary.py @@ -18,26 +18,27 @@ class UnitSummaryWidget(BaseWidget): """ Plot a unit summary. - If amplitudes are alreday computed they are displayed. + If amplitudes are alreday computed, they are displayed. Parameters ---------- - sorting_analyzer : SortingAnalyzer + sorting_analyzer: SortingAnalyzer The SortingAnalyzer object - unit_id : int or str + unit_id: int or str The unit id to plot the summary of - unit_colors : dict or None, default: None + unit_colors: dict or None, default: None If given, a dictionary with unit ids as keys and colors as values, - sparsity : ChannelSparsity or None, default: None + sparsity: ChannelSparsity or None, default: None Optional ChannelSparsity to apply. If SortingAnalyzer is already sparse, the argument is ignored - widget_params : dict or None, default: None + subwidget_kwargs: dict or None, default: None Parameters for the subwidgets in a nested dictionary unit_locations: UnitLocationsWidget (see UnitLocationsWidget for details) unit_waveforms: UnitWaveformsWidget (see UnitWaveformsWidget for details) unit_waveform_density_map: UnitWaveformDensityMapWidget (see UnitWaveformDensityMapWidget for details) autocorrelograms: AutoCorrelogramsWidget (see AutoCorrelogramsWidget for details) amplitudes: AmplitudesWidget (see AmplitudesWidget for details) + Please note that the unit_colors should not be set in subwidget_kwargs, but directly as a parameter of plot_unit_summary. """ # possible_backends = {} @@ -48,7 +49,7 @@ def __init__( unit_id, unit_colors=None, sparsity=None, - widget_params=None, + subwidget_kwargs=None, backend=None, **backend_kwargs, ): @@ -57,15 +58,18 @@ def __init__( if unit_colors is None: unit_colors = get_unit_colors(sorting_analyzer) - if widget_params is None: - widget_params = dict() + if subwidget_kwargs is None: + subwidget_kwargs = dict() + for kwargs in subwidget_kwargs.values(): + if "unit_colors" in kwargs: + raise ValueError("unit_colors should not be set in subwidget_kwargs, but directly as a parameter of plot_unit_summary") plot_data = dict( sorting_analyzer=sorting_analyzer, unit_id=unit_id, unit_colors=unit_colors, sparsity=sparsity, - widget_params=widget_params, + subwidget_kwargs=subwidget_kwargs, ) BaseWidget.__init__(self, plot_data, backend=backend, **backend_kwargs) @@ -81,12 +85,12 @@ def plot_matplotlib(self, data_plot, **backend_kwargs): unit_colors = dp.unit_colors sparsity = dp.sparsity - widget_params = defaultdict(lambda: dict(), dp.widget_params) - unitlocationswidget_params = widget_params["unit_locations"] - unitwaveformswidget_params = widget_params["unit_waveforms"] - unitwaveformdensitymapwidget_params = widget_params["unit_waveform_density_map"] - autocorrelogramswidget_params = widget_params["autocorrelograms"] - amplitudeswidget_params = widget_params["amplitudes"] + subwidget_kwargs = defaultdict(lambda: dict(), dp.subwidget_kwargs) + unitlocationswidget_kwargs = subwidget_kwargs["unit_locations"] + unitwaveformswidget_kwargs = subwidget_kwargs["unit_waveforms"] + unitwaveformdensitymapwidget_kwargs = subwidget_kwargs["unit_waveform_density_map"] + autocorrelogramswidget_kwargs = subwidget_kwargs["autocorrelograms"] + amplitudeswidget_kwargs = subwidget_kwargs["amplitudes"] # force the figure without axes if "figsize" not in backend_kwargs: @@ -117,7 +121,7 @@ def plot_matplotlib(self, data_plot, **backend_kwargs): plot_legend=False, backend="matplotlib", ax=ax1, - **unitlocationswidget_params, + **unitlocationswidget_kwargs, ) unit_locations = sorting_analyzer.get_extension("unit_locations").get_data(outputs="by_unit") @@ -140,7 +144,7 @@ def plot_matplotlib(self, data_plot, **backend_kwargs): sparsity=sparsity, backend="matplotlib", ax=ax2, - **unitwaveformswidget_params, + **unitwaveformswidget_kwargs, ) ax2.set_title(None) @@ -154,7 +158,7 @@ def plot_matplotlib(self, data_plot, **backend_kwargs): same_axis=False, backend="matplotlib", ax=ax3, - **unitwaveformdensitymapwidget_params, + **unitwaveformdensitymapwidget_kwargs, ) ax3.set_ylabel(None) @@ -166,7 +170,7 @@ def plot_matplotlib(self, data_plot, **backend_kwargs): unit_colors=unit_colors, backend="matplotlib", ax=ax4, - **autocorrelogramswidget_params, + **autocorrelogramswidget_kwargs, ) ax4.set_title(None) @@ -184,7 +188,7 @@ def plot_matplotlib(self, data_plot, **backend_kwargs): plot_histograms=True, backend="matplotlib", axes=axes, - **amplitudeswidget_params, + **amplitudeswidget_kwargs, ) fig.suptitle(f"unit_id: {dp.unit_id}") From 3a48d66a52af617fdbbac4bcd94595727dc1cffe Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 11 Sep 2024 00:26:04 +0000 Subject: [PATCH 09/11] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/spikeinterface/widgets/unit_summary.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/spikeinterface/widgets/unit_summary.py b/src/spikeinterface/widgets/unit_summary.py index fd7dafd5d6..652c0f841f 100644 --- a/src/spikeinterface/widgets/unit_summary.py +++ b/src/spikeinterface/widgets/unit_summary.py @@ -62,7 +62,9 @@ def __init__( subwidget_kwargs = dict() for kwargs in subwidget_kwargs.values(): if "unit_colors" in kwargs: - raise ValueError("unit_colors should not be set in subwidget_kwargs, but directly as a parameter of plot_unit_summary") + raise ValueError( + "unit_colors should not be set in subwidget_kwargs, but directly as a parameter of plot_unit_summary" + ) plot_data = dict( sorting_analyzer=sorting_analyzer, From 94abde04386441e3d2994635d4ee545a5b414175 Mon Sep 17 00:00:00 2001 From: Florent Pollet Date: Tue, 10 Sep 2024 20:27:18 -0400 Subject: [PATCH 10/11] feat: default dict comment --- src/spikeinterface/widgets/unit_summary.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/spikeinterface/widgets/unit_summary.py b/src/spikeinterface/widgets/unit_summary.py index fd7dafd5d6..6c39c902eb 100644 --- a/src/spikeinterface/widgets/unit_summary.py +++ b/src/spikeinterface/widgets/unit_summary.py @@ -85,6 +85,7 @@ def plot_matplotlib(self, data_plot, **backend_kwargs): unit_colors = dp.unit_colors sparsity = dp.sparsity + # defaultdict returns empty dict if key not found in subwidget_kwargs subwidget_kwargs = defaultdict(lambda: dict(), dp.subwidget_kwargs) unitlocationswidget_kwargs = subwidget_kwargs["unit_locations"] unitwaveformswidget_kwargs = subwidget_kwargs["unit_waveforms"] From 01485d91646b0234d0ade2df0b98db2d197ca4fc Mon Sep 17 00:00:00 2001 From: Alessio Buccino Date: Wed, 11 Sep 2024 12:17:36 +0200 Subject: [PATCH 11/11] Add space before colons in docs --- src/spikeinterface/widgets/unit_summary.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/spikeinterface/widgets/unit_summary.py b/src/spikeinterface/widgets/unit_summary.py index 851dfa049a..755e60ccbf 100644 --- a/src/spikeinterface/widgets/unit_summary.py +++ b/src/spikeinterface/widgets/unit_summary.py @@ -22,22 +22,22 @@ class UnitSummaryWidget(BaseWidget): Parameters ---------- - sorting_analyzer: SortingAnalyzer + sorting_analyzer : SortingAnalyzer The SortingAnalyzer object - unit_id: int or str + unit_id : int or str The unit id to plot the summary of - unit_colors: dict or None, default: None + unit_colors : dict or None, default: None If given, a dictionary with unit ids as keys and colors as values, - sparsity: ChannelSparsity or None, default: None + sparsity : ChannelSparsity or None, default: None Optional ChannelSparsity to apply. If SortingAnalyzer is already sparse, the argument is ignored - subwidget_kwargs: dict or None, default: None + subwidget_kwargs : dict or None, default: None Parameters for the subwidgets in a nested dictionary - unit_locations: UnitLocationsWidget (see UnitLocationsWidget for details) - unit_waveforms: UnitWaveformsWidget (see UnitWaveformsWidget for details) - unit_waveform_density_map: UnitWaveformDensityMapWidget (see UnitWaveformDensityMapWidget for details) - autocorrelograms: AutoCorrelogramsWidget (see AutoCorrelogramsWidget for details) - amplitudes: AmplitudesWidget (see AmplitudesWidget for details) + unit_locations : UnitLocationsWidget (see UnitLocationsWidget for details) + unit_waveforms : UnitWaveformsWidget (see UnitWaveformsWidget for details) + unit_waveform_density_map : UnitWaveformDensityMapWidget (see UnitWaveformDensityMapWidget for details) + autocorrelograms : AutoCorrelogramsWidget (see AutoCorrelogramsWidget for details) + amplitudes : AmplitudesWidget (see AmplitudesWidget for details) Please note that the unit_colors should not be set in subwidget_kwargs, but directly as a parameter of plot_unit_summary. """