Skip to content

Commit a7213be

Browse files
committed
wip
1 parent 12b3f1b commit a7213be

File tree

1 file changed

+47
-18
lines changed

1 file changed

+47
-18
lines changed

neo/rawio/spikegadgetsrawio.py

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def _parse_header(self):
5959
sconf = root.find('SpikeConfiguration')
6060

6161
self._sampling_rate = float(hconf.attrib['samplingRate'])
62+
num_ephy_channels = int(hconf .attrib['numChannels'])
6263

6364
# explore sub stream and count packet size
6465
# first bytes is 0x55
@@ -71,20 +72,43 @@ def _parse_header(self):
7172
num_bytes = int(device.attrib['numBytes'])
7273
stream_bytes[stream_id] = packet_size
7374
packet_size += num_bytes
74-
print('packet_size', packet_size)
75+
#~ print('packet_size', packet_size)
7576
#~ print(stream_bytes)
7677
#~ exit()
7778

7879
# timesteamps 4 uint32
7980
self._timestamp_byte = packet_size
8081
packet_size += 4
8182

82-
num_ephy_channels = len(sconf)
8383
packet_size += 2 * num_ephy_channels
8484

85+
print('packet_size', packet_size)
86+
87+
#~ num_ephy_channels = num_ephy_channels * 4
88+
#~ num_ephy_channels = 0
89+
#~ chan_ids = []
90+
#~ for chan_ind, trode in enumerate(sconf):
91+
#~ for spikechan in trode:
92+
#~ print(spikechan, spikechan.attrib)
93+
#~ num_ephy_channels += 1
94+
#~ chan_ids.append(int(spikechan.attrib['hwChan']))
95+
#~ print('num_ephy_channels', num_ephy_channels)
96+
#~ print(np.sort(chan_ids))
97+
98+
99+
100+
101+
85102
raw_memmap = np.memmap(self.filename, mode='r', offset=header_size, dtype='<u1')
86103

104+
inds, = np.nonzero(raw_memmap == 0x55)
105+
#~ print(inds)
106+
#~ print(np.diff(inds))
107+
#~ exit()
108+
109+
87110
num_packet = raw_memmap.size // packet_size
111+
#~ print(num_packet, num_packet*packet_size, raw_memmap.size)
88112
raw_memmap = raw_memmap[:num_packet*packet_size]
89113
self._raw_memmap = raw_memmap.reshape(-1, packet_size)
90114

@@ -134,24 +158,28 @@ def _parse_header(self):
134158
stream_name = stream_id
135159
signal_streams.append((stream_name, stream_id))
136160
self._mask_channels_bytes[stream_id] = []
137-
for chan_ind, trode in enumerate(sconf):
138-
name = trode.attrib['id']
139-
chan_id = trode.attrib['id']
140-
units = 'uV' # TODO check where is the info
141-
gain = 1. # TODO check where is the info
142-
offset = 0. # TODO check where is the info
143-
signal_channels.append((name, chan_id, self._sampling_rate, 'int16',
144-
units, gain, offset, stream_id))
145-
146-
chan_mask = np.zeros(packet_size, dtype='bool')
147-
148-
num_bytes = packet_size - 2 * num_ephy_channels + 2 * chan_ind
149-
chan_mask[num_bytes] = True
150-
chan_mask[num_bytes+1] = True
151-
self._mask_channels_bytes[stream_id].append(chan_mask)
161+
162+
chan_ind = 0
163+
for trode in sconf:
164+
for schan in trode:
165+
name = 'trode' + trode.attrib['id'] + 'chan' + schan.attrib['hwChan']
166+
chan_id = schan.attrib['hwChan']
167+
units = 'uV' # TODO check where is the info
168+
gain = 1. # TODO check where is the info
169+
offset = 0. # TODO check where is the info
170+
signal_channels.append((name, chan_id, self._sampling_rate, 'int16',
171+
units, gain, offset, stream_id))
172+
173+
chan_mask = np.zeros(packet_size, dtype='bool')
174+
175+
num_bytes = packet_size - 2 * num_ephy_channels + 2 * chan_ind
176+
chan_mask[num_bytes] = True
177+
chan_mask[num_bytes+1] = True
178+
self._mask_channels_bytes[stream_id].append(chan_mask)
179+
180+
chan_ind += 1
152181

153182
# make mask as array
154-
self._mask_channels_bytes[stream_id]
155183
self._mask_streams = {}
156184
for stream_id, l in self._mask_channels_bytes.items():
157185
mask = np.array(l)
@@ -239,3 +267,4 @@ def _get_analogsignal_chunk(self, block_index, seg_index, i_start, i_stop, strea
239267

240268
return raw_unit16
241269

270+

0 commit comments

Comments
 (0)