Skip to content

Commit deda58c

Browse files
authored
Merge pull request #1926 from cboulay/nev-22-spikes-above-255
Blackrock: read NEV 2.2 spikes on electrodes above 255
2 parents 540abbe + e59a6a9 commit deda58c

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

‎neo/rawio/blackrockrawio.py‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2744,14 +2744,25 @@ def _is_set(self, flag, pos):
27442744
# Used to create masks that filter raw data packets by their packet ID field.
27452745
# Single values indicate equality check, tuples (min, max) indicate range check.
27462746
# According to NEV spec: packet IDs < 32768 identify channels, IDs >= 32768 are system events.
2747+
# Packets whose ID is not listed for a spec are not read. Known cases, ignored on purpose:
2748+
# - 0x8000 + channel (e.g. 32769): preview packets of the live protocol (cbproto's "Preview Data Packet
2749+
# Definitions"), found in 3.0 files written by Central. They carry no neural data.
2750+
# - 0xFFF9: recording events of 3.0 files written by Central (header type 0 start, 1 stop, 2 pause,
2751+
# 3 resume; Central's CNevFile30::AddRecordingEvent). Not used to split segments, which come from
2752+
# resets and gaps.
27472753
NEV_PACKET_IDENTIFIERS_BY_SPEC = {
27482754
"2.1": {
27492755
"NonNeural": 0,
27502756
"Spikes": (1, 255), # Packet IDs in this range identify spike events on electrodes
27512757
},
27522758
"2.2": {
27532759
"NonNeural": 0,
2754-
"Spikes": (1, 255), # Packet IDs in this range identify spike events on electrodes
2760+
# Packet IDs in this range identify spike events on electrodes. Wider than 2.1's range:
2761+
# Ripple Trellis writes 2.2 files with electrode IDs above 255 (its front-end ports are
2762+
# numbered 1-128, 129-256, 257-384...), and every spike on them was dropped without a
2763+
# warning (NeuralEnsemble/python-neo#1918). The bound is 5120 because Trellis writes
2764+
# stimulation packets on 5120 plus the electrode ID.
2765+
"Spikes": (1, 5120),
27552766
},
27562767
"2.3": {
27572768
"NonNeural": 0,

‎neo/test/rawiotest/test_blackrockrawio.py‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,23 @@ def test_nev_segments_ignore_order_between_packet_types(self):
651651
)
652652
self.assertEqual(returned, 960)
653653

654+
def test_nev_22_reads_spikes_on_electrodes_above_255(self):
655+
"""
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.
659+
"""
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)
670+
654671

655672
if __name__ == "__main__":
656673
unittest.main()

0 commit comments

Comments
 (0)