Skip to content

Commit cbbda7a

Browse files
JamesBelangerclaude
andcommitted
Test the NSx 2.1 sample count on the gin stub with fixed values
The stub is the first 0.3 s of l101210-001, so the ns2 and ns5 must hold 300 and 9000 samples. These numbers come from the cut, not from the reader's own formula. Master reads 299 and 8999. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent b881bb0 commit cbbda7a

1 file changed

Lines changed: 15 additions & 19 deletions

File tree

‎neo/test/rawiotest/test_blackrockrawio.py‎

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

5-
import os
65
import unittest
76
import warnings
87

@@ -153,7 +152,7 @@ def test_compare_blackrockio_with_matlabloader_v21(self):
153152
raw_sigs = reader.get_analogsignal_chunk(channel_indexes=[c])
154153
raw_sigs = raw_sigs.flatten()
155154
# The Matlab export stops one sample before the end of the file
156-
# (see test_nsx21_signal_size_matches_file_size)
155+
# (see test_nsx21_reads_the_last_sample)
157156
self.assertEqual(raw_sigs.size, lfp_ml.shape[1] + 1)
158157
assert_equal(raw_sigs[: lfp_ml.shape[1]], lfp_ml[c, :])
159158

@@ -191,23 +190,20 @@ def test_compare_blackrockio_with_matlabloader_v21(self):
191190
matlab_digievents = mts_ml[mid_ml == int(label)]
192191
assert_equal(python_digievents, matlab_digievents)
193192

194-
def test_nsx21_signal_size_matches_file_size(self):
195-
"""
196-
NSx 2.1 headers do not store the number of samples, so it has to come from the file size:
197-
a 32-byte basic header and 4 bytes per channel, then int16 samples for every channel.
198-
"""
199-
dirname = self.get_local_path("blackrock/blackrock_2_1/l101210-001")
200-
for nsx_nb in (2, 5):
201-
reader = BlackrockRawIO(dirname, nsx_to_load=nsx_nb)
202-
reader.parse_header()
203-
num_channels = reader.signal_channels_count(stream_index=0)
204-
data_bytes = os.path.getsize(f"{dirname}.ns{nsx_nb}") - (32 + 4 * num_channels)
205-
self.assertEqual(data_bytes % (2 * num_channels), 0)
206-
expected_num_samples = data_bytes // (2 * num_channels)
207-
self.assertEqual(reader.get_signal_size(block_index=0, seg_index=0, stream_index=0), expected_num_samples)
208-
# the last sample is readable
209-
last = reader.get_analogsignal_chunk(i_start=expected_num_samples - 1, i_stop=expected_num_samples)
210-
self.assertEqual(last.shape, (1, num_channels))
193+
def test_nsx21_reads_the_last_sample(self):
194+
filename = self.get_local_path("blackrock/version_2_1/spikes/offline_sorted_units/online_sorted_units")
195+
196+
reader = BlackrockRawIO(filename=filename, nsx_to_load=2)
197+
reader.parse_header()
198+
number_of_samples = reader.get_signal_size(block_index=0, seg_index=0, stream_index=0)
199+
expected_number_of_samples = 300 # 0.3 s at 1 kHz
200+
self.assertEqual(number_of_samples, expected_number_of_samples)
201+
202+
reader = BlackrockRawIO(filename=filename, nsx_to_load=5)
203+
reader.parse_header()
204+
number_of_samples = reader.get_signal_size(block_index=0, seg_index=0, stream_index=0)
205+
expected_number_of_samples = 9000 # 0.3 s at 30 kHz
206+
self.assertEqual(number_of_samples, expected_number_of_samples)
211207

212208
def test_blackrockrawio_ptp_timestamps(self):
213209
dirname = self.get_local_path("blackrock/blackrock_3_0_ptp/20231027-125608-001")

0 commit comments

Comments
 (0)