-
Notifications
You must be signed in to change notification settings - Fork 280
Fix raster plot handling of segment times where t_start is not zero.
#4790
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
JoeZiminski
wants to merge
24
commits into
main
Choose a base branch
from
fix-raster-plot-segment
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
24 commits
Select commit
Hold shift + click to select a range
f1a3365
wip
JoeZiminski e3c603e
update.
JoeZiminski 434d58e
Merge branch 'main' into fix-raster-plot-segment
JoeZiminski b2b6112
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 22c6e16
Tidy up,tests.
JoeZiminski e572373
Tidy
JoeZiminski 0d1745a
Fix linting.
JoeZiminski acf27b0
Small tidy up.
JoeZiminski 1f31ce7
Fix sorting bug, roll out across all plots, remove durations.
JoeZiminski c9e8e77
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 3851db2
Update tests.
JoeZiminski 9ead884
Add comment.
JoeZiminski 98143d1
Remove unused var.
JoeZiminski 539b7ed
Fix raster widgets.
JoeZiminski 48ca1c9
Fix rasters.
JoeZiminski 25de7b4
Convert to dict.
JoeZiminski 5ae61c4
Util for conversion to boundaries.
JoeZiminski da4456c
Tidy.
JoeZiminski c000d5b
Linting.
JoeZiminski edf00d4
Remove stuff now in PR 4796.
JoeZiminski 3e9d805
Fix test.
JoeZiminski 033d3a3
Fix tests.
JoeZiminski 244d985
Fix tests....again.
JoeZiminski 6db46de
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| """ | ||
| Generate a multi-segment recording whose segments start at non-zero times, | ||
| then plot a raster of the segments. | ||
| """ | ||
|
|
||
| import matplotlib | ||
|
|
||
| matplotlib.use("QtAgg") | ||
| import matplotlib.pyplot as plt | ||
|
|
||
| from spikeinterface.core import append_recordings, append_sortings, create_sorting_analyzer, generate_ground_truth_recording | ||
| from spikeinterface.generation import generate_drifting_recording | ||
| from spikeinterface.preprocessing import compute_motion | ||
| import spikeinterface.widgets as sw | ||
|
|
||
|
|
||
| def make_multi_segment_recording(num_segments=3, seed=2205): | ||
| """Build a multi-segment recording and sorting with non-zero segment start times.""" | ||
|
|
||
| common_kwargs = dict( | ||
| durations=[10.0], | ||
| sampling_frequency=30000.0, | ||
| num_channels=64, | ||
| num_units=60, | ||
| ) | ||
|
|
||
| recordings = [] | ||
| sortings = [] | ||
| # Offsets so segments do NOT start at time zero. | ||
| start_time_offsets = [5.0, 120.0, 260.0] | ||
|
|
||
| for seg in range(num_segments): | ||
| recording, sorting = generate_ground_truth_recording(seed=seed + seg, **common_kwargs) | ||
| # Give this segment a non-zero start time. | ||
| recording.shift_times(shift=start_time_offsets[seg % len(start_time_offsets)]) | ||
| recordings.append(recording) | ||
| sortings.append(sorting) | ||
|
|
||
| multi_segment_recording = append_recordings(recordings) | ||
| multi_segment_sorting = append_sortings(sortings) | ||
| return multi_segment_recording, multi_segment_sorting | ||
|
|
||
|
|
||
| def plot_amplitudes_output(recording, sorting): | ||
| """Plot spike amplitudes for a few units across all recording segments.""" | ||
|
|
||
| analyzer = create_sorting_analyzer(sorting=sorting, recording=recording, format="memory") | ||
| analyzer.compute(["random_spikes", "waveforms", "templates", "spike_amplitudes"]) | ||
|
|
||
| amplitude_widget = sw.plot_amplitudes( | ||
| analyzer, | ||
| unit_ids=sorting.unit_ids[:6], | ||
| segment_indices=list(range(sorting.get_num_segments())), | ||
| plot_histograms=True, | ||
| ) | ||
| amplitude_widget.figure.canvas.manager.set_window_title("Amplitude output") | ||
| amplitude_widget.axes.flatten()[0].set_title("Spike amplitudes") | ||
|
|
||
|
|
||
| def main(): | ||
| recording, sorting = make_multi_segment_recording() | ||
| sorting.register_recording(recording) | ||
|
|
||
| for seg in range(recording.get_num_segments()): | ||
| print(f" segment {seg}: start={recording.get_start_time(seg):.1f}s end={recording.get_end_time(seg):.1f}s") | ||
|
|
||
| # Plot a raster of all segments. | ||
| segment_indices = list(range(sorting.get_num_segments())) | ||
| # sw.plot_rasters(sorting, segment_indices=segment_indices) | ||
| # plot_amplitudes_output(recording, sorting) | ||
|
|
||
|
|
||
| motion_recording = recording.select_segments([0]) | ||
| motion, motion_info = compute_motion( | ||
| motion_recording, | ||
| preset="rigid_fast", | ||
| estimate_motion_kwargs=dict(method="decentralized", conv_engine="numpy"), | ||
| n_jobs=-1, | ||
| progress_bar=True, | ||
| output_motion_info=True, | ||
| ) | ||
| print(motion) | ||
| motion_widget = sw.plot_motion_info(motion_info, recording=motion_recording) | ||
| motion_widget.figure.canvas.manager.set_window_title("Motion output") | ||
| motion_widget.figure.canvas.draw() | ||
| motion_widget.figure.show() | ||
|
|
||
| plt.show(block=True) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
This is unused in main, but I guess this is public facing and will need a deprecation warning? (although maybe not if its never used anyway)