Skip to content

[NeuralynxIO] Update .ncs file reading #819

@TRuikes

Description

@TRuikes

Hi! While working with NeuralynxIO in different datasets I came across a few bug/missing features, which I think will be useful (necessary) additions:

  • Input is automatically inverted, I was not aware this was happening, but is important to know.
  • Using regexp breaks, in two cases: 1) somehow the header string type does not match the application version (happens if I save old NL data using a new version of Neuraview) 2) if we have this in the header: ## Time Closed File was not closed properly; we don't know how it got there, but the data itself seems intact
  • NCS files within one session can have different data lengths, causing this to break. When DspFilterDelay_µs > 0 and DspDelayCompensation == Enabled, there seems to be padding of the data by Cheetah (im not 100% confident about how). For a tetrode, someone would have 3 channels saved with DspFilterDelay==0, but one is being bandpassed (DspFilterDelay >0), yielding patches before and after the signal if the Dsp Delay compensation is on.
  • If DspDelayCompensation == Disabled and DspFilterDelay > 0, this is not dealt with, and one would have channels with improper alignment
  • Ring buffer gaps are detected as gaps, and translated as different segments. In short, if the buffer during recording overflows, Cheetah will drop the data, making the recorded values discontinuous. Still Cheetah will save the timestamps for the signal, so it is solvable. In fact you are allready reading those gaps with this line, but treat them as segments, instead of faulty data. Fieldtrip has a nice implementation to deal with this; ft_read_neuralynx_interp, wherein they fill the gaps with NaN's. This ensures for instance that when generating .dat files the data is properly aligned.

The header thing will be solved easily, but the delay and buffer errors are a bit more though, I you would have to restructure how .ncs files are read. Currently the first file in read, used to determine gaps/data size shape, and it is ignorant to any Dsp delays.

Maybe this workflow would solve it:

  • Scan all .ncs files; per file get:
    • t_start & t_stop
    • find presence of ring buffer errors/gaps
    • Dsp delay & compensation
  • Define segments, a common t_start and t_stop
  • For each .ncs file, patch missing data (or alternatively have the 'broken' channels dropped)

I can this a try for a pull request if you want, the only thing I'm not sure about how to solve is how to patch the data, as there's np.memmap being used.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions