-
Notifications
You must be signed in to change notification settings - Fork 263
Use probeinterface's renamed Neuropixels readers and new probe detectors #4593
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
h-mayorquin
wants to merge
3
commits into
SpikeInterface:main
Choose a base branch
from
h-mayorquin:neuropixels_use_new_probe_extraciton_functions
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.
+32
−14
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,13 @@ | ||
| from pathlib import Path | ||
| import warnings | ||
| import numpy as np | ||
|
|
||
| import packaging | ||
|
|
||
| import packaging.version | ||
| import probeinterface | ||
| from spikeinterface.core.core_tools import define_function_from_class | ||
| from spikeinterface.extractors.neuropixels_utils import ( | ||
| get_neuropixels_sample_shifts_from_probe, | ||
| compute_saturation_threshold_from_probe, | ||
| ) | ||
|
|
||
| from .neobaseextractor import NeoBaseRecordingExtractor | ||
|
|
||
|
|
@@ -56,12 +59,29 @@ def __init__( | |
| ) | ||
| self._kwargs.update(dict(file_path=str(Path(file_path).absolute()), stream_id=stream_id)) | ||
|
|
||
| probegroup = probeinterface.read_spikegadgets(file_path, raise_error=False) | ||
| # TODO: add adc sample shifts and saturation levels if available in the probe metadata | ||
|
|
||
| if probegroup is not None: | ||
| if probeinterface.has_spikegadgets_neuropixels_probes(file_path): | ||
| probegroup = probeinterface.read_spikegadgets_neuropixels(file_path) | ||
| self.set_probegroup(probegroup, in_place=True) | ||
|
|
||
| # get inter-sample shifts based on the probe information and mux channels | ||
| sample_shifts = np.array([]) | ||
| saturation_thresholds_uV = [] | ||
| for probe in probegroup.probes: | ||
| sample_shifts_probe = get_neuropixels_sample_shifts_from_probe(probe) | ||
| if sample_shifts_probe is not None: | ||
| sample_shifts = np.concatenate([sample_shifts, sample_shifts_probe]) | ||
| # add saturation levels if available | ||
| saturation_threshold_uV_probe = compute_saturation_threshold_from_probe(probe, self.stream_id) | ||
| if saturation_threshold_uV_probe is not None: | ||
| saturation_thresholds_uV.append(saturation_threshold_uV_probe) | ||
|
|
||
| if len(sample_shifts) > self.get_num_channels(): | ||
|
Comment on lines
+77
to
+78
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. should this be equal? |
||
| self.set_property("inter_sample_shift", sample_shifts) | ||
| if len(set(saturation_thresholds_uV)) == 1: | ||
| self.annotate(saturation_threshold_uV=saturation_thresholds_uV[0]) | ||
| else: | ||
| warnings.warn("Multiple saturation thresholds found for different probes, unable to annotate.") | ||
|
|
||
| @classmethod | ||
| def map_to_neo_kwargs(cls, file_path): | ||
| neo_kwargs = {"filename": str(file_path)} | ||
|
|
||
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.
The function
get_neuropixels_sample_shifts_from_probereturns the sample shifts in probe (contact) order, so before you set them as a channel property you need to re-wire them into channel order. This works for SpikeGLX and OpenEphys without any extra step because probeinterface already wires those probes so their contacts are in the order of the binary traces (device_channel_indices = arange), so contact order already equals channel order.We could do that re-wiring here too, but it is more complicated than in the SpikeGLX and OpenEphys case. Those write one file per probe, while SpikeGadgets puts more than one probe in a single file. For the dataset with neuropixels that we have on gin already (
SpikeGadgets_test_data_2xNpix1.0_20240318_173658.rec, the two probes are interleaved in that single binary in blocks of 32 channels (channels 0-31 are probe 0, 32-63 are probe 1, 64-95 are probe 0, and so on), so a probe's contacts do not map to a contiguous run of channels anddevice_channel_indicesis a real permutation (hwChan) rather thanarange. That is why the currentnp.concatenateof per-probe shifts lands on the wrong channels (704 of 768 on this fixture).I see three possible paths forward:
get_neuropixels_sample_shifts_from_probethroughdevice_channel_indices. Each probe'sdevice_channel_indicestells you which recording channel each contact maps to, so you scatter the per-probe shifts into a channel-length array:Re-sort at the probeinterface level using the global device channel indices, sorting each probe/group so the contacts come out in channel order. I am not sure this is possible, since each probe owns a non-contiguous, interleaved set of channels, so a per-probe
arangemight not be doable but given that you guys like that pattern maybe you might be able to find it. I don't like the pattern and you know how motivated thinking is a horrible beast.Use the property from the probe after you set it. This does the rearranging after we set it on the recording (so it is already re-ordered by
set_probegroup): readself.get_property("contact_vector")["adc_sample_order"], which is already one value per channel in channel order, and set the property from that.I honestly prefer 1: explicit is better than implicit, and it will not clash with any of the current Probe refactorings like option 3 might. Option 2 will require more work on your side and I would like to merge this and then do that if you want to move that way.