Skip to main content

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
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) raise ValueError if an input trace/array contains NaN or Inf, rather than returning garbage. fit_biexponential's fit_mode reports 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.5.0

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

Source distribution (sdist)

Source distribution for calab 0.5.0
File Size Uploaded Provenance Actions
calab-0.5.0.tar.gz 271.6 kB With provenance Details for calab-0.5.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for calab 0.5.0
File Actions
calab-0.5.0-cp311-abi3-win_amd64.whl CPython 3.11 abi3 Windows x86-64 Details for calab-0.5.0-cp311-abi3-win_amd64.whl
calab-0.5.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.11 abi3 Linux glibc 2.17+ x86-64 Details for calab-0.5.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
calab-0.5.0-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.11 abi3 Linux glibc 2.17+ ARM64 Details for calab-0.5.0-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
calab-0.5.0-cp311-abi3-macosx_11_0_arm64.whl CPython 3.11 abi3 macOS 11.0+ ARM64 Details for calab-0.5.0-cp311-abi3-macosx_11_0_arm64.whl
calab-0.5.0-cp311-abi3-macosx_10_12_x86_64.whl CPython 3.11 abi3 macOS 10.12+ x86-64 Details for calab-0.5.0-cp311-abi3-macosx_10_12_x86_64.whl

Total release size: 5.4 MB

Release files / calab-0.5.0.tar.gz

Download URL calab-0.5.0.tar.gz
Size 271.6 kB
Tags Source
SHA-256 checksum
How to use checksums
e13916caa28053ab3bc5a69a0b03a02c0f5f60793fd14bad5933823fbb82ccc1
BLAKE2b-256 checksum
How to use checksums
34fc33a99d38e69c28567e181a2ac34d91031c28e1b89f418fe7366c4ed6d4fc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 7, 2026.

Transparency log

Release files / calab-0.5.0-cp311-abi3-win_amd64.whl

Download URL calab-0.5.0-cp311-abi3-win_amd64.whl
Size 1.2 MB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
22b5a2e080d403f6e5bbc5e0d815c8c4bb47dc2ebce5a4a7b8c540945e1341e4
BLAKE2b-256 checksum
How to use checksums
5b75d34e6945d57557715a308f84dcbd84d6da60a717e6d64f790fff13ae78a8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 7, 2026.

Transparency log

Release files / calab-0.5.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL calab-0.5.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 1.2 MB
Tags CPython 3.11 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
ae0c89ea0ca5446e5c8684bcfd314f58d11109ba40f3fc9d1d1c088beccef686
BLAKE2b-256 checksum
How to use checksums
93af158ea49f7c1a6a8ceeae37902ff1c0437d2cc872cff30eb2d1b74931cf1c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 7, 2026.

Transparency log

Release files / calab-0.5.0-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL calab-0.5.0-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 842.3 kB
Tags CPython 3.11 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
a20d6b2ababb7d1b90c2f5218141dbcb35d8159234e8acb82d6e6cfa3a7dc4a3
BLAKE2b-256 checksum
How to use checksums
0d78f6c4b2608dc3101300d09c7bb005b64d1f18659dd8c9f284b9877652c68b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 7, 2026.

Transparency log

Release files / calab-0.5.0-cp311-abi3-macosx_11_0_arm64.whl

Download URL calab-0.5.0-cp311-abi3-macosx_11_0_arm64.whl
Size 809.5 kB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
8e66083011a3f8aa9b9aa03a937cb51d8fa6416c327c35ac5babacf93607337d
BLAKE2b-256 checksum
How to use checksums
bf22374c87f03e774373d045aefd1df532085ce61e9d9ef0732ab9ef598262d9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 7, 2026.

Transparency log

Release files / calab-0.5.0-cp311-abi3-macosx_10_12_x86_64.whl

Download URL calab-0.5.0-cp311-abi3-macosx_10_12_x86_64.whl
Size 1.1 MB
Tags CPython 3.11 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
b32634be2ef04c94e9a3f1469e918674e0cb7bb0eecc8b8675f86094a2979009
BLAKE2b-256 checksum
How to use checksums
fe4dfdc07e0e1954f1630555429d33989a555042d8f18c5ea91cc8c7cebde93e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 7, 2026.

Transparency log

Security for calab 0.5.0

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.

Full provenance

All 6 files in this release have been uploaded with provenance metadata.

Select from 6 files

Attestation for calab-0.5.0.tar.gz

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 Nov 7, 2026.

Transparency log

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