Skip to content

Read NeuroExplorer files above 2 GB and fix spike waveform offsets - #1898

Open
h-mayorquin wants to merge 1 commit into
NeuralEnsemble:masterfrom
h-mayorquin:fix_neuroexplorer_offsets
Open

Read NeuroExplorer files above 2 GB and fix spike waveform offsets#1898
h-mayorquin wants to merge 1 commit into
NeuralEnsemble:masterfrom
h-mayorquin:fix_neuroexplorer_offsets

Conversation

@h-mayorquin

Copy link
Copy Markdown
Contributor

Rodrigo Paz from the Nelson lab can't convert their NeuroExplorer sessions as most of their files are above 2 GB.
This PR reads DataOffset as unsigned and that recovers the true offset for any file below 4 GB. Above that the low bits are really gone and the file has to be re-exported as .nex5, which uses 64 bit offsets. I also fixed the spike waveforms which were read from offset + n * 2 when the timestamps that precede them are 4 bytes each.

I tested both on a 2.5 GB recording of theirs with 196 variables, 69 of them past the boundary. Every array lands where the headers say and the first samples of AD18 read -208, -241, -282 instead of 193, 215, 224.

Two defects in neuroexplorerrawio, both returning wrong data without raising.

Waveform data starts after the variable's timestamps, which the specification
stores as 4 bytes each. _get_spike_raw_waveforms skipped only n * 2 bytes, so it
began reading halfway through the timestamp array. On the gin file
File_neuroexplorer_2.nex, sig01i_wf started [-26086, 22, -24757, 22] where the
file holds [-60, -13, 37, 138].

DataOffset is declared signed in the specification, but NeuroExplorer keeps
writing past 2 GB and stores the low 32 bits, so a variable beyond that point
reads back negative and the reader indexes its memmap from the wrong end of the
file. Reading the field unsigned recovers the true offset exactly for any file
below 4 GB; above that the information is genuinely lost and the file has to be
re-exported as .nex5, which uses 64-bit offsets. Verified on a 2.5 GB recording
with 196 variables, 69 of them past the boundary: every array then lands where
the headers say, and the first samples of a continuous variable read -208, -241,
-282 instead of 193, 215, 224.

The counts come out of the header as numpy int32, so mixing them with a python
int in the offset arithmetic raises OverflowError under numpy 2. Every value
entering that arithmetic is now a python int.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant