Skip to content

Commit 3d49896

Browse files
committed
spikegadget wip
1 parent c481de6 commit 3d49896

File tree

1 file changed

+51
-18
lines changed

1 file changed

+51
-18
lines changed

neo/rawio/spikegadgetsrawio.py

Lines changed: 51 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
1212
Author: Samuel Garcia
1313
"""
14-
from .baserawio import (BaseRawIO, _signal_channel_dtype, _unit_channel_dtype,
15-
_event_channel_dtype)
14+
from .baserawio import (BaseRawIO, _signal_channel_dtype, _signal_stream_dtype,
15+
_spike_channel_dtype, _event_channel_dtype)
1616

1717
import numpy as np
1818

@@ -39,9 +39,10 @@ def _parse_header(self):
3939
if b"</Configuration>" in line:
4040
header_size = f.tell()
4141
break
42+
4243
if header_size is None:
4344
ValueError("SpikeGadgets : the xml header do not contain </Configuration>")
44-
print(header_size)
45+
4546
f.seek(0)
4647
header_txt = f.read(header_size).decode('utf8')
4748

@@ -52,21 +53,53 @@ def _parse_header(self):
5253
hconf = root.find('HardwareConfiguration')
5354
self._sampling_rate = float(hconf.attrib['samplingRate'])
5455

56+
# explore sub stream
57+
# the raw part is a complex vector of struct that depend on channel maps.
58+
# the "main_dtype" represent it
59+
main_dtype = []
60+
for device in hconf:
61+
bytes = int(device.attrib['numBytes'])
62+
name = device.attrib['name']
63+
sub_dtype = (name, 'u1', (bytes, ))
64+
main_dtype.append(sub_dtype)
65+
self._main_dtype = np.dtype(main_dtype)
66+
67+
self._raw_memmap = np.memmap(self.filename, mode='r', offset=header_size, dtype=self._main_dtype)
68+
print(self._raw_memmap[:3])
69+
70+
# wlak channels and keep only "analog" one
71+
stream_ids = []
72+
signal_streams = []
5573
signal_channels = []
56-
for chan_ind, child in enumerate(hconf.find('Device')):
57-
name = child.attrib['id']
58-
chan_id = chan_ind #TODO change this to str with new rawio refactoring
59-
dtype = 'int16' # TODO check this
60-
units = 'uV' # TODO check where is the info
61-
gain = 1. # TODO check where is the info
62-
offset = 0. # TODO check where is the info
63-
group_id = 0
64-
signal_channels.append((name, chan_id, self._sampling_rate, 'int16',
65-
units, gain, offset, group_id))
74+
for device in hconf:
75+
stream_id = device.attrib['name']
76+
for channel in device:
77+
#~ print(channel, channel.attrib)
78+
79+
if channel.attrib['dataType'] == 'analog':
80+
81+
if stream_id not in stream_ids:
82+
stream_ids.append(stream_id)
83+
stream_name = stream_id
84+
signal_streams.append((stream_name, stream_id))
85+
86+
name = channel.attrib['id']
87+
chan_id = channel.attrib['id']
88+
dtype = 'uint8' # TODO check this
89+
units = 'uV' # TODO check where is the info
90+
gain = 1. # TODO check where is the info
91+
offset = 0. # TODO check where is the info
92+
signal_channels.append((name, chan_id, self._sampling_rate, 'int16',
93+
units, gain, offset, stream_id))
94+
95+
signal_streams = np.array(signal_streams, dtype=_signal_stream_dtype)
6696
signal_channels = np.array(signal_channels, dtype=_signal_channel_dtype)
97+
print(signal_channels)
98+
print(signal_streams)
99+
100+
exit()
67101

68-
self._raw_memmap = np.memmap(self.filename, mode='r', offset=header_size, dtype='int16')
69-
self._raw_memmap = self._raw_memmap.reshape(-1, signal_channels.size)
102+
print(self._raw_memmap[:3])
70103

71104
# No events
72105
event_channels = []
@@ -94,14 +127,14 @@ def _segment_t_stop(self, block_index, seg_index):
94127
t_stop = size / self._sampling_rate
95128
return t_stop
96129

97-
def _get_signal_size(self, block_index, seg_index, channel_indexes):
130+
def _get_signal_size(self, block_index, seg_index, stream_index):
98131
size = self._raw_memmap.shape[0]
99132
return size
100133

101-
def _get_signal_t_start(self, block_index, seg_index, channel_indexes):
134+
def _get_signal_t_start(self, block_index, seg_index, stream_index):
102135
return 0.
103136

104-
def _get_analogsignal_chunk(self, block_index, seg_index, i_start, i_stop, channel_indexes):
137+
def _get_analogsignal_chunk(self, block_index, seg_index, i_start, i_stop, stream_index, channel_indexes):
105138
if channel_indexes is None:
106139
channel_indexes = slice(None)
107140
raw_signals = self._raw_memmap[slice(i_start, i_stop), :][:, channel_indexes]

0 commit comments

Comments
 (0)