-
Notifications
You must be signed in to change notification settings - Fork 17
Add events handling: trace/map + new view for aliggned/rasters + PSTHs #218
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
Open
alejoe91
wants to merge
5
commits into
SpikeInterface:main
Choose a base branch
from
alejoe91:events
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
11ce0b4
Add events handling: trace/map + new view for aliggned/rasters + PSTHs
alejoe91 80716ec
EventView in panel
alejoe91 8d7ac18
centralize toolbars in traces
alejoe91 c2d0003
Add events on Trace/TraceMap for panel
alejoe91 02f80a6
wip: move event functions to event_tools
alejoe91 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| import numpy as np | ||
|
|
||
| from spikeinterface.core import BaseEvent | ||
|
|
||
| def parse_events(events, controller, verbose=False): | ||
| """Parse events input into a standard format. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| events : dict | BaseEvent | ||
| BaseEvent object or a dictionary where keys are event names and values are dictionaries with at least a | ||
| 'samples' key or 'times' key. | ||
| controller : Controller | ||
| Controller object managing the event parsing. | ||
| verbose : bool, default: False | ||
| Whether to print verbose messages. | ||
|
|
||
| Returns | ||
| ------- | ||
| parsed_events : dict | ||
| Parsed events dictionary. The keys are event names, and the values are lists of numpy arrays of event sample indices. | ||
| Each element corresponds to a segment in the recording. | ||
| """ | ||
| parsed_events = {} | ||
| if isinstance(events, dict): | ||
| for key, val in events.items(): | ||
| if not isinstance(val, dict): | ||
| if verbose: | ||
| print(f'\tSkipping event {key}: not a dict') | ||
| continue | ||
| if 'samples' not in val and 'times' not in val: | ||
| if verbose: | ||
| print(f'\tSkipping event {key}: missing samples or times') | ||
| continue | ||
| if 'times' in val: | ||
| samples_data = val['times'] | ||
| convert_to_samples = True | ||
| else: | ||
| samples_data = val['samples'] | ||
| convert_to_samples = False | ||
| if controller.num_segments > 1: | ||
| if not len(samples_data) == controller.num_segments: | ||
| if verbose: | ||
| print(f'\tSkipping event {key}: inconsistent number of samples') | ||
| continue | ||
| else: | ||
| # here we make sure samples is a list of list | ||
| if np.array(samples_data).ndim == 1: | ||
| samples_data = [samples_data] | ||
| if convert_to_samples: | ||
| parsed_events[key] = [np.array(controller.time_to_sample_index(s)) for s in samples_data] | ||
| else: | ||
| parsed_events[key] = [np.array(s) for s in samples_data] | ||
| elif isinstance(events, BaseEvent): | ||
| event_names = events.channel_ids | ||
| parsed_events = { | ||
| event_name: [] for event_name in event_names | ||
| } | ||
| for event_name in event_names: | ||
| for segment_index in range(controller.num_segments): | ||
| event_times_segment = events.get_event_times( | ||
| channel_id=event_name, | ||
| segment_index=segment_index | ||
| ) | ||
| event_samples_segment = controller.time_to_sample_index( | ||
| event_times_segment | ||
| ) | ||
| parsed_events[event_name].append(np.array(event_samples_segment)) | ||
| else: | ||
| if verbose: | ||
| print('\tSkipping events: not a dict or BaseEvent') | ||
|
|
||
| return parsed_events |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Lets move this events handling in a separate function no ?