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
3 changes: 2 additions & 1 deletion neo/rawio/plexonrawio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
52 changes: 51 additions & 1 deletion neo/test/rawiotest/test_plexonrawio.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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()
Loading