Skip to content

Commit e59a6a9

Browse files
committed
Test NEV 2.2 spikes above 255 on the gin Trellis recording
1 parent 05803c4 commit e59a6a9

1 file changed

Lines changed: 13 additions & 33 deletions

File tree

‎neo/test/rawiotest/test_blackrockrawio.py‎

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
Tests of neo.rawio.examplerawio
33
"""
44

5-
import tempfile
65
import unittest
7-
from pathlib import Path
86
import warnings
97

108
from neo.rawio.blackrockrawio import BlackrockRawIO
@@ -655,38 +653,20 @@ def test_nev_segments_ignore_order_between_packet_types(self):
655653

656654
def test_nev_22_reads_spikes_on_electrodes_above_255(self):
657655
"""
658-
A FileSpec 2.2 NEV with spikes on an electrode above 255 (Ripple Trellis numbers its front-end ports
659-
1-128, 129-256, 257-384...) keeps them, as 2.3 does (NeuralEnsemble/python-neo#1918). Built from neo's
660-
2.3 test NEV: marked 2.2, with electrode 1 renumbered 300 in its NEUEVWAV header and spike packets.
656+
A FileSpec 2.2 NEV written by Ripple Trellis keeps its spikes on electrodes above 255, as 2.3
657+
does (NeuralEnsemble/python-neo#1918). Trellis numbers its front-end ports 1-128, 129-256,
658+
257-384..., and this file has one spike on each of 28 electrodes between 257 and 306.
661659
"""
662-
source_base = self.get_local_path("blackrock/FileSpec2.3001")
663-
original = BlackrockRawIO(filename=source_base, nsx_to_load=None)
664-
original.parse_header()
665-
units_on_1 = [i for i, (channel, _) in enumerate(original.internal_unit_ids) if channel == 1]
666-
self.assertTrue(units_on_1) # electrode 1 has spikes to move
667-
expected = np.concatenate([original.get_spike_timestamps(0, 0, i, None, None) for i in units_on_1])
668-
669-
data = bytearray(Path(source_base + ".nev").read_bytes())
670-
data[9] = 2 # FileSpec 2.3 -> 2.2
671-
header_size, packet_size = np.frombuffer(bytes(data[12:20]), dtype="<u4")
672-
for at in range(336, int(header_size), 32): # extended headers follow the 336-byte basic header
673-
if data[at : at + 8] == b"NEUEVWAV" and int.from_bytes(data[at + 8 : at + 10], "little") == 1:
674-
data[at + 8 : at + 10] = (300).to_bytes(2, "little")
675-
# 2.x packets: a uint32 timestamp, then the uint16 packet id
676-
for at in range(int(header_size), len(data) - int(packet_size) + 1, int(packet_size)):
677-
if int.from_bytes(data[at + 4 : at + 6], "little") == 1:
678-
data[at + 4 : at + 6] = (300).to_bytes(2, "little")
679-
680-
with tempfile.TemporaryDirectory() as folder:
681-
base = str(Path(folder) / "trellis_like")
682-
Path(base + ".nev").write_bytes(bytes(data))
683-
reader = BlackrockRawIO(filename=base, nsx_to_load=None)
684-
reader.parse_header()
685-
self.assertEqual(reader._nev_spec, "2.2")
686-
units_on_300 = [i for i, (channel, _) in enumerate(reader.internal_unit_ids) if channel == 300]
687-
self.assertTrue(units_on_300, "no spike channel on electrode 300")
688-
got = np.concatenate([reader.get_spike_timestamps(0, 0, i, None, None) for i in units_on_300])
689-
assert_equal(np.sort(got), np.sort(expected))
660+
filename = self.get_local_path("blackrock/version_2_2/spikes/electrode_ids_above_255/electrode_ids_above_255")
661+
reader = BlackrockRawIO(filename=filename)
662+
reader.parse_header()
663+
electrodes = [channel for channel, _ in reader.internal_unit_ids]
664+
self.assertEqual(len(electrodes), 28)
665+
self.assertTrue(all(257 <= electrode <= 306 for electrode in electrodes))
666+
spikes = [
667+
reader.get_spike_timestamps(0, 0, unit_index, None, None).size for unit_index in range(len(electrodes))
668+
]
669+
self.assertEqual(spikes, [1] * 28)
690670

691671

692672
if __name__ == "__main__":

0 commit comments

Comments
 (0)