Skip to content

Commit 6f49801

Browse files
committed
correct get_analogsignal_chunk for other formats
1 parent baf6d3f commit 6f49801

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

neo/rawio/intanrawio.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,15 +208,20 @@ def _parse_header(self):
208208

209209
self._max_sampling_rate = np.max(signal_channels["sampling_rate"])
210210

211+
# if header is attached we need to incorporate our block size to get signal length
211212
if self.file_format == 'header-attached':
212213
self._max_sigs_length = self._raw_data.size * self._block_size
214+
# for one-file-per-signal we just take the size which will give n_samples for each
215+
# signal stream and then we just take the longest one
213216
elif self.file_format == 'one-file-per-signal':
214217
self._max_sigs_length = max(
215218
[
216219
raw_data.size
217220
for raw_data in self._raw_data.values()
218221
]
219222
)
223+
# for one-file-per-channel we do the same as for one-file-per-signal, but since they
224+
# are in a list we just take the first channel in each list of channels
220225
else:
221226
self._max_sigs_length = max(
222227
[
@@ -258,8 +263,10 @@ def _get_signal_size(self, block_index, seg_index, stream_index):
258263
channel_id_0 = channel_ids[0]
259264
if self.file_format == "header-attached":
260265
size = self._raw_data[channel_id_0].size
266+
# one-file-per-signal is (n_samples, n_channels)
261267
elif self.file_format == 'one-file-per-signal':
262268
size = self._raw_data[stream_index].shape[0]
269+
# one-file-per-channel is (n_samples) so pull from list
263270
else:
264271
size = self._raw_data[stream_index][0].size
265272

@@ -296,19 +303,18 @@ def _get_analogsignal_chunk(self, block_index, seg_index, i_start, i_stop, strea
296303
else:
297304
shape = self._raw_data[stream_index][channel_indexes[0]].shape
298305

299-
300306
# some channel (temperature) have 1D field so shape 1D
301307
# because 1 sample per block
302308
if len(shape) == 2:
303-
# this is the general case with 2D
309+
# this is the general case with 2D (ie in the header-attached format)
304310
block_size = shape[1]
305311
block_start = i_start // block_size
306312
block_stop = i_stop // block_size + 1
307313

308314
sl0 = i_start % block_size
309315
sl1 = sl0 + (i_stop - i_start)
310316

311-
if self.file_format == 'header-attached' and stream_id == 'RHD2000 amplifier channel':
317+
if self.file_format != 'header-attached' and stream_id == 'RHD2000 amplifier channel':
312318
sigs_chunk = np.zeros((i_stop - i_start, len(channel_ids)), dtype="int16")
313319
else:
314320
sigs_chunk = np.zeros((i_stop - i_start, len(channel_ids)), dtype="uint16")
@@ -327,8 +333,9 @@ def _get_analogsignal_chunk(self, block_index, seg_index, i_start, i_stop, strea
327333
else:
328334
data_chan = self._raw_data[stream_index][channel_indexes[channel_index]]
329335

330-
331-
if len(shape) == 1:
336+
# if shape is 1 it is either temp a 1d or a 1d array from one-file-per-stream
337+
# or one-file-per-channel. In which case we do not want to do the block math
338+
if len(shape) == 1 or self.file_format != 'header-attached':
332339
sigs_chunk[:, channel_index] = data_chan[i_start:i_stop]
333340
else:
334341
sigs_chunk[:, channel_index] = data_chan[block_start:block_stop].flatten()[sl0:sl1]

0 commit comments

Comments
 (0)