Skip to content

Commit

Permalink
Fix ephys channel ids in spikegadgetsrawio
Browse files Browse the repository at this point in the history
  • Loading branch information
rly authored Jul 6, 2023
1 parent 6ce00dc commit 3a9caae
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions neo/rawio/spikegadgetsrawio.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,21 @@ def __init__(self, filename='', selected_streams=None):
def _source_name(self):
return self.filename

def _produce_ephys_channel_ids(self, n_total_channels, n_channels_per_chip):
"""Compute the channel ID labels
The ephys channels in the .rec file are stored in the following order:
hwChan ID of channel 0 of first chip, hwChan ID of channel 0 of second chip, ..., hwChan ID of channel 0 of Nth chip,
hwChan ID of channel 1 of first chip, hwChan ID of channel 1 of second chip, ..., hwChan ID of channel 1 of Nth chip,
...
So if there are 32 channels per chip and 128 channels (4 chips), then the channel IDs are:
0, 32, 64, 96, 1, 33, 65, 97, ..., 128
See also: https://github.com/NeuralEnsemble/python-neo/issues/1215
"""
x = []
for k in range(n_channels_per_chip):
x.append([k+i*n_channels_per_chip for i in range(int(n_total_channels/n_channels_per_chip))])
return [item for sublist in x for item in sublist]

def _parse_header(self):
# parse file until "</Configuration>"
header_size = None
Expand All @@ -77,7 +92,8 @@ def _parse_header(self):
sconf = root.find('SpikeConfiguration')

self._sampling_rate = float(hconf.attrib['samplingRate'])
num_ephy_channels = int(hconf .attrib['numChannels'])
num_ephy_channels = int(hconf.attrib['numChannels'])
num_chan_per_chip = int(sconf.attrib['chanPerChip'])

# explore sub stream and count packet size
# first bytes is 0x55
Expand Down Expand Up @@ -147,11 +163,14 @@ def _parse_header(self):
signal_streams.append((stream_name, stream_id))
self._mask_channels_bytes[stream_id] = []

channel_ids = self._produce_channel_ids(num_ephy_channels, num_chan_per_chip)

chan_ind = 0
for trode in sconf:
for schan in trode:
name = 'trode' + trode.attrib['id'] + 'chan' + schan.attrib['hwChan']
chan_id = schan.attrib['hwChan']
chan_id = str(channel_ids[chan_ind])
name = 'chan' + chan_id

# TODO LATER : handle gain correctly according the file version
units = ''
gain = 1.
Expand Down

0 comments on commit 3a9caae

Please sign in to comment.