def from_memory(recording: se.RecordingExtractor, serialize=False, serialize_dtype=None): if serialize: if serialize_dtype is None: raise Exception( 'You must specify the serialize_dtype when serializing recording extractor in from_memory()' ) with hi.TemporaryDirectory() as tmpdir: fname = tmpdir + '/' + _random_string(10) + '_recording.mda' se.BinDatRecordingExtractor.write_recording( recording=recording, save_path=fname, time_axis=0, dtype=serialize_dtype) with ka.config(use_hard_links=True): uri = ka.store_file(fname, basename='raw.mda') num_channels = recording.get_num_channels() channel_ids = [int(a) for a in recording.get_channel_ids()] xcoords = [ recording.get_channel_property(a, 'location')[0] for a in channel_ids ] ycoords = [ recording.get_channel_property(a, 'location')[1] for a in channel_ids ] recording = LabboxEphysRecordingExtractor({ 'recording_format': 'bin1', 'data': { 'raw': uri, 'raw_num_channels': num_channels, 'num_frames': int(recording.get_num_frames()), 'samplerate': float(recording.get_sampling_frequency()), 'channel_ids': channel_ids, 'channel_map': dict( zip([str(c) for c in channel_ids], [int(i) for i in range(num_channels)])), 'channel_positions': dict( zip([str(c) for c in channel_ids], [[float(xcoords[i]), float(ycoords[i])] for i in range(num_channels)])) } }) return recording obj = { 'recording_format': 'in_memory', 'data': register_in_memory_object(recording) } return LabboxEphysRecordingExtractor(obj)
def _get_geom_from_recording(recording: se.RecordingExtractor): channel_ids = recording.get_channel_ids() M = len(channel_ids) location0 = recording.get_channel_property(channel_ids[0], 'location') nd = len(location0) geom = np.zeros((M, nd)) for i in range(M): location_i = recording.get_channel_property(channel_ids[i], 'location') geom[i, :] = location_i return geom
def _get_geom_from_recording(recording: se.RecordingExtractor) -> np.ndarray: """Retrieve the electrode locations for a recording Parameters ---------- recording : se.RecordingExtractor Recording extractor (SpikeInterface) Returns ------- np.ndarray Geom array (M x D) where the dimension D is either 2 or 3 """ channel_ids = recording.get_channel_ids() M = len(channel_ids) location0 = recording.get_channel_property(channel_ids[0], 'location') nd = len(location0) geom = np.zeros((M, nd)) for ch_id, ii in enumerate(channel_ids): location_ii = recording.get_channel_property( ch_id, 'location') geom[ii, :] = list(location_ii) return geom