-
Notifications
You must be signed in to change notification settings - Fork 241
More possibilities for gt generation #4289
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
yger
wants to merge
11
commits into
SpikeInterface:main
Choose a base branch
from
yger:advanced_gt
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.
+87
−41
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ee0e270
WIP
yger f92cf38
WIP
yger 58037c5
Updating generator
yger 01856ce
More inputs
yger 2947b35
Merge branch 'main' of github.com:spikeinterface/spikeinterface into …
yger a64dc9e
Merge branch 'main' of github.com:spikeinterface/spikeinterface into …
yger b3db151
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 97a5a92
Checks
yger b1e4e96
Merge branch 'main' of https://github.com/SpikeInterface/spikeinterfa…
yger 5078f80
WIP
yger 3defe3c
[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 |
|---|---|---|
|
|
@@ -309,7 +309,9 @@ def generate_drifting_recording( | |
| duration=600.0, | ||
| sampling_frequency=30000.0, | ||
| probe_name="Neuropixels1-128", | ||
| probe=None, | ||
| generate_probe_kwargs=None, | ||
| unit_locations=None, | ||
| generate_unit_locations_kwargs=dict( | ||
| margin_um=20.0, | ||
| minimum_z=5.0, | ||
|
|
@@ -321,6 +323,7 @@ def generate_drifting_recording( | |
| # distribution="multimodal", | ||
| # num_modes=2, | ||
| ), | ||
| displacement_data=None, | ||
| generate_displacement_vector_kwargs=dict( | ||
| displacement_sampling_frequency=5.0, | ||
| drift_start_um=[0, 20], | ||
|
|
@@ -347,7 +350,9 @@ def generate_drifting_recording( | |
| ellipse_angle=(0, np.pi * 2), | ||
| ), | ||
| ), | ||
| sorting=None, | ||
| generate_sorting_kwargs=dict(firing_rates=(2.0, 8.0), refractory_period_ms=4.0), | ||
| noise=None, | ||
| generate_noise_kwargs=dict(noise_levels=(6.0, 8.0), spatial_decay=25.0), | ||
| extra_outputs=False, | ||
| seed=None, | ||
|
|
@@ -364,20 +369,30 @@ def generate_drifting_recording( | |
| The duration in seconds. | ||
| sampling_frequency : float, dfault: 30000. | ||
| The sampling frequency. | ||
| probe: Probe object, default None | ||
| If provided, the Probe geometry to consider | ||
| probe_name : str, default: "Neuropixels1-128" | ||
| The probe type if generate_probe_kwargs is None. | ||
| The probe type if generate_probe_kwargs is None and probe is None. | ||
| generate_probe_kwargs : None or dict | ||
| A dict to generate the probe, this supersede probe_name when not None. | ||
| unit_locations: array, default None | ||
| The unit locations of the cells | ||
| generate_unit_locations_kwargs : dict | ||
| Parameters given to generate_unit_locations(). | ||
| Parameters given to generate_unit_locations() if unit_locations is None | ||
| displacement_data: tuple of arrays, default None | ||
| The output of generate_displacement_vector(), if precomputed by the user | ||
| generate_displacement_vector_kwargs : dict | ||
| Parameters given to generate_displacement_vector(). | ||
| Parameters given to generate_displacement_vector() if displacement_data is None | ||
| generate_templates_kwargs : dict | ||
| Parameters given to generate_templates() | ||
| sorting: NumpySorting, default None | ||
| The sorting to generate data from | ||
| generate_sorting_kwargs : dict | ||
| Parameters given to generate_sorting(). | ||
| Parameters given to generate_sorting() if sorting is None | ||
| noise: NoiseGenerator, default None | ||
| Noise generator used to generate background noise | ||
| generate_noise_kwargs : dict | ||
| Parameters given to generate_noise(). | ||
| Parameters given to generate_noise() if no noise is None | ||
| extra_outputs : bool, default False | ||
| Return optionaly a dict with more variables. | ||
| seed : None ot int | ||
|
|
@@ -406,12 +421,33 @@ def generate_drifting_recording( | |
|
|
||
| seed = _ensure_seed(seed) | ||
|
|
||
| if sorting is None: | ||
| sorting = generate_sorting( | ||
| num_units=num_units, | ||
| sampling_frequency=sampling_frequency, | ||
| durations=[ | ||
| duration, | ||
| ], | ||
| **generate_sorting_kwargs, | ||
| seed=seed, | ||
| ) | ||
| else: | ||
| num_units = sorting.get_num_units() | ||
| sampling_frequency = sorting.sampling_frequency | ||
| if sorting._recording is not None: | ||
| assert ( | ||
| sorting.get_total_duration() == duration | ||
| ), "Sorting should have the same duration as the generated data" | ||
|
|
||
| # probe | ||
| if generate_probe_kwargs is None: | ||
| generate_probe_kwargs = _toy_probes[probe_name] | ||
| probe = generate_multi_columns_probe(**generate_probe_kwargs) | ||
| num_channels = probe.get_contact_count() | ||
| probe.set_device_channel_indices(np.arange(num_channels)) | ||
| if probe is None: | ||
| if generate_probe_kwargs is None: | ||
| generate_probe_kwargs = _toy_probes[probe_name] | ||
|
|
||
| probe = generate_multi_columns_probe(**generate_probe_kwargs) | ||
| num_channels = probe.get_contact_count() | ||
| probe.set_device_channel_indices(np.arange(num_channels)) | ||
|
|
||
| channel_locations = probe.contact_positions | ||
| # import matplotlib.pyplot as plt | ||
| # import probeinterface.plotting | ||
|
|
@@ -420,20 +456,34 @@ def generate_drifting_recording( | |
| # plt.show() | ||
|
|
||
| # unit locations | ||
| unit_locations = generate_unit_locations( | ||
| num_units, | ||
| channel_locations, | ||
| seed=seed, | ||
| **generate_unit_locations_kwargs, | ||
| ) | ||
|
|
||
| ( | ||
| unit_displacements, | ||
| displacement_vectors, | ||
| displacement_unit_factor, | ||
| displacement_sampling_frequency, | ||
| displacements_steps, | ||
| ) = generate_displacement_vector(duration, unit_locations[:, :2], seed=seed, **generate_displacement_vector_kwargs) | ||
| if unit_locations is None: | ||
| unit_locations = generate_unit_locations( | ||
| num_units, | ||
| channel_locations, | ||
| seed=seed, | ||
| **generate_unit_locations_kwargs, | ||
| ) | ||
| else: | ||
| assert len(unit_locations) == num_units, "We should have num_units unit locations" | ||
|
|
||
| if displacement_data is None: | ||
| ( | ||
| unit_displacements, | ||
| displacement_vectors, | ||
| displacement_unit_factor, | ||
| displacement_sampling_frequency, | ||
| displacements_steps, | ||
| ) = generate_displacement_vector( | ||
| duration, unit_locations[:, :2], seed=seed, **generate_displacement_vector_kwargs | ||
| ) | ||
| else: | ||
| ( | ||
|
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 would make a dict no ? Or at least a named tuple.
Collaborator
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. I don't know, this was to be consistent, but I can make it a dict if you prefer |
||
| unit_displacements, | ||
| displacement_vectors, | ||
| displacement_unit_factor, | ||
| displacement_sampling_frequency, | ||
| displacements_steps, | ||
| ) = displacement_data | ||
|
|
||
| # unit_params need to be fixed before the displacement steps | ||
| generate_templates_kwargs = generate_templates_kwargs.copy() | ||
|
|
@@ -470,16 +520,6 @@ def generate_drifting_recording( | |
|
|
||
| drifting_templates = DriftingTemplates.from_static_templates(templates) | ||
|
|
||
| sorting = generate_sorting( | ||
| num_units=num_units, | ||
| sampling_frequency=sampling_frequency, | ||
| durations=[ | ||
| duration, | ||
| ], | ||
| **generate_sorting_kwargs, | ||
| seed=seed, | ||
| ) | ||
|
|
||
| sorting.set_property("gt_unit_locations", unit_locations) | ||
|
|
||
| distances = np.linalg.norm(unit_locations[:, np.newaxis, :2] - channel_locations[np.newaxis, :, :], axis=2) | ||
|
|
@@ -493,13 +533,18 @@ def generate_drifting_recording( | |
| drifting_templates.templates_array_moved = templates_array_moved | ||
| drifting_templates.displacements = displacements_steps | ||
|
|
||
| noise = generate_noise( | ||
| probe=probe, | ||
| sampling_frequency=sampling_frequency, | ||
| durations=[duration], | ||
| seed=seed, | ||
| **generate_noise_kwargs, | ||
| ) | ||
| if noise is None: | ||
| noise = generate_noise( | ||
| probe=probe, | ||
| sampling_frequency=sampling_frequency, | ||
| durations=[duration], | ||
| seed=seed, | ||
| **generate_noise_kwargs, | ||
| ) | ||
yger marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| else: | ||
| assert noise.sampling_frequency == sampling_frequency, "Noise sampling frequency mismatch" | ||
| assert noise.probe.get_contact_count() == probe.get_contact_count(), "Noise num channels mismatch" | ||
| assert noise.get_total_duration() == duration, "Noise duration should be the same as the recording duration" | ||
|
|
||
| static_recording = InjectDriftingTemplatesRecording( | ||
| sorting=sorting, | ||
|
|
@@ -531,6 +576,7 @@ def generate_drifting_recording( | |
| displacement_unit_factor=displacement_unit_factor, | ||
| unit_displacements=unit_displacements, | ||
| templates=templates, | ||
| generate_templates_kwargs=generate_templates_kwargs, | ||
| ) | ||
| return static_recording, drifting_recording, sorting, extra_infos | ||
| else: | ||
|
|
||
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.