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.2.tar.gz (236.3 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.2-cp312-cp312-win_amd64.whl (654.1 kB view details)

Uploaded CPython 3.12Windows x86-64

calab-0.2.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (724.5 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

calab-0.2.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (504.5 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

calab-0.2.2-cp312-cp312-macosx_11_0_arm64.whl (478.8 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

calab-0.2.2-cp312-cp312-macosx_10_12_x86_64.whl (644.1 kB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: calab-0.2.2.tar.gz
  • Upload date:
  • Size: 236.3 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.2.tar.gz
Algorithm Hash digest
SHA256 4b9b2660e6980fa196b84aab9ee5445ab3d10a558a59925cd46eb0bf1147e929
MD5 fd4947951f4fe8b7734a9c94a97dc75d
BLAKE2b-256 57ab99619d529c078ad1b3fcc440a3007411ae7beeff9a1ed2819ebb197305fa

See more details on using hashes here.

Provenance

The following attestation bundles were made for calab-0.2.2.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.2-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: calab-0.2.2-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 654.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.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 8c328a6b5c05f045c5a238303903b1c0164962e69f54d6df73bc4f14a9a24d08
MD5 5d7afa964a92c4a049d1ee622d0f9ba5
BLAKE2b-256 b27166c9b306d8ea14832bac6172d6e9eb94ee6f3a1c4140d0203fe1f84bfb92

See more details on using hashes here.

Provenance

The following attestation bundles were made for calab-0.2.2-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.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for calab-0.2.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ce17214ce90c812963eaa9943c7b9cf96ade6c6acd835a525b37ecd9da2376c6
MD5 99b4f2c3f72832366c41ab8a1b1dac57
BLAKE2b-256 7e13beaee3f10c91afb183d5dc2e5014fd714a0154d14951f95eb3b271ca5a33

See more details on using hashes here.

Provenance

The following attestation bundles were made for calab-0.2.2-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.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for calab-0.2.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 602b9dab76b99d9bf8dff16277b294291b0e98860933714789e43317cbe0d166
MD5 e417248e62bc40be3e3d132e974f7c07
BLAKE2b-256 5dc70ef49c2d841ea39c0f3d130ec2d2bc0089b9f735abae45597b34966dea2e

See more details on using hashes here.

Provenance

The following attestation bundles were made for calab-0.2.2-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.2-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for calab-0.2.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3c73870fce7add3940c415a367137ea58dbeba15666b21ccfbaeaa7ae97fd9e9
MD5 8217e9c177ac80a941116ff5b4ec8329
BLAKE2b-256 2e392e4a9dd9fad490257cc3bcbc8c832970917ff52f6917b25f22106d212982

See more details on using hashes here.

Provenance

The following attestation bundles were made for calab-0.2.2-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.2-cp312-cp312-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for calab-0.2.2-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 b9543785ae7a30237ce0570db53c9d755240e17ef366bb57677e1e3bc671b7a8
MD5 5452070733bdb12d690946be3cbbe75b
BLAKE2b-256 23542355cfd4dbfb9df81335d9d1bb0c6763bc6a02d1a2541c1463045970e876

See more details on using hashes here.

Provenance

The following attestation bundles were made for calab-0.2.2-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