@@ -54,6 +54,21 @@ def __init__(self, filename='', selected_streams=None):
54
54
def _source_name (self ):
55
55
return self .filename
56
56
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
+
57
72
def _parse_header (self ):
58
73
# parse file until "</Configuration>"
59
74
header_size = None
@@ -77,7 +92,8 @@ def _parse_header(self):
77
92
sconf = root .find ('SpikeConfiguration' )
78
93
79
94
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' ])
81
97
82
98
# explore sub stream and count packet size
83
99
# first bytes is 0x55
@@ -147,11 +163,14 @@ def _parse_header(self):
147
163
signal_streams .append ((stream_name , stream_id ))
148
164
self ._mask_channels_bytes [stream_id ] = []
149
165
166
+ channel_ids = self ._produce_channel_ids (num_ephy_channels , num_chan_per_chip )
167
+
150
168
chan_ind = 0
151
169
for trode in sconf :
152
170
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
+
155
174
# TODO LATER : handle gain correctly according the file version
156
175
units = ''
157
176
gain = 1.
0 commit comments