How to write your own lfpack file

compress_bin_to_h5 starts from a SpikeGLX binary. For anything else (another acquisition system, simulated data, an array already in memory) use compress_to_h5, which runs only the codec on a time-first (ns, nc) float32 .npy:

import numpy as np
from lfpack import compress_to_h5

np.save("probe00.npy", data)   # (ns, nc) float32, already at the rate to store
compress_to_h5("probe00.npy", "session.lf.h5", recording="probe00", fs=250.0, alpha=7.0)

recording is any unique key (IBL uses the probe-insertion UUID); it becomes the top-level HDF5 group and is what LFPackReader(..., recording=) selects. Pass h= for the probe geometry and channels= for brain locations; see compress_to_h5 for every parameter.

Several recordings in one file

Write one file per recording, then merge them without re-compressing:

from lfpack import merge_h5, subset_h5

merge_h5(["probe00.lf.h5", "probe01.lf.h5"], "session.lf.h5")
subset_h5("session.lf.h5", "probe01_only.lf.h5", recordings=["probe01"])

Attach sync

Affine: a sync-corrected rate and start time, enough for ordinary clock drift:

compress_to_h5("probe00.npy", "probe00.lf.h5", recording="probe00", fs=250.0,
               t0_sync=12.345, fs_sync=249.998)

Piecewise: when the sample-to-time mapping is not a straight line (a step, a truncated recording), write the knots after compression. write_sync_attrs also stores their least-squares affine as t0_sync/fs_sync, and the reader interpolates through the knots:

import h5py
import lfpack

with h5py.File("probe00.lf.h5", "a") as f:
    meta = f["probe00/00/meta"]
    lfpack.clear_sync_attrs(meta)                           # drop a previous attempt
    lfpack.write_sync_attrs(meta, sample_knots, time_knots)  # float64, increasing