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
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) 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.3.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.3.0
File Size Uploaded
calab-0.3.0.tar.gz 173.1 kB Details

Built distributions (wheels)

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

Total release size: 3.8 MB

Release files / calab-0.3.0.tar.gz

Download URL calab-0.3.0.tar.gz
Size 173.1 kB
Tags Source
SHA-256 checksum
How to use checksums
99c630dc5a519c280ad57698df2742b918c45100db7120cba871402223a1df4c
BLAKE2b-256 checksum
How to use checksums
9035465c012613134bc3a70f7a63c6b4d7c27233d8f226cdfcc447a65857f64e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 3, 2026.

Transparency log

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

Download URL calab-0.3.0-cp311-abi3-win_amd64.whl
Size 794.3 kB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
157f9bf017bfbb4b0c127a96dedf6af002d94ad9ea880268a11f51155044a187
BLAKE2b-256 checksum
How to use checksums
a9035b3148888fdde86650e572124ba4fb4d20515c1439415f8b3ce394828eb2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 3, 2026.

Transparency log

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

Download URL calab-0.3.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 859.2 kB
Tags CPython 3.11 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
3fbc24c7af4216fff6313481fbf2766a6933e017771eeeea2417fb20869225aa
BLAKE2b-256 checksum
How to use checksums
f9e1f69177280b1bc695b95c6aced6b8659b228968cbcb511691811a13e06c2c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 3, 2026.

Transparency log

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

Download URL calab-0.3.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 628.0 kB
Tags CPython 3.11 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
75cdf8616057cf2605b1ddc66683ee621fc3a49004dd6968a65b9ece98e62556
BLAKE2b-256 checksum
How to use checksums
b033ca97efa1bc1f33a32d7ddf7407d7f149093060e66d6285cf9ccf51e4d650
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 3, 2026.

Transparency log

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

Download URL calab-0.3.0-cp311-abi3-macosx_11_0_arm64.whl
Size 609.5 kB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
5e7a7e3a3eef64e13921cf0771f5ee8b502d08b4d7a992f3ce4c343d5d7188b6
BLAKE2b-256 checksum
How to use checksums
86480b32ef7390558077ef09fe42d755c3b9443265f9c60a379b225828a0d70b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 3, 2026.

Transparency log

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

Download URL calab-0.3.0-cp311-abi3-macosx_10_12_x86_64.whl
Size 784.0 kB
Tags CPython 3.11 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
fd39ee507b6d3c90d778177bb33d1fca23d340198897af881daa25c58c40cac6
BLAKE2b-256 checksum
How to use checksums
892444260d4be8c93b76296f9114118a87b0bddc485e11e93472f2021651dd96
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 3, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.3.0 This release

6 release files

0.2.4

6 release files

0.2.3

6 release files

0.2.2

6 release files

0.2.1

6 release files

0.2.0

6 release files

0.1.0

2 release files

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