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..6e054ca2c 100644 --- a/neo/rawio/plexonrawio.py +++ b/neo/rawio/plexonrawio.py @@ -236,7 +236,8 @@ def _parse_header(self): if index == 0: data_block["cumsum"][index] = 0 else: - data_block["cumsum"][index] = data_block["cumsum"][index - 1] + sample_count + previous_sample_count = data_block["size"][index - 1] // 2 + data_block["cumsum"][index] = data_block["cumsum"][index - 1] + previous_sample_count self._data_blocks[bl_type][chan_id] = data_block diff --git a/neo/test/rawiotest/test_plexonrawio.py b/neo/test/rawiotest/test_plexonrawio.py index f1dac1cff..744255544 100644 --- a/neo/test/rawiotest/test_plexonrawio.py +++ b/neo/test/rawiotest/test_plexonrawio.py @@ -1,8 +1,10 @@ import unittest +from pathlib import Path +from tempfile import TemporaryDirectory import numpy as np -from neo.rawio.plexonrawio import PlexonRawIO +from neo.rawio.plexonrawio import DataBlockHeader, GlobalHeader, PlexonRawIO, SlowChannelHeader from neo.test.rawiotest.common_rawio_test import BaseTestRawIO @@ -57,5 +59,53 @@ 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 TestPlexonBlockOffsets(unittest.TestCase): + """Check parsed offsets and reads without downloading recordings.""" + + def test_unequal_signal_block_sizes(self): + """Parsed block starts must use the number of samples in preceding blocks.""" + samples = np.arange(350, dtype="int16") + header = np.zeros(1, dtype=GlobalHeader) + for field, value in { + "MagicNumber": 0x58454C50, + "Version": 106, + "ADFrequency": 1000, + "NumSlowChannels": 1, + "Year": 2020, + "Month": 1, + "Day": 1, + "BitsPerSpikeSample": 16, + "SlowMaxMagnitudeMV": 5000, + }.items(): + header[field] = value + channel = np.zeros(1, dtype=SlowChannelHeader) + channel["Name"] = b"AI1" + for field in ["Gain", "PreampGain", "Enabled"]: + channel[field] = 1 + channel["ADFreq"] = 1000 + + with TemporaryDirectory() as directory: + filename = Path(directory) / "unequal_blocks.plx" + with filename.open("wb") as stream: + header.tofile(stream) + channel.tofile(stream) + for start, stop in [(0, 100), (100, 300), (300, 350)]: + block = np.zeros(1, dtype=DataBlockHeader) + block["Type"] = 5 + block["TimeStamp"] = start + block["NumberOfWaveforms"] = 1 + block["NumberOfWordsInWaveform"] = stop - start + block.tofile(stream) + samples[start:stop].tofile(stream) + reader = PlexonRawIO(filename=str(filename), progress_bar=False) + try: + reader.parse_header() + np.testing.assert_array_equal(reader._data_blocks[5][0]["cumsum"], [0, 100, 300]) + chunk = reader.get_analogsignal_chunk(i_start=80, i_stop=280) + np.testing.assert_array_equal(chunk[:, 0], samples[80:280]) + finally: + del reader + + if __name__ == "__main__": unittest.main()