npcomp — lossless compression and backup for SpikeGLX Neuropixels data
npcomp is a minimal CLI wrapper around mtscomp, the IBL lossless compressor for raw Neuropixels data (about 3x compression):
- compress: losslessly compress SpikeGLX
.binfiles into.cbin + .ch(mtscomp's built-in byte-per-byte verification runs automatically); - restore: decompress
.cbin + .chback to.bin(also automatically verified); - status: report compression state, space already saved, estimated savings and time;
- backup mode (
--dest): mirror a whole folder into a destination;.binfiles are compressed, everything else is copied and verified.
Chinese version: README_ZH.md.
Installation
From PyPI:
pip install npcomp
From source (current development workflow):
conda create -n mtscomp python=3.10 -y
conda activate mtscomp
cd <path-to-repo>
pip install -e .
Add the Scripts folder of the conda environment (e.g. <conda-env>\Scripts, where npcomp.exe lives) to your user PATH, then open a new terminal and run npcomp directly.
Quick start
# Report compression status
npcomp status <path-to-session>
# Compress in place (.bin -> .cbin + .ch, originals kept)
npcomp compress <path-to-session>
# Mirror backup to a destination: .bin compressed, everything else copied & verified
npcomp compress <path-to-session> --dest <backup-dir>
# Same backup, but run .bin compression through a fast scratch disk (e.g. NVMe)
npcomp compress <path-to-session> --dest <backup-dir> --scratch <fast-disk-dir>
# Delete source .bin only after a successful, verified compression (this run only)
npcomp compress <path-to-session> --dest <backup-dir> --delete
# Restore (in place by default; --dest redirects the output)
npcomp restore <backup-dir>
npcomp restore <backup-dir> --dest <restore-dir>
Command reference
npcomp compress <folder> [--dest DIR] [--scratch DIR] [--dry-run] [--delete] [--cpus N] [--chunk SEC] [--force] [--yes] [--quiet]
- Recursively scans
<folder>and only processes.binfiles that have a valid SpikeGLX.metasibling (containingnSavedChansplusimSampRate/niSampRate); covers ap/lf/nidq and leaves every other.binuntouched. - Parameters are read from the
.meta: channel count fromnSavedChans; sample rate fromimSampRate(ap),imSampRate/12(lf), orniSampRate(nidq); data type is fixed toint16. - Defaults: 1-second chunks, all CPU cores, verification always on.
- Without
--dest: writesX.cbin + X.chnext to the source; existing pairs are skipped,--forcerecompresses. - With
--dest: mirror-backup mode —.binfiles are compressed into the destination, every other file (.meta, logs, video sidecars, ...) is copied and byte-verified. Existing destination files with identical content are skipped; same-name/different-content files trigger an overwrite prompt (--yesanswers yes everywhere,--forceredoes everything). - With
--scratch(requires--dest): raw.binfiles are first copied to a fast scratch directory (e.g. an NVMe SSD), compressed there, and the verified.cbin/.chare copied back to the destination. This can be much faster when the destination is a slow disk. Scratch files are removed after each file; the scratch directory must be empty before a run (npcomp refuses otherwise) and should stay dedicated to npcomp. --delete: delete the source.binonly for files successfully compressed and verified in this run.--dry-run: print the plan (compress/copy/delete) without touching anything.- If the destination already contains data (e.g. a previous run interrupted by power loss), you are prompted first; non-interactive runs require
--yes.
npcomp restore <folder> [--dest DIR] [--overwrite] [--delete] [--dry-run] [--quiet]
- Recursively finds every
X.cbin + X.chpair and decompresses it toX.bin(mtscomp verifies each decompression byte-for-byte). - Restores in place by default; existing
.binfiles are skipped unless--overwriteis given. - The compressed
X.cbin + X.chpair is kept by default; only an explicit--deleteremoves it after a successful restore (and only pairs successfully restored in this run; skipped pairs are kept). - A missing
.metaonly produces a warning — it is not needed for byte-level decompression, but downstream tools need it.
npcomp status <folder> [--ratio F] [--throughput MBS]
- Reports per-file state (
raw-only / both / compressed-only / incomplete, plus+tmpfor leftovers) and sizes. - Compressed files use actual sizes for the saved-space figure; uncompressed files are estimated with the default compression ratio 3.0 (
--ratio) and throughput 88 MB/s (--throughput). - Status is based on file existence and size only; it does not validate file contents.
Safety design
- Lossless + automatic verification: compression and decompression both run a byte-per-byte check; failures raise errors and clean up temp files, so no half-written output survives.
- Atomic rename: data is written to
*.tmpfirst and renamed into place viaos.replaceonly after verification; a power loss leaves only.tmpfiles, which are cleaned automatically on the next run. Source.binfiles are never touched by a failed run. - Conservative deletion: only an explicit
--deleteremoves source.binfiles, and only those successfully compressed and verified in this run. - Backup verification: in
--destmode every copied file is byte-verified after copying;.npcomp_manifest.jsonin the destination records the SHA-256 of every source file (plus the.cbin/.chhashes for recordings), so re-runs skip unchanged content and detect same-name/different-content or tampered files. - Space check before writing:
compressestimates the output size (raw size / 3 plus a small per-file overhead) and refuses to start when the target drive — or the scratch drive, against the largest single file — lacks room. If a disk still fills up mid-run, the run aborts immediately instead of failing file by file. - Two-step rename caveat:
.cbinand.chare each renamed into place in separate steps; a power loss in between can leave a mismatched pair. The nextcompressrun detects this via the manifest and prompts to recompress (self-healing). - Keep the trio: after backup, keep
X.cbin + X.ch + X.metatogether. Losing.chmakes decompression impossible; losing.metamakes the restored data unusable by downstream tools.
License
This project is licensed under the BSD 3-Clause License.
Metadata
Release files for npcomp 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| npcomp-0.1.0.tar.gz | 21.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| npcomp-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 37.5 kB
Release files / npcomp-0.1.0.tar.gz
| Download URL | npcomp-0.1.0.tar.gz |
|---|---|
| Size | 21.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9b21df5b5a853ea9a35eb4018281451709ade8de88a66cc7e5c5f60a0cd50982
|
|
BLAKE2b-256 checksum How to use checksums |
cbd808f6a94a11d37e593287c28425b9c7487eae0f05748b940ae4582e746eba
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.20
|
Release files / npcomp-0.1.0-py3-none-any.whl
| Download URL | npcomp-0.1.0-py3-none-any.whl |
|---|---|
| Size | 16.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a4abe86953a210503451a8890243855d86a5fc0e83de4469751dc2dac83e6cd8
|
|
BLAKE2b-256 checksum How to use checksums |
d0f925031428ff1b41881f7e14a149c61c7edf33a08bb66d677dfa489e4fb12e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.20
|