Add optional mtscomp support to Open Ephys binary reader - #1887
Add optional mtscomp support to Open Ephys binary reader#1887arturoptophys wants to merge 4 commits into
Conversation
|
So you guys compress the Open Ephys .dat files with Normally, we'd like to keep NEO as a library to read "default" file formats. This is especially true in this case, as we need core changes to the buffer logic. A potential alternative would be to add a separate reader either here or in SpikeInterface (if you guys use it). This is what we have done for IBL What do you think? |
|
@alejoe91 Well, we have not been using in on a large scale yet, but it is a consideration given that it helps a bit with the disc space. And yes, our pipeline is based on SpikeInterface. It just seemed an easier task to modify the reader at the very base instead of a bit more complex implementation within SI. But I will take a look if it would be possible to create a custom reader which combines openephys meta-data extraction with the cbin - raw data extraction. |
If you are just starting with this, I strongly recommend using SpikeInterface compression directly! It uses zarr and it's natively chunked and cloud compatible :) |
|
@alejoe91 Thx i will look into it, is there a reverse operation for SI-compression (to restore original files) ? otherwise it becomes a bit of a forever buy-in in SI :) |
Everything is saved to zarr, so it can be read directly through their API. I argue that this is less of a buy-in than |
|
I agree with @alejoe91 here. |
Summary
This PR adds optional, transparent support for losslessly compressed Open Ephys
continuous signals stored as:
OpenEphysBinaryRawIOcontinues to support the existingcontinuous.datlayout. When both representations are present, the raw
.datfile takesprecedence.
Why
mtscomp provides a lossless compression for ephys data streams. In its current implementation,
its mostly designed to work with SpikeGLX files and when using SpikeInterface read_cbin_ibl is implemented there.
However, mtscomp can also compress the .dat files from open ephys providing a 50-60 % reduction of file size. A possible usage scenario is compressing the file in-place so replacing the continuous.dat with continuous.cbin and continuous.ch.
Before this change,
OpenEphysBinaryRawIOalways expectedcontinuous.dat. Reading a compressed recording therefore required an out-of-band full decompression step, duplicated the signal data on disk, and prevented consumers from treating compressed and uncompressed recordings through the same Neo interface.This implementation keeps mtscomp optional and decompresses only the requested chunks in memory. It does not create a temporary decompressed
.datfile. All the meta data from openephys are still read via the normal path.What was implemented
Generic mtscomp buffer backend
mtscompbuffer type toBaseRawWithBufferApiIO.mtscomp.Readerper(block_index, seg_index, buffer_id).Open Ephys ADC and SYNC separation remains outside the generic backend.
optional dependency.
Open Ephys storage detection
continuous.dator acontinuous.cbin/continuous.chpair withoutwildcard matching.
.datprecedence when both formats exist..chfile or missing signal data.cbinandchto the recognized extensions.uses_mtscompproperty for downstream integrations.Metadata validation
The
.chJSON metadata is read during header parsing without importingmtscomp. The reader validates:
n_channels,sample_rate,dtype, andchunk_boundsfields;For each compressed stream, these values are cross-checked against
structure.oebin. The final chunk bound is used as the compressed buffer'ssample count.
Backward compatibility
.datpath still uses the existingraw_filenamefield,memmap shape calculation, and raw buffer-description keys.
raw_filenameremains present in the dictionaries returned byexplore_folder()for raw recordings.raw_filenamepointing to a
.cbinfile.continuous.datexists.
metadata paths.
continues through the shared code paths.
Optional dependencies
neo[mtscomp]optional extra.mtscomp>=1.0.2after a compatibility smoke test.tqdmin the extra because mtscomp 1.0.2 imports it at runtime butdoes not declare package dependencies.
testandallextras; it remains outside Neo'smandatory dependencies.
Tests added
The Open Ephys RawIO tests now build small synthetic recordings, copy them, and
compress the copies without modifying shared fixtures. Coverage includes:
.dat-only,.datplus compressed files,.cbin/.ch, missing.ch,orphaned
.ch, and missing-data storage selection;boundaries;
isolation;
mtscomp;
raw_filename;.datfile.Validation
BaseRawWithBufferApiIOreader tests available locally: 1 passed, 33 skippedRawBinarySignalRawIOread/cleanup smoke test: passedgit diff --check: passedThe skipped tests require Datalad-backed external fixtures, which were not available in the local environment.
The mtscomp compatibility spike used mtscomp 1.0.2 with Python 3.12.9 and
NumPy 2.4.4 and verified
Reader.open(), shape, dtype, arbitrary frame andchannel slicing, and slices crossing compression chunk boundaries. The full
Python 3.10-3.13 matrix is left to CI.