@@ -54,6 +54,21 @@ def __init__(self, filename='', selected_streams=None):
5454 def _source_name (self ):
5555 return self .filename
5656
57+ def _produce_ephys_channel_ids (self , n_total_channels , n_channels_per_chip ):
58+ """Compute the channel ID labels
59+ The ephys channels in the .rec file are stored in the following order:
60+ hwChan ID of channel 0 of first chip, hwChan ID of channel 0 of second chip, ..., hwChan ID of channel 0 of Nth chip,
61+ hwChan ID of channel 1 of first chip, hwChan ID of channel 1 of second chip, ..., hwChan ID of channel 1 of Nth chip,
62+ ...
63+ So if there are 32 channels per chip and 128 channels (4 chips), then the channel IDs are:
64+ 0, 32, 64, 96, 1, 33, 65, 97, ..., 128
65+ See also: https://github.com/NeuralEnsemble/python-neo/issues/1215
66+ """
67+ x = []
68+ for k in range (n_channels_per_chip ):
69+ x .append ([k + i * n_channels_per_chip for i in range (int (n_total_channels / n_channels_per_chip ))])
70+ return [item for sublist in x for item in sublist ]
71+
5772 def _parse_header (self ):
5873 # parse file until "</Configuration>"
5974 header_size = None
@@ -77,7 +92,8 @@ def _parse_header(self):
7792 sconf = root .find ('SpikeConfiguration' )
7893
7994 self ._sampling_rate = float (hconf .attrib ['samplingRate' ])
80- num_ephy_channels = int (hconf .attrib ['numChannels' ])
95+ num_ephy_channels = int (hconf .attrib ['numChannels' ])
96+ num_chan_per_chip = int (sconf .attrib ['chanPerChip' ])
8197
8298 # explore sub stream and count packet size
8399 # first bytes is 0x55
@@ -147,11 +163,14 @@ def _parse_header(self):
147163 signal_streams .append ((stream_name , stream_id ))
148164 self ._mask_channels_bytes [stream_id ] = []
149165
166+ channel_ids = self ._produce_channel_ids (num_ephy_channels , num_chan_per_chip )
167+
150168 chan_ind = 0
151169 for trode in sconf :
152170 for schan in trode :
153- name = 'trode' + trode .attrib ['id' ] + 'chan' + schan .attrib ['hwChan' ]
154- chan_id = schan .attrib ['hwChan' ]
171+ chan_id = str (channel_ids [chan_ind ])
172+ name = 'chan' + chan_id
173+
155174 # TODO LATER : handle gain correctly according the file version
156175 units = ''
157176 gain = 1.
0 commit comments