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

How to easily extract spike times related to a recording chunk. #3675

Open
Djoels opened this issue Feb 6, 2025 · 3 comments
Open

How to easily extract spike times related to a recording chunk. #3675

Djoels opened this issue Feb 6, 2025 · 3 comments
Labels
question General question regarding SI

Comments

@Djoels
Copy link

Djoels commented Feb 6, 2025

Just a question: how can one easily create selection of a time fragment along a recording.
For the recording you can make a call to select_channels and time_slice, to get a chunk of the recording.
However when trying to extract the affiliated spike times to this time_slice, I find I'm having to play with the sampling frequency (given that I don't have a time vector).

Am I missing some elegant way of doing this?

@zm711
Copy link
Collaborator

zm711 commented Feb 6, 2025

I always just do this myself by converting to samples from time (as you said using the sampling_frequency), but maybe @alejoe91 or @samuelgarcia know of a machinery in spikeinterface to easily do this (in which case I might switch myself :) )

@zm711 zm711 added the question General question regarding SI label Feb 6, 2025
@chrishalcrow
Copy link
Collaborator

Hello! There's a few ways to look at spike trains: to_spike_vector, get_unit_spike_train and I recently found spike_vector_to_spike_train(!). Of these, the get_unit_spike_train method has a return_times parameter. So if you have a sorting object called sort you can do something like

unit_id = 5
unit_spike_train = sort.get_unit_spike_train(unit_id = unit_id, return_times=True)

t_start = 1
t_end = 4
interval_train = unit_spike_train[(1 < unit_spike_train) & (unit_spike_train < 4)]

But if you're working with the to_spike_vector output, you'll need to deal with the sampling_frequency yourself.

@alejoe91
Copy link
Member

alejoe91 commented Feb 7, 2025

Another option is to use the sorting.frame_slice() to get a new sorting object. I think we could add a time_slice, which automatically does the conversion/checks the registered recording for timestamps.

@chrishalcrow can you give it a try?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question General question regarding SI
Projects
None yet
Development

No branches or pull requests

4 participants