magland / sortingview

Web app for viewing results of ephys spike sorting
Apache License 2.0
25 stars 8 forks source link

wrapper to convert a new spikeinterface recording to the old spikeextractors RecordingExtractor #145

Closed khl02007 closed 3 years ago

khl02007 commented 3 years ago

@magland could you add to sortingview?

import spikeextractors as se
import spikeinterface as si

class SpikeInterfaceRecordingExtractor(se.RecordingExtractor):
    extractor_name = 'SpikeInterfaceRecordingExtractor'
    is_writable = False
    def __init__(self, new_recording: si.BaseRecording):
        se.RecordingExtractor.__init__(self)

        self._new_recording = new_recording

        for id in new_recording.get_channel_ids():
            pos = new_recording.get_channel_property(id, 'location')
            self.set_channel_property(id, 'location', pos)

    def get_channel_ids(self):
        return [int(id) for id in self._new_recording.channel_ids]

    def get_num_frames(self):
        return self._new_recording.get_num_frames()

    def get_sampling_frequency(self):
        return self._new_recording.get_sampling_frequency()

    def get_traces(self, channel_ids=None, start_frame=None, end_frame=None, return_scaled=True):
        X = self._new_recording.get_traces(
            segment_index=0,
            start_frame=start_frame,
            end_frame=end_frame,
            channel_ids=channel_ids,
        )
        return X.T
magland commented 3 years ago

@khl02007 I have incorporated this in but renamed asWrapperRecordingExtractor. Upgrade to sortingview >=0.6.11.

Could you please take a look at this example and let me know if it works okay: https://github.com/magland/sortingview/wiki/new-spike-interface-recording

khl02007 commented 3 years ago

Yes it works, except the input to the WrapperRecordingExtractor should be R not R_old

magland commented 3 years ago

Thanks, I fixed that. Closing.