CaLab Python
Calcium imaging analysis tools -- deconvolution, simulation, and data preparation. Python companion package for the CaLab web tools.
The calab package runs the same Rust FISTA solver used by the CaLab web apps (compiled to a native Python extension via PyO3), and provides two deconvolution approaches:
- CaTune -- interactive parameter tuning in the browser, then batch deconvolution with those parameters. Uses established FISTA deconvolution with a double-exponential kernel.
- CaDecon -- automated deconvolution that estimates the calcium kernel and parameters from your data. A new approach developed by the CaLab team.
Plus utilities for loading data from common pipelines, synthetic trace simulation with ground truth, and batch processing from scripts.
Full documentation: calab.readthedocs.io
Installation
pip install calab
# Optional: CaImAn HDF5 and Minian Zarr loaders
pip install calab[loaders]
# Optional: headless browser for batch CaDecon runs
pip install calab[headless]
playwright install chromium
Requires Python 3.10+. Pre-built wheels include the compiled Rust solver for Linux, macOS, and Windows -- no Rust toolchain needed.
CaTune: Interactive Parameter Tuning
Choose your deconvolution parameters visually in the browser, then apply them in batch.
1. Tune in the browser
import numpy as np
import calab
traces = np.load("my_traces.npy") # (n_cells, n_timepoints)
# Opens CaTune in the browser -- tune parameters, click Export
params = calab.tune(traces, fs=30.0)
# Returns: {'tau_rise': 0.02, 'tau_decay': 0.4, 'lambda_': 0.01, 'fs': 30.0, 'filter_enabled': False}
2. Batch deconvolution
Apply the parameters you chose (or values from the literature) across all traces:
activity = calab.run_deconvolution(
traces, fs=30.0,
tau_r=params["tau_rise"],
tau_d=params["tau_decay"],
lam=params["lambda_"],
)
# Full diagnostics: baseline, reconvolution, convergence
result = calab.run_deconvolution_full(traces, fs=30.0, tau_r=0.02, tau_d=0.4, lam=0.01)
Note: The deconvolved output represents scaled neural activity, not discrete spikes or firing rates. The signal is scaled by an unknown constant (indicator expression level, optical path, etc.), so absolute values should not be interpreted as spike counts.
3. From a CaTune export JSON
params = calab.load_export_params("catune-params.json")
activity = calab.deconvolve_from_export(traces, "catune-params.json")
CaDecon: Automated Deconvolution
CaDecon estimates the calcium kernel and deconvolution parameters from your data -- no manual tuning needed.
Interactive mode
result = calab.decon(traces, fs=30.0)
Autorun mode
result = calab.decon(traces, fs=30.0, autorun=True)
print(result.activity.shape) # (n_cells, n_timepoints), float32
print(result.kernel_slow.shape) # estimated slow kernel waveform
print(result.metadata) # tau values, convergence info, etc.
Headless mode (batch processing)
Run without a browser window. Requires pip install calab[headless] and playwright install chromium.
# Single run
result = calab.decon(traces, fs=30.0, headless=True, autorun=True)
# Batch processing (reuses one browser across datasets)
from calab import HeadlessBrowser
with HeadlessBrowser() as hb:
for traces, fs in datasets:
result = calab.decon(traces, fs, headless=hb, autorun=True)
Loading Data
# CaImAn HDF5 -- reads traces and sampling rate directly
traces, meta = calab.load_caiman("caiman_results.hdf5")
# Minian Zarr -- reads traces, sampling rate must be provided
traces, meta = calab.load_minian("minian_output/", fs=30.0)
# Both return (ndarray, dict) with shape (n_cells, n_timepoints)
Requires pip install calab[loaders].
Saving for CaTune
calab.save_for_tuning(traces, fs=30.0, path="my_recording")
# Creates my_recording.npy + my_recording_metadata.json
Synthetic Data Simulation
Generate synthetic calcium traces with ground truth for testing and benchmarking. The simulation runs in Rust for performance.
result = calab.simulate()
print(result.traces.shape) # (100, 27000)
print(result.ground_truth[0].spikes) # spike counts at imaging rate for cell 0
Available presets: gcamp6f, gcamp6s, gcamp6m, jgcamp8f, ogb1, and clean (minimal noise, for debugging). These are approximate starting points for generating synthetic data.
Custom configuration with Pydantic models:
from calab import SimulationConfig, KernelConfig, NoiseConfig, PoissonConfig
config = SimulationConfig(
num_cells=20,
num_timepoints=9000,
fs_hz=30.0,
kernel=KernelConfig(tau_rise_s=0.05, tau_decay_s=0.3),
spike_model=PoissonConfig(rate_hz=2.0),
noise=NoiseConfig(snr=5.0),
)
result = calab.simulate(config)
CLI
# CaTune: interactive tuning
calab tune my_traces.npy --fs 30.0
# CaDecon: automated deconvolution
calab cadecon my_traces.npy --fs 30.0 -o results
# Batch deconvolution with CaTune export params
calab deconvolve my_traces.npy --params catune-params.json -o activity.npy
# Convert from CaImAn/Minian to CaLab format
calab convert caiman_results.hdf5 --format caiman -o my_recording
# Show file info
calab info my_traces.npy
# Print version
calab --version
API Reference
For full API documentation with parameter details, see calab.readthedocs.io.
CaTune
| Function | Description |
|---|---|
tune(traces, fs, ...) |
Open CaTune in browser for interactive tuning |
run_deconvolution(traces, fs, tau_r, tau_d, lam) |
FISTA deconvolution, returns activity array |
run_deconvolution_full(traces, fs, tau_r, tau_d, lam) |
Full result with baseline, reconvolution |
load_export_params(path) |
Load params from CaTune export JSON |
deconvolve_from_export(traces, params_path) |
Load params + deconvolve in one step |
save_for_tuning(traces, fs, path) |
Save traces for CaTune browser |
load_tuning_data(path) |
Load traces saved by save_for_tuning |
DeconvolutionResult |
Namedtuple: activity, baseline, reconvolution, iterations, converged |
CaDecon
| Function / Type | Description |
|---|---|
decon(traces, fs, ...) |
Open CaDecon in browser |
HeadlessBrowser() |
Context manager for headless browser sessions |
solve_trace(trace, tau_rise, tau_decay, fs, ...) |
Single-trace InDeCa pipeline |
estimate_kernel(traces_flat, spikes_flat, ...) |
Free-form kernel estimation |
fit_biexponential(h_free, fs, ...) |
Bi-exponential kernel fit |
compute_upsample_factor(fs, target_fs) |
Upsample factor for target rate |
CaDeconResult |
Namedtuple: activity, alphas, baselines, pves, kernels, fs, metadata |
SolveTraceResult |
Namedtuple: s_counts, alpha, baseline, threshold, pve, iterations, converged |
BiexpFitResult |
Namedtuple: tau_rise, tau_decay, beta, residual, fast-component fields, fit_mode |
Non-finite input: the deconvolution/fit entry points (
run_deconvolution*,solve_trace,estimate_kernel,fit_biexponential, and the batch paths) raiseValueErrorif an input trace/array containsNaNorInf, rather than returning garbage.fit_biexponential'sfit_modereports the outcome ("TwoComponent"/"SlowOnly"/"Degenerate"/"Empty").
Shared Utilities
| Function | Description |
|---|---|
build_kernel(tau_rise, tau_decay, fs) |
Double-exponential calcium kernel |
bandpass_filter(trace, tau_rise, tau_decay, fs) |
FFT bandpass filter from kernel params |
compute_lipschitz(kernel) |
Lipschitz constant for FISTA step size |
tau_to_ar2(tau_rise, tau_decay, fs) |
AR(2) coefficients from tau values |
Loaders
| Function | Description |
|---|---|
load_caiman(path, ...) |
Load traces from CaImAn HDF5 file |
load_minian(path, ...) |
Load traces from Minian Zarr directory |
Simulation
| Function / Type | Description |
|---|---|
simulate(config, ...) |
Generate synthetic calcium traces with ground truth |
presets |
Built-in indicator presets (gcamp6f, gcamp6s, gcamp6m, jgcamp8f, ogb1, clean) |
SimulationConfig |
Top-level simulation configuration (Pydantic model) |
SimulationResult |
Result with traces array and per-cell ground truth |
CellGroundTruth |
Per-cell ground truth: spikes, clean_calcium, alpha, snr, tau values |
KernelConfig |
Double-exponential kernel parameters |
MarkovConfig |
Two-state HMM spike generator (default) |
PoissonConfig |
Homogeneous Poisson spike generator |
NoiseConfig |
Gaussian + optional shot noise |
SinusoidalDrift |
Deterministic sinusoidal baseline drift |
RandomWalkDrift |
Mean-reverting random walk drift (default) |
PhotobleachingConfig |
Exponential photobleaching model |
SaturationConfig |
Hill equation indicator saturation model |
Metadata
Release files for calab 0.2.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| calab-0.2.4.tar.gz | 118.4 kB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| calab-0.2.4-cp311-abi3-win_amd64.whl | CPython 3.11 | abi3 | Windows x86-64 | Details |
| calab-0.2.4-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | CPython 3.11 | abi3 | Linux glibc 2.17+ x86-64 | Details |
| calab-0.2.4-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl | CPython 3.11 | abi3 | Linux glibc 2.17+ ARM64 | Details |
| calab-0.2.4-cp311-abi3-macosx_11_0_arm64.whl | CPython 3.11 | abi3 | macOS 11.0+ ARM64 | Details |
| calab-0.2.4-cp311-abi3-macosx_10_12_x86_64.whl | CPython 3.11 | abi3 | macOS 10.12+ x86-64 | Details |
Total release size: 3.6 MB
Release files / calab-0.2.4.tar.gz
| Download URL | calab-0.2.4.tar.gz |
|---|---|
| Size | 118.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fe964bc82cd969fe7c30480764b2b7e2b24687fbce84dd85e077928c72856b35
|
|
BLAKE2b-256 checksum How to use checksums |
56c4d15f711d5be1cabd37c1ebb387c71916c61ec1fd69430078c3c8375c5ec4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.13
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 25, 2026.
Transparency logRelease files / calab-0.2.4-cp311-abi3-win_amd64.whl
| Download URL | calab-0.2.4-cp311-abi3-win_amd64.whl |
|---|---|
| Size | 749.5 kB |
| Tags | CPython 3.11 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
9a442e0312eba1e60ec815115ea9e43f6134275ce9560d6494283e32329d30f4
|
|
BLAKE2b-256 checksum How to use checksums |
ded492e8038437534d084e8346aadd3d15f48c98189c92919e5016449cbfb503
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.13
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 25, 2026.
Transparency logRelease files / calab-0.2.4-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | calab-0.2.4-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 820.6 kB |
| Tags | CPython 3.11 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
43ad107b6c6f8c55d07f577c1bb964f4798fe5d1e51949783bdf5831216c5315
|
|
BLAKE2b-256 checksum How to use checksums |
eb8ee5bcbebeb9ac94a3d6f490ef43aa08ea22292480130af8231b76d06bee7e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.13
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 25, 2026.
Transparency logRelease files / calab-0.2.4-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | calab-0.2.4-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 594.5 kB |
| Tags | CPython 3.11 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
7ec144cbddc666be7dbd36338608b28cf4865c540c0b8df712a5b2a7f28bbe81
|
|
BLAKE2b-256 checksum How to use checksums |
8984f85fcf10b08d64ebbdd118ca796207a63d2d57d848731a1690aab028b1fb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.13
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 25, 2026.
Transparency logRelease files / calab-0.2.4-cp311-abi3-macosx_11_0_arm64.whl
| Download URL | calab-0.2.4-cp311-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 570.9 kB |
| Tags | CPython 3.11 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
ddd3321721eddb6480fb550cc98389786ae8275e36563d5c8b2fb4a93463b51e
|
|
BLAKE2b-256 checksum How to use checksums |
ae5d5c95f9e18508e9e53f26192906b1aed5b630e92a883a1e4a5519cf411205
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.13
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 25, 2026.
Transparency logRelease files / calab-0.2.4-cp311-abi3-macosx_10_12_x86_64.whl
| Download URL | calab-0.2.4-cp311-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 743.4 kB |
| Tags | CPython 3.11 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
f04eb4b5481aee9559874fac11e7f5d7206728d830b8dab68e3003d1f7197750
|
|
BLAKE2b-256 checksum How to use checksums |
924e0b1341602dd968da1ff9c9c290e83c8c68adcef6165384dca1becb39328c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.13
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 25, 2026.
Transparency log