CaLab: calcium imaging analysis tools — deconvolution and data preparation
Project description
CaLab Python
Calcium imaging analysis tools — deconvolution and data preparation. Python companion package for the CaLab tools.
The calab package runs the same Rust FISTA solver used by the CaTune web app (compiled to a native Python extension via PyO3), and provides utilities for loading data from common pipelines, interactive parameter tuning in the browser, and batch deconvolution from scripts.
Installation
pip install calab
# Optional: CaImAn HDF5 and Minian Zarr loaders
pip install calab[loaders]
Note: Pre-built wheels include the compiled Rust solver for Linux, macOS, and Windows. No Rust toolchain is needed for installation.
Quick Start
import numpy as np
import calab
# Load your calcium traces (n_cells x n_timepoints)
traces = np.load("my_traces.npy")
# Interactive tuning: opens CaTune in the browser, returns exported params
params = calab.tune(traces, fs=30.0)
# Batch deconvolution with tuned parameters
activity = calab.run_deconvolution(
traces, fs=30.0,
tau_r=params["parameters"]["tau_rise_s"],
tau_d=params["parameters"]["tau_decay_s"],
lam=params["parameters"]["lambda"],
)
Loading Data
Direct loaders (CaImAn, Minian)
# CaImAn HDF5 — reads traces and sampling rate directly
traces, meta = calab.load_caiman("caiman_results.hdf5")
# Minian Zarr — reads traces, fs must be provided
traces, meta = calab.load_minian("minian_output/", fs=30.0)
# Both return (ndarray, dict) with shape (n_cells, n_timepoints)
print(meta)
# {'source': 'caiman', 'sampling_rate_hz': 30.0, 'num_cells': 256, 'num_timepoints': 9000}
Requires optional dependencies: 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
Interactive Tuning (Bridge)
calab.tune() starts a local HTTP server, opens CaTune in the browser with your data pre-loaded, and waits for you to export parameters:
params = calab.tune(traces, fs=30.0)
# Browser opens → tune parameters → click Export
# params contains the CaTune export JSON
The bridge serves traces via http://127.0.0.1:<port> and the web app communicates back via the ?bridge= URL parameter.
Deconvolution
Run FISTA deconvolution using the native Rust solver:
# Basic: returns non-negative activity array
activity = calab.run_deconvolution(traces, fs=30.0, tau_r=0.02, tau_d=0.4, lam=0.01)
# Full: returns activity, baseline, reconvolution, iterations, converged
result = calab.run_deconvolution_full(traces, fs=30.0, tau_r=0.02, tau_d=0.4, lam=0.01)
print(f"Baseline: {result.baseline}, Converged: {result.converged}")
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.
Bandpass Filter
Apply the same FFT bandpass filter used in the CaTune web app:
filtered = calab.bandpass_filter(trace, tau_rise=0.02, tau_decay=0.4, fs=100.0)
Using CaTune Export JSON
Load parameters from a CaTune export and run deconvolution:
params = calab.load_export_params("catune-params-2025-01-15.json")
# {'tau_rise': 0.02, 'tau_decay': 0.4, 'lambda_': 0.01, 'fs': 30.0, 'filter_enabled': False}
# One-step pipeline: loads params, optionally filters, deconvolves
activity = calab.deconvolve_from_export(traces, "catune-params-2025-01-15.json")
Kernel Math
kernel = calab.build_kernel(tau_rise=0.02, tau_decay=0.4, fs=30.0)
g1, g2, d, r = calab.tau_to_ar2(tau_rise=0.02, tau_decay=0.4, fs=30.0)
L = calab.compute_lipschitz(kernel)
CLI
The calab command-line tool is installed with the package:
# Interactive tuning
calab tune my_traces.npy --fs 30.0
# Batch deconvolution with exported 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
API Reference
| Function | Description |
|---|---|
tune(traces, fs, ...) |
Open CaTune in browser for interactive tuning |
load_caiman(path, ...) |
Load traces from CaImAn HDF5 file |
load_minian(path, ...) |
Load traces from Minian Zarr directory |
build_kernel(tau_rise, tau_decay, fs) |
Build double-exponential calcium kernel |
tau_to_ar2(tau_rise, tau_decay, fs) |
Derive AR(2) coefficients from tau values |
compute_lipschitz(kernel) |
Lipschitz constant for FISTA step size |
run_deconvolution(traces, fs, tau_r, tau_d, lam) |
FISTA deconvolution, returns activity |
run_deconvolution_full(traces, fs, tau_r, tau_d, lam) |
Full result with baseline, reconvolution |
bandpass_filter(trace, tau_rise, tau_decay, fs) |
FFT bandpass filter from kernel params |
save_for_tuning(traces, fs, path) |
Save traces for CaTune browser tool |
load_tuning_data(path) |
Load traces saved by save_for_tuning |
load_export_params(path) |
Load params from CaTune export JSON |
deconvolve_from_export(traces, params_path) |
Full pipeline: load params + deconvolve |
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file calab-0.2.0.tar.gz.
File metadata
- Download URL: calab-0.2.0.tar.gz
- Upload date:
- Size: 138.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
77c40340108f8f39a743231428b0ded1036e5bc2b93a7f6093229985e8369090
|
|
| MD5 |
a4574179ee50578040ef64050739de74
|
|
| BLAKE2b-256 |
72c5db94d57d59bb4690f791e11a0eb70eef512a7ee0edf6ddba04f94c488e4f
|
Provenance
The following attestation bundles were made for calab-0.2.0.tar.gz:
Publisher:
publish-python.yml on miniscope/CaLab
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
calab-0.2.0.tar.gz -
Subject digest:
77c40340108f8f39a743231428b0ded1036e5bc2b93a7f6093229985e8369090 - Sigstore transparency entry: 983942488
- Sigstore integration time:
-
Permalink:
miniscope/CaLab@6ae05c3c5bf6b35c30f2b09d7600de8ddbcde6e9 -
Branch / Tag:
refs/tags/py/v0.2.0 - Owner: https://github.com/miniscope
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python.yml@6ae05c3c5bf6b35c30f2b09d7600de8ddbcde6e9 -
Trigger Event:
push
-
Statement type:
File details
Details for the file calab-0.2.0-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: calab-0.2.0-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 618.8 kB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2f3c5f724626e49e078e3329e09e7df20e8d78e9d869265928cb70944632a25b
|
|
| MD5 |
75ef6275f9822caca3ee45e838ebb33a
|
|
| BLAKE2b-256 |
fc70cb3fddde26896e4bf18b263444425ef86e1d891a08633d9fe076ed4a5605
|
Provenance
The following attestation bundles were made for calab-0.2.0-cp312-cp312-win_amd64.whl:
Publisher:
publish-python.yml on miniscope/CaLab
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
calab-0.2.0-cp312-cp312-win_amd64.whl -
Subject digest:
2f3c5f724626e49e078e3329e09e7df20e8d78e9d869265928cb70944632a25b - Sigstore transparency entry: 983942618
- Sigstore integration time:
-
Permalink:
miniscope/CaLab@6ae05c3c5bf6b35c30f2b09d7600de8ddbcde6e9 -
Branch / Tag:
refs/tags/py/v0.2.0 - Owner: https://github.com/miniscope
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python.yml@6ae05c3c5bf6b35c30f2b09d7600de8ddbcde6e9 -
Trigger Event:
push
-
Statement type:
File details
Details for the file calab-0.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: calab-0.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 691.7 kB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8eb56393ed34e51acf4e8df6e6565f35d73ec5c4e69d0a154a084ec9b0e18715
|
|
| MD5 |
9a165bf07163cc43c8f37116726a9e80
|
|
| BLAKE2b-256 |
47a3dfda1a2aec03626e1a5704deb52a0beda82f37d7f7ca0184aa14b02cb8c2
|
Provenance
The following attestation bundles were made for calab-0.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
publish-python.yml on miniscope/CaLab
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
calab-0.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
8eb56393ed34e51acf4e8df6e6565f35d73ec5c4e69d0a154a084ec9b0e18715 - Sigstore transparency entry: 983942548
- Sigstore integration time:
-
Permalink:
miniscope/CaLab@6ae05c3c5bf6b35c30f2b09d7600de8ddbcde6e9 -
Branch / Tag:
refs/tags/py/v0.2.0 - Owner: https://github.com/miniscope
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python.yml@6ae05c3c5bf6b35c30f2b09d7600de8ddbcde6e9 -
Trigger Event:
push
-
Statement type:
File details
Details for the file calab-0.2.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: calab-0.2.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 475.9 kB
- Tags: CPython 3.12, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cb6816c72aadad770b0b3a55adc140366d026cf8463047c2c78fb9a3f08bff8b
|
|
| MD5 |
b811e63ad770ee71b5dfdf9fcdb0919e
|
|
| BLAKE2b-256 |
2a5a6f74cdaa14134328336dbe08e54c03e2122ec91d853d6dd3f6cfa28750f4
|
Provenance
The following attestation bundles were made for calab-0.2.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:
Publisher:
publish-python.yml on miniscope/CaLab
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
calab-0.2.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl -
Subject digest:
cb6816c72aadad770b0b3a55adc140366d026cf8463047c2c78fb9a3f08bff8b - Sigstore transparency entry: 983942586
- Sigstore integration time:
-
Permalink:
miniscope/CaLab@6ae05c3c5bf6b35c30f2b09d7600de8ddbcde6e9 -
Branch / Tag:
refs/tags/py/v0.2.0 - Owner: https://github.com/miniscope
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python.yml@6ae05c3c5bf6b35c30f2b09d7600de8ddbcde6e9 -
Trigger Event:
push
-
Statement type:
File details
Details for the file calab-0.2.0-cp312-cp312-macosx_11_0_arm64.whl.
File metadata
- Download URL: calab-0.2.0-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 450.7 kB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b0e18a9eca42270c5b427dbbb1c159ae3762bd10fb9f233a4f82d1cc4e53b816
|
|
| MD5 |
19298f6ddd99585cebf74ef11da35787
|
|
| BLAKE2b-256 |
337d8bc703bd2dd9cca350efc5ab18930751eec0ffdc2cc7a83f151d1b291971
|
Provenance
The following attestation bundles were made for calab-0.2.0-cp312-cp312-macosx_11_0_arm64.whl:
Publisher:
publish-python.yml on miniscope/CaLab
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
calab-0.2.0-cp312-cp312-macosx_11_0_arm64.whl -
Subject digest:
b0e18a9eca42270c5b427dbbb1c159ae3762bd10fb9f233a4f82d1cc4e53b816 - Sigstore transparency entry: 983942650
- Sigstore integration time:
-
Permalink:
miniscope/CaLab@6ae05c3c5bf6b35c30f2b09d7600de8ddbcde6e9 -
Branch / Tag:
refs/tags/py/v0.2.0 - Owner: https://github.com/miniscope
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python.yml@6ae05c3c5bf6b35c30f2b09d7600de8ddbcde6e9 -
Trigger Event:
push
-
Statement type:
File details
Details for the file calab-0.2.0-cp312-cp312-macosx_10_12_x86_64.whl.
File metadata
- Download URL: calab-0.2.0-cp312-cp312-macosx_10_12_x86_64.whl
- Upload date:
- Size: 612.3 kB
- Tags: CPython 3.12, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ed897fad4e2e4c5bef07a1433c4432442e34b3fa7f9dffe06a8239672deabd5a
|
|
| MD5 |
77292f5d455a12a811e12e37651943b0
|
|
| BLAKE2b-256 |
c22dc5b8f5ba64b05e225308d667c9ebf3b64b5582de90e7311201440a68cc84
|
Provenance
The following attestation bundles were made for calab-0.2.0-cp312-cp312-macosx_10_12_x86_64.whl:
Publisher:
publish-python.yml on miniscope/CaLab
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
calab-0.2.0-cp312-cp312-macosx_10_12_x86_64.whl -
Subject digest:
ed897fad4e2e4c5bef07a1433c4432442e34b3fa7f9dffe06a8239672deabd5a - Sigstore transparency entry: 983942523
- Sigstore integration time:
-
Permalink:
miniscope/CaLab@6ae05c3c5bf6b35c30f2b09d7600de8ddbcde6e9 -
Branch / Tag:
refs/tags/py/v0.2.0 - Owner: https://github.com/miniscope
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python.yml@6ae05c3c5bf6b35c30f2b09d7600de8ddbcde6e9 -
Trigger Event:
push
-
Statement type: