Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/authors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ and may not be the current affiliation of a contributor.
* Axel Coiffard-Donaty
* Anthony Mercer
* Aaron Kanzer [53]
* Eva B (evadiva3 on GitHub)

1. Centre de Recherche en Neuroscience de Lyon, CNRS UMR5292 - INSERM U1028 - Université Claude Bernard Lyon 1
2. Unité de Neuroscience, Information et Complexité, CNRS UPR 3293, Gif-sur-Yvette, France
Expand Down
4 changes: 3 additions & 1 deletion neo/rawio/plexonrawio.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,9 @@ def _get_analogsignal_chunk(self, block_index, seg_index, i_start, i_stop, strea
# right border
# be careful that bl could be both bl0 and bl1!!
border = data.size - (i_stop - data_blocks[bl]["cumsum"])
data = data[:-border]
# Avoid an empty slice when the chunk ends at the block boundary.
if border > 0:
data = data[:-border]
if bl == bl0:
# left border
border = i_start - data_blocks[bl]["cumsum"]
Expand Down
39 changes: 39 additions & 0 deletions neo/test/rawiotest/test_plexonrawio.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,44 @@ def test_timestamps_with_lower_word_above_two_to_the_31(self):
np.testing.assert_array_equal(around_second_wrap, [8_589_765_078, 8_589_773_845, 8_590_497_111, 8_590_594_911])


class TestPlexonAnalogSignalChunk(unittest.TestCase):
"""Test the reading of signal chunks on synthetic data blocks (no file needed)."""

def setUp(self):
# one channel made of three data blocks of four int16 samples each
self.samples = np.arange(1, 13, dtype="int16")
data_blocks = np.zeros(3, dtype=[("pos", "int64"), ("size", "int64"), ("cumsum", "int64")])
data_blocks["pos"] = [0, 8, 16]
data_blocks["size"] = 8
data_blocks["cumsum"] = [0, 4, 8]

class FakePlexonRawIO:
_get_analogsignal_chunk = PlexonRawIO._get_analogsignal_chunk

self.reader = FakePlexonRawIO()
self.reader.header = {
"signal_channels": np.array(
[("ch", "7", "s0")], dtype=[("name", "U8"), ("id", "U8"), ("stream_id", "U8")]
),
"signal_streams": np.array([("s", "s0")], dtype=[("name", "U8"), ("id", "U8")]),
}
self.reader._stream_id_samples = {"s0": self.samples.size}
self.reader._data_blocks = {5: {np.int32(7): data_blocks}}
self.reader._memmap = self.samples.view("uint8")

def _read(self, i_start, i_stop):
return self.reader._get_analogsignal_chunk(0, 0, i_start, i_stop, 0, None)[:, 0]

def test_chunk_stopping_at_the_end_of_the_signal(self):
"""The last data block must not be dropped when the chunk stops at its end."""
np.testing.assert_array_equal(self._read(None, None), self.samples)
np.testing.assert_array_equal(self._read(2, 12), self.samples[2:12])
np.testing.assert_array_equal(self._read(9, 12), self.samples[9:12])

def test_chunk_stopping_inside_or_between_blocks(self):
for i_start, i_stop in [(0, 11), (0, 8), (3, 6), (4, 8), (5, 9)]:
np.testing.assert_array_equal(self._read(i_start, i_stop), self.samples[i_start:i_stop])


if __name__ == "__main__":
unittest.main()