Skip to content
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

Code for getting a SortingExtractor with timestamps in synch with current recording in dandi. #60

Closed
h-mayorquin opened this issue Apr 30, 2024 · 1 comment · Fixed by #93
Assignees

Comments

@h-mayorquin
Copy link
Contributor

from dandi.dandiapi import DandiAPIClient
from spikeinterface.extractors import NwbRecordingExtractor, IblSortingExtractor

client = DandiAPIClient.for_dandi_instance("dandi")

# We specifiy a dataset by is dandiset_id and its asset path
dandiset_id = "000409"
dandiset = client.get_dandiset(dandiset_id)

asset_path = "sub-KS042/sub-KS042_ses-8c552ddc-813e-4035-81cc-3971b57efe65_behavior+ecephys+image.nwb"
recording_asset = dandiset.get_asset_by_path(path=asset_path)
url = recording_asset.get_content_url(follow_redirects=True, strip_query=True)
file_path = url


# Note that this ElectricalSeries corresponds to the data from probe 00
electrical_series_path = "acquisition/ElectricalSeriesAp00"
recording = NwbRecordingExtractor(file_path=file_path, stream_mode="remfile", electrical_series_path=electrical_series_path)  
session_id = recording._file["general"]["session_id"][()].decode()
eid = session_id.split("-chunking")[0] # eid : experiment id


# We use the sorting extractor from the IBL spike sorting pipeline that matches with eid
from one.api import ONE
ONE.setup(base_url='https://openalyx.internationalbrainlab.org', silent=True)
one_instance = ONE(password='international')


# Then we match the available probes with the probe number in the electrical series path
pids, probes = one_instance.eid2pid(eid)
probe_number = electrical_series_path.split("Ap")[-1]

sorting_pid = None 
for pid, probe in zip(pids, probes):
    probe_number_in_pid = probe[-2:]
    if probe_number_in_pid == probe_number:
        sorting_pid = pid
        break
    
    
sorting = IblSortingExtractor(pid=sorting_pid, one=one_instance, good_clusters_only=True)

Note that Ibl might have been modified
SpikeInterface/spikeinterface#2617

@CodyCBakerPhD
Copy link
Member

@CodyCBakerPhD CodyCBakerPhD linked a pull request Sep 29, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants