-
Notifications
You must be signed in to change notification settings - Fork 235
Allow create_sorting_analyzer to accept dicts
#4037
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
8301ae2
4817c45
96a1819
9b5fd01
4b76f2f
9a46c3e
ad5eff9
8f5f103
433a2ae
c2dfc55
3d7d6c5
38f8533
ac6bf72
492d1fa
11c96d4
5b8ba0e
36312f3
78af5b6
1eb05c7
b9cf1d8
f8b3b26
97073b6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,8 +21,7 @@ | |
|
|
||
| import spikeinterface | ||
|
|
||
| from .baserecording import BaseRecording | ||
| from .basesorting import BaseSorting | ||
| from spikeinterface.core import BaseRecording, BaseSorting, aggregate_channels, aggregate_units | ||
|
|
||
| from .recording_tools import check_probe_do_not_overlap, get_rec_attributes, do_recording_attributes_match | ||
| from .core_tools import ( | ||
|
|
@@ -54,6 +53,7 @@ def create_sorting_analyzer( | |
| folder=None, | ||
| sparse=True, | ||
| sparsity=None, | ||
| set_sparsity_by_dict_key=False, | ||
| return_scaled=None, | ||
| return_in_uV=True, | ||
| overwrite=False, | ||
|
|
@@ -71,10 +71,10 @@ def create_sorting_analyzer( | |
|
|
||
| Parameters | ||
| ---------- | ||
| sorting : Sorting | ||
| The sorting object | ||
| recording : Recording | ||
| The recording object | ||
| sorting : Sorting | dict | ||
| The sorting object, or a dict of them | ||
| recording : Recording | dict | ||
| The recording object, or a dict of them | ||
| folder : str or Path or None, default: None | ||
| The folder where analyzer is cached | ||
| format : "memory | "binary_folder" | "zarr", default: "memory" | ||
|
|
@@ -88,6 +88,9 @@ def create_sorting_analyzer( | |
| You can control `estimate_sparsity()` : all extra arguments are propagated to it (included job_kwargs) | ||
| sparsity : ChannelSparsity or None, default: None | ||
| The sparsity used to compute exensions. If this is given, `sparse` is ignored. | ||
| set_sparsity_by_dict_key : bool, default: False | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I support this.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it's False by default, some tetrode people will have un-sparsified tetrode bundles (not great, but ok) So I vote False! |
||
| If True and passing recording and sorting dicts, will set the sparsity based on the dict keys, | ||
| and other `sparsity_kwargs` are overwritten. If False, use other sparsity settings. | ||
| return_scaled : bool | None, default: None | ||
| DEPRECATED. Use return_in_uV instead. | ||
| All extensions that play with traces will use this global return_in_uV : "waveforms", "noise_levels", "templates". | ||
|
|
@@ -139,6 +142,34 @@ def create_sorting_analyzer( | |
| In some situation, sparsity is not needed, so to make it fast creation, you need to turn | ||
| sparsity off (or give external sparsity) like this. | ||
| """ | ||
|
|
||
| if isinstance(sorting, dict) and isinstance(recording, dict): | ||
|
|
||
| if sorting.keys() != recording.keys(): | ||
| raise ValueError( | ||
| f"Keys of `sorting`, {sorting.keys()}, and `recording`, {recording.keys()}, dicts do not match." | ||
| ) | ||
|
|
||
| aggregated_recording = aggregate_channels(recording) | ||
| aggregated_sorting = aggregate_units(sorting) | ||
|
|
||
| if set_sparsity_by_dict_key: | ||
| sparsity_kwargs = {"method": "by_property", "by_property": "aggregation_key"} | ||
|
|
||
| return create_sorting_analyzer( | ||
| sorting=aggregated_sorting, | ||
| recording=aggregated_recording, | ||
| format=format, | ||
| folder=folder, | ||
| sparse=sparse, | ||
| sparsity=sparsity, | ||
| return_scaled=return_scaled, | ||
| return_in_uV=return_in_uV, | ||
| overwrite=overwrite, | ||
| backend_options=backend_options, | ||
| **sparsity_kwargs, | ||
| ) | ||
|
|
||
| if format != "memory": | ||
| if format == "zarr": | ||
| if not is_path_remote(folder): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How? Do keys of the dict need to match up? Will the user know how the sorting dict looks vs the recording dict?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could check that keys are the same in the same order no ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah we either do that for the users internally or need to explain it here. So I think doing it ourselves is fine. Chris is doing a dict key comparison below but I haven't tested it to see if it checks the order or just the presence of the same keys.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to hopefully make things clearer.
The order of keys doesn't matter: when you aggregate, the link between the recording channels and unit ids is independent of this dict stuff I'm adding. Added a test to check this is true.