-
Notifications
You must be signed in to change notification settings - Fork 236
Add waveform PTP metric #4266
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
1
commit into
SpikeInterface:main
Choose a base branch
from
alejoe91:wfs-ptp-3
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.
+150
−107
Open
Add waveform PTP metric #4266
Changes from all commits
Commits
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 |
|---|---|---|
| @@ -1,8 +1,85 @@ | ||
| import pytest | ||
|
|
||
| from spikeinterface.postprocessing.tests.conftest import _small_sorting_analyzer | ||
| from spikeinterface.core import ( | ||
| generate_ground_truth_recording, | ||
| create_sorting_analyzer, | ||
| ) | ||
|
|
||
| job_kwargs = dict(n_jobs=2, progress_bar=True, chunk_duration="1s") | ||
|
|
||
|
|
||
| def make_small_analyzer(): | ||
| recording, sorting = generate_ground_truth_recording( | ||
| durations=[2.0], | ||
| num_units=10, | ||
| seed=1205, | ||
| ) | ||
|
|
||
| channel_ids_as_integers = [id for id in range(recording.get_num_channels())] | ||
| unit_ids_as_integers = [id for id in range(sorting.get_num_units())] | ||
| recording = recording.rename_channels(new_channel_ids=channel_ids_as_integers) | ||
| sorting = sorting.rename_units(new_unit_ids=unit_ids_as_integers) | ||
|
|
||
| sorting = sorting.select_units([2, 7, 0], ["#3", "#9", "#4"]) | ||
|
|
||
| sorting_analyzer = create_sorting_analyzer(recording=recording, sorting=sorting, format="memory") | ||
|
|
||
| extensions_to_compute = { | ||
| "random_spikes": {"seed": 1205}, | ||
| "noise_levels": {"seed": 1205}, | ||
| "waveforms": {}, | ||
| "templates": {"operators": ["average", "median"]}, | ||
| "spike_amplitudes": {}, | ||
| "spike_locations": {}, | ||
| "principal_components": {}, | ||
| } | ||
|
|
||
| sorting_analyzer.compute(extensions_to_compute) | ||
|
|
||
| return sorting_analyzer | ||
|
|
||
|
|
||
| @pytest.fixture(scope="module") | ||
| def small_sorting_analyzer(): | ||
| return _small_sorting_analyzer() | ||
| return make_small_analyzer() | ||
|
|
||
|
|
||
| @pytest.fixture(scope="module") | ||
| def sorting_analyzer_simple(): | ||
| # we need high firing rate for amplitude_cutoff | ||
| recording, sorting = generate_ground_truth_recording( | ||
| durations=[ | ||
| 120.0, | ||
| ], | ||
| sampling_frequency=30_000.0, | ||
| num_channels=6, | ||
| num_units=10, | ||
| generate_sorting_kwargs=dict(firing_rates=10.0, refractory_period_ms=4.0), | ||
| generate_unit_locations_kwargs=dict( | ||
| margin_um=5.0, | ||
| minimum_z=5.0, | ||
| maximum_z=20.0, | ||
| ), | ||
| generate_templates_kwargs=dict( | ||
| unit_params=dict( | ||
| alpha=(200.0, 500.0), | ||
| ) | ||
| ), | ||
| noise_kwargs=dict(noise_levels=5.0, strategy="tile_pregenerated"), | ||
| seed=1205, | ||
| ) | ||
|
|
||
| channel_ids_as_integers = [id for id in range(recording.get_num_channels())] | ||
| unit_ids_as_integers = [id for id in range(sorting.get_num_units())] | ||
| recording = recording.rename_channels(new_channel_ids=channel_ids_as_integers) | ||
| sorting = sorting.rename_units(new_unit_ids=unit_ids_as_integers) | ||
|
|
||
| sorting_analyzer = create_sorting_analyzer(sorting, recording, format="memory", sparse=True) | ||
|
|
||
| sorting_analyzer.compute("random_spikes", max_spikes_per_unit=300, seed=1205) | ||
| sorting_analyzer.compute("noise_levels") | ||
| sorting_analyzer.compute("waveforms", **job_kwargs) | ||
| sorting_analyzer.compute("templates") | ||
| sorting_analyzer.compute(["spike_amplitudes", "spike_locations"], **job_kwargs) | ||
|
|
||
| return sorting_analyzer |
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 was deleted.
Oops, something went wrong.
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
17 changes: 17 additions & 0 deletions
17
src/spikeinterface/metrics/spiketrain/tests/test_spiketrain_metrics.py
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,17 @@ | ||
| import numpy as np | ||
| from spikeinterface.metrics.spiketrain import ( | ||
| compute_firing_rates, | ||
| compute_num_spikes, | ||
| ) | ||
|
|
||
|
|
||
| def test_calculate_firing_ratess(sorting_analyzer_simple): | ||
| sorting_analyzer = sorting_analyzer_simple | ||
| firing_rates = compute_firing_rates(sorting_analyzer) | ||
| assert np.all(np.array(list(firing_rates.values())) > 0) | ||
|
|
||
|
|
||
| def test_calculate_num_spikes(sorting_analyzer_simple): | ||
| sorting_analyzer = sorting_analyzer_simple | ||
| num_spikes = compute_num_spikes(sorting_analyzer) | ||
| assert np.all(np.array(list(num_spikes.values())) > 0) |
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.
maybe should be a more explicit ref to the bombcel paper?