Skip to main content

datapack

Lossless and visually-lossless compression of acquisition data (ephys, video, histology) with verification and manifests.

datapack moves raw acquisition data into a compressed state, verifies every artifact, and writes a manifest so a downstream offload/tape process can move it and delete the original with confidence. It only ever reads the source — it never mutates or deletes the raw data.

What it handles

Modality Lossless? Engine Typical saving Notes
Ephys (Neuropixels / Open Ephys) lossless (bit-exact) IBL mtscomp (.cbin+.ch) ~⅓ (NP1 ~59%) round-trips back to identical .dat
Video (behavioural, H.264) visually lossless ffmpeg HEVC (NVENC) ~35–65% re-encode for DLC/SLEAP; the .mp4 is the working form
Histology (TIFF: brainsaw/StitchIt, brainreg) lossless (bit-exact) tifffile ADOBE_DEFLATE + predictor ~⅔ (labels 40–75×) files stay natively readable; tracks/metadata copied verbatim

Design principles

  • Compress only the large data. Metadata, .npy tracks, recipes, logs, JSON/CSV are copied byte-for-byte verbatim.
  • Verify before trusting. Lossless engines prove a bit-exact round-trip; video checks frame-count + clean decode. Verification gates the artifact before it lands.
  • Round-trip in place. Lossless outputs stay readable / restorable, so you can work on them in scratch (spike-sorting, image processing) and recompress — no lock-in.
  • Never touch the source. Write-to-temp → verify → atomic rename; originals untouched.
  • Manifests record sizes, ratios, hashes, params and tool versions for the offload step.

Installation

pip install datapack-neuro                # core (CLI + histology-independent pieces)
pip install "datapack-neuro[ephys]"       # + mtscomp, numpy, tqdm (ephys engine)
pip install "datapack-neuro[histology]"   # + tifffile, imagecodecs, numpy (histology engine)

The distribution is datapack-neuro; the import name is datapack. An unrelated datapack project already holds that name on PyPI.

Video needs an NVENC-enabled ffmpeg on the system (not a Python dep). datapack resolves it from --ffmpeg, then $DATAPACK_FFMPEG, then PATH. On a cluster, assume the GPU is managed externally — datapack fails loudly if no working GPU encoder is found rather than silently grinding on CPU (opt into the slow CPU path with --allow-cpu).

CLI

Run datapack <command> --help for full flags. All commands take a source and a destination and never modify the source.

compress — one file, modality auto-detected

datapack compress <src> <dst> [--modality ephys|video|histology] [--dry-run] [--report manifest.jsonl]

Detects the modality from the path (continuous.dat→ephys, .h264/.mp4→video, .tif/.tiff→histology) and runs the right engine. For tuned video/ephys runs prefer the dedicated commands below.

Ephys

# Compress a whole Open Ephys session: every continuous.dat -> .cbin/.ch,
# all sidecars (structure.oebin, *.npy, events/, settings.xml ...) copied verbatim.
datapack oe-session <session_dir> <dest_dir> [--threads N] [--chunk-duration S] \
                    [--no-sidecars] [--overwrite] [--dry-run] [--report manifest.jsonl]

# Restore a compressed session to a working/scratch tree (bit-exact .dat) for
# SpikeInterface / Kilosort. Inverse of oe-session.
datapack oe-restore <compressed_session_dir> <work_dir> [--overwrite]

Video

# Visually-lossless HEVC re-encode (NVENC; libx265 CPU fallback only with --allow-cpu).
datapack video <src.h264> <dst.mp4> [--quality safe|balanced|small] [--qp N] [--fps F] \
               [--ffmpeg /path/to/ffmpeg] [--allow-cpu] [--report manifest.jsonl]

--quality presets (preset p7, GOP 100): safe=qp18, balanced=qp20 (default), small=qp22. Provisional pending the lab's DLC/SLEAP tracking validation; --qp overrides. Raw .h264 has no timing, so --fps (default 100) is forced on input.

Histology

# In-place lossless recompression of every TIFF in a tree (e.g. a brainreg
# registration/), copying non-TIFF (incl. brainreg .npy tracks) verbatim. Output
# files stay normal, natively-readable TIFFs (ADOBE_DEFLATE) — no unpack needed.
datapack histology tree <src_dir> <dst_dir> [--codec deflate|zstd] [--level N] \
                        [--no-tile] [--overwrite] [--dry-run] [--report manifest.jsonl]

# Optional bundling: recompress a TIFF dir then store it as ONE archive (adds no
# compression over `tree` — purely bundling for transfer/tape).
datapack histology pack   <tiff_dir> <archive.zip> [--codec ...] [--level N] [--overwrite] [--dry-run]
datapack histology unpack <archive.zip> <work_dir> [--no-verify]   # extract + re-verify
datapack histology repack <work_dir> <archive.zip> [--codec ...] [--level N]  # after editing

Datasets (dataset-aware "pack and stash")

# Pack a brainsaw/StitchIt serial_section/<sample>/ sample. Default: recompress every
# TIFF in place (raw + registration) -> stays browsable; copy .npy tracks + recipe/
# logs/mat/ini verbatim. Use --archive-raw to bundle stitchedImages/downsampled
# into one zip each (no ratio benefit, only one-object-per-dir for transfer/tape).
datapack serial-section <sample_dir> <dest_dir> [--archive-raw] [--codec deflate|zstd] \
                        [--overwrite] [--dry-run]

Python API

import datapack

# one file (modality auto-detected or forced)
rec = datapack.compress_file("continuous.dat", "out.cbin",
                             params={"sample_rate": 30000, "n_channels": 384})
print(rec.ratio, rec.lossless, rec.verification.ok, rec.ready_to_offload)

# ephys session round-trip
datapack.compress_oe_session("session/", "compressed/")     # -> .cbin/.ch + sidecars
datapack.decompress_oe_session("compressed/", "scratch/")   # -> bit-exact .dat tree

# dataset-aware
datapack.pack_serial_section("serial_section/ap5l/", "packed/")

from datapack.engines import (
    EphysEngine, HistologyEngine, VideoEngine,   # Engine.compress(Job) -> ManifestRecord
    compress_tiff_tree, pack, unpack, repack,    # histology tree + archive
    probe_ffmpeg,                                 # video capability probe
)
from datapack.core import Job, ManifestRecord, ManifestWriter, read_manifest

Every engine returns a ManifestRecord (pydantic): source/output paths + sizes, ratio, lossless, the VerifyResult, engine + tool versions, and engine-specific extra (e.g. mtscomp sha1_uncompressed/sha1_compressed, or a TIFF decoded-pixel SHA-256). Write a run's records to JSON-lines with ManifestWriter and read them back with read_manifest.

Development setup

git clone https://github.com/larsrollik/datapack.git
cd datapack
uv sync --extra dev
uv run pre-commit install --hook-type pre-commit --hook-type commit-msg

Running tests

uv run pytest

Tests needing optional deps or a GPU skip automatically when unavailable. To exercise the real NVENC video path, point $DATAPACK_FFMPEG at an nvenc-enabled ffmpeg.

Release workflow

  1. Work on a feature/ or fix/ branch, committing with cz commit
  2. Open a PR — CI (lint + tests + secrets scan) must pass before merge
  3. Merge to main → version bump and tag are created automatically
  4. Tag triggers release: GitHub release + PyPI publish

License

See LICENSE.

Metadata

Release files for datapack-neuro 1.2.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for datapack-neuro 1.2.3
File Size Uploaded Provenance Actions
datapack_neuro-1.2.3.tar.gz 45.1 kB Without provenance Details for datapack_neuro-1.2.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for datapack-neuro 1.2.3
File Interpreter ABI Platform Actions
datapack_neuro-1.2.3-py3-none-any.whl Python 3 none any Details for datapack_neuro-1.2.3-py3-none-any.whl

Total release size: 88.5 kB

Release files / datapack_neuro-1.2.3.tar.gz

Download URL datapack_neuro-1.2.3.tar.gz
Size 45.1 kB
Tags Source
SHA-256 checksum
How to use checksums
cc00bb9bc0417c52bc01e73255197a41551a6b3e7a2f1b70302d2034f0f8ee3f
BLAKE2b-256 checksum
How to use checksums
4be17d7fa28833376126ae94b9637c8df722ccb032178dd84a3a2bf7ff0395a8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / datapack_neuro-1.2.3-py3-none-any.whl

Download URL datapack_neuro-1.2.3-py3-none-any.whl
Size 43.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
675c934c4e713957058a9c590e0f2c7e6e7c3dc93a49b95c43491e25826d1e09
BLAKE2b-256 checksum
How to use checksums
403df61417a1b46ba386f31e858d8c663514cb41d2e1000d00ccbf16a5c028d6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for datapack-neuro 1.2.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page