Skip to main content

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

calab-0.2.1.tar.gz (138.7 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

calab-0.2.1-cp312-cp312-win_amd64.whl (619.1 kB view details)

Uploaded CPython 3.12Windows x86-64

calab-0.2.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (691.9 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

calab-0.2.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (476.1 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

calab-0.2.1-cp312-cp312-macosx_11_0_arm64.whl (451.0 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

calab-0.2.1-cp312-cp312-macosx_10_12_x86_64.whl (612.5 kB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

File details

Details for the file calab-0.2.1.tar.gz.

File metadata

  • Download URL: calab-0.2.1.tar.gz
  • Upload date:
  • Size: 138.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for calab-0.2.1.tar.gz
Algorithm Hash digest
SHA256 7abb12f4c328ffb213f5c436f6b5b38ebcf6808518c535947417b9615099050f
MD5 462300d6b9ad0ebb5fe170f046e4f2d8
BLAKE2b-256 24c402191744409ea588299ad6df2c32afe016253f4143be1e2f9f72c40c1fa6

See more details on using hashes here.

Provenance

The following attestation bundles were made for calab-0.2.1.tar.gz:

Publisher: publish-python.yml on miniscope/CaLab

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file calab-0.2.1-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: calab-0.2.1-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 619.1 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

Hashes for calab-0.2.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 e70b3700943bc3a79d9bb14951baa6dda2c4499d96df37cf21e5004026431728
MD5 48df1b251aa6efec4ea939d679c6bc8e
BLAKE2b-256 c29093f049d208f9a0448fb2d91383eabf9796ff9cba0e32e1fbf8ecbc77a52b

See more details on using hashes here.

Provenance

The following attestation bundles were made for calab-0.2.1-cp312-cp312-win_amd64.whl:

Publisher: publish-python.yml on miniscope/CaLab

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file calab-0.2.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for calab-0.2.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 465dd0b79741b29c0cb80757556386e7a3d9fe047b6ccb0095719a47f4c7831f
MD5 84f95a65723a5d67f5a020686014aef6
BLAKE2b-256 b93f843bfcc682ce0c6626c20a53c164b1d423e23dcbec092892d8f3e6788adb

See more details on using hashes here.

Provenance

The following attestation bundles were made for calab-0.2.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish-python.yml on miniscope/CaLab

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file calab-0.2.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for calab-0.2.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 fff69bec6b55efe53ba3737f269337eac28af845bff6146fc5e81f289af45900
MD5 d7ff69045e6bb95c935240097ad61f12
BLAKE2b-256 1063d400291ea1653fb1800b6398994c3ff4f72bd786c736d89495e10d05b92a

See more details on using hashes here.

Provenance

The following attestation bundles were made for calab-0.2.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: publish-python.yml on miniscope/CaLab

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file calab-0.2.1-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for calab-0.2.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 20e62abcda3c4f93ed42682e2e257cece43c011099a7d6e6e0a228e03c4669a4
MD5 bc50fd5120a355902597b128d6e3802e
BLAKE2b-256 673182a0557c9b200c43d5ce25b35b252d7ad480eafdedcc0a5b93883b734637

See more details on using hashes here.

Provenance

The following attestation bundles were made for calab-0.2.1-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: publish-python.yml on miniscope/CaLab

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file calab-0.2.1-cp312-cp312-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for calab-0.2.1-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 a4cb5fbcbe0c19e843166180b7aa80a6f650fa0d87807b0d763c8980698624e7
MD5 072e9f9fe4a06656dc53481b2856922c
BLAKE2b-256 e2a4a304be908982f0dfe0aa96f3ed695bef5397fa14f6837e69e072ef860abe

See more details on using hashes here.

Provenance

The following attestation bundles were made for calab-0.2.1-cp312-cp312-macosx_10_12_x86_64.whl:

Publisher: publish-python.yml on miniscope/CaLab

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page