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/5] 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/5] Retry Read the Docs after infrastructure timeout From 3db458f4fab6836a926edb0358c8f7300e28aec2 Mon Sep 17 00:00:00 2001 From: evadiva3 Date: Fri, 20 Nov 2026 01:50:38 -0500 Subject: [PATCH 3/5] Retry docs after external dataset service failure From 6189fc6425869144bc8be9c510b73e1cf5cb3d02 Mon Sep 17 00:00:00 2001 From: evadiva3 Date: Fri, 20 Nov 2026 01:54:20 -0500 Subject: [PATCH 4/5] Retry docs after verifying all example recordings are available From ac894f788641e4fe4807ca6e5328bb52f000d1f9 Mon Sep 17 00:00:00 2001 From: Eva B <250416784+evadiva3@users.noreply.github.com> Date: Sun, 22 Nov 2026 21:47:33 -0500 Subject: [PATCH 5/5] Test final Plexon block reads on recorded data --- neo/test/rawiotest/test_plexonrawio.py | 54 +++++++------------------- 1 file changed, 15 insertions(+), 39 deletions(-) diff --git a/neo/test/rawiotest/test_plexonrawio.py b/neo/test/rawiotest/test_plexonrawio.py index 3aea5046b..02f8e20df 100644 --- a/neo/test/rawiotest/test_plexonrawio.py +++ b/neo/test/rawiotest/test_plexonrawio.py @@ -21,6 +21,21 @@ class TestPlexonRawIO( "plexon/plx/timestamp_clock/one_megahertz_forty_bit_timestamps/sorted_spikes_and_strobed_events.plx", ] + def test_chunk_stopping_at_the_end_of_the_last_block(self): + """Keep the final block when the right border is zero.""" + reader = PlexonRawIO(filename=self.get_local_path("plexon/File_plexon_3.plx"), progress_bar=False) + reader.parse_header() + last = reader._data_blocks[5][0][-1] + samples = np.frombuffer(reader._memmap, dtype="int16", count=last["size"] // 2, offset=last["pos"]) + # Use the parsed start to test trimming independently of the block-offset fix in #1980. + start = int(last["cumsum"]) + stop = start + samples.size + for offset in (0, 10): + chunk = reader.get_analogsignal_chunk(i_start=start + offset, i_stop=stop) + np.testing.assert_array_equal(chunk[:, 0], samples[offset:]) + chunk = reader.get_analogsignal_chunk(i_start=start, i_stop=stop - 1) + np.testing.assert_array_equal(chunk[:, 0], samples[:-1]) + def test_timestamps_with_lower_word_above_two_to_the_31(self): """The lower 32 bits of the 40-bit block timestamp must be read unsigned. @@ -57,44 +72,5 @@ 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()