Real-time Application (Online Use)
Once you have detected sequences, you can use RT-Sort for real-time applications. Here's how to do it:
Reset the RTSort Object
Before online use, reset the RTSort object:
rt_sort.reset()
Note: For optimal performance, call rt_sort.reset()
if more than 50ms have passed since the last rt_sort.running_sort(obs)
method call.
Continuous Sorting
During online use, continuously call the following method to sort a stream of data:
sequence_detections = rt_sort.running_sort(obs)
Parameters
obs
: NumPy array with shape (num_frames, num_electrodes). This should contain only the most recent frames of data.
Returns
A list where each element is a tuple of length 2 containing the data for a sorted spike in the obs
recording chunk:
- 0th element: ID number of the sequence that the spike was assigned to
- 1st element: Time the spike occurred (in milliseconds)
Notes
- The first 50ms of data passed as
obs
torunning_sort
is needed to initialize the RTSort object after the lastrt_sort.reset()
, so no spikes will be sorted during this time. num_frames
must be at least 1 and can be different for eachrunning_sort
call.- To minimize sorting latency,
num_frames
should ideally change and be equal to the amount of time that has passed since the lastrunning_sort
call. - To align with the RT-Sort Methods, use 100 frames for 20kHz MEAs and 150 frames for 30kHz Neuropixels.
Example with Maxwell MEA
Here's an example of how to use RT-Sort with a Maxwell MEA:
from braindance.core.maxwell_env import MaxwellEnv
env = MaxwellEnv(**params)
done = False
while not done:
obs, done = env.step()
sequence_detections = rt_sort.running_sort(obs)
# Process sequence_detections
Next Steps
If you want to customize RT-Sort further, you might be interested in training your own models.