From b03f07cf42aae3142e27ed9ff1bf27bed163850b Mon Sep 17 00:00:00 2001 From: Eva B <250416784+evadiva3@users.noreply.github.com> Date: Mon, 16 Nov 2026 18:18:59 -0800 Subject: [PATCH 1/2] Keep the last Plexon signal block when a read reaches its end --- doc/source/authors.rst | 1 + neo/rawio/plexonrawio.py | 4 ++- neo/test/rawiotest/test_plexonrawio.py | 39 ++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/doc/source/authors.rst b/doc/source/authors.rst index 357faaf52..f6ec68038 100644 --- a/doc/source/authors.rst +++ b/doc/source/authors.rst @@ -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 diff --git a/neo/rawio/plexonrawio.py b/neo/rawio/plexonrawio.py index 0f713fcb0..3bef3f26a 100644 --- a/neo/rawio/plexonrawio.py +++ b/neo/rawio/plexonrawio.py @@ -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"] diff --git a/neo/test/rawiotest/test_plexonrawio.py b/neo/test/rawiotest/test_plexonrawio.py index f1dac1cff..3aea5046b 100644 --- a/neo/test/rawiotest/test_plexonrawio.py +++ b/neo/test/rawiotest/test_plexonrawio.py @@ -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() From 628249cc97ded0116040c6e783baec85188e8691 Mon Sep 17 00:00:00 2001 From: evadiva3 Date: Wed, 18 Nov 2026 20:02:27 -0500 Subject: [PATCH 2/2] Retry Read the Docs after infrastructure timeout