科研 Skill

钙成像数据分析

calcium-imaging-analysis

Processes two-photon or widefield calcium imaging with Suite2p or CaImAn, from motion correction through ROI extraction to dF/F and spike deconvolution. Use for calcium imaging movies.

发布者 Codar安全审核通过v0.1.0更新于 2026-11-18

SKILL.md

Calcium imaging analysis

Calcium imaging movies need to be stabilized, segmented into cells (or other regions of interest), and turned into interpretable fluorescence traces before any downstream analysis (tuning curves, place fields, decoding) is meaningful. The pipeline below follows the two dominant open-source tools, Suite2p and CaImAn, and the checks that catch the most common mistakes.

When to use this skill

Use it when the user:

  • has raw two-photon, one-photon miniscope, or widefield calcium movies (TIFF stacks, ScanImage, Bruker/PrairieView, Thorlabs, Inscopix .isxd) and needs cells/ROIs and traces out of them,
  • asks about motion correction, non-rigid registration, or "my movie is jittery / shifted",
  • asks how to pick between Suite2p and CaImAn, or how to tune their parameters,
  • needs dF/F, neuropil-corrected traces, or deconvolved spike estimates,
  • is comparing ROIs or registering cells across sessions or days,
  • asks about photobleaching correction, z-drift, or SNR of a calcium indicator (GCaMP6/7/8, jGCaMP8, RCaMP, jRGECO).

1. Inventory the recording

Before processing, record: indicator (GCaMP6f/6s/7f/7s/8f/8m/8s, jRGECO1a, etc.) and its kinetics (fast indicators need higher frame rates to resolve single spikes), imaging modality (two-photon, one-photon miniscope, widefield), frame rate, field of view and pixel size, number of planes (single-plane vs. volumetric/multi-plane), and the microscope's native file format. Fast indicators (GCaMP8f, jGCaMP8f) decay in ~100-200 ms; slow indicators (GCaMP6s) decay over ~1-2 s and blur closely spaced events together — this matters for how much to trust deconvolved spike timing.

2. Pick a toolkit

ToolBest forInstall
Suite2pTwo-photon, fast, good defaults, built-in GUI curationpip install suite2p
CaImAnOne-photon/miniscope (CNMF-E), online/streaming analysis, more tunablepip install caiman (conda recommended; needs a caimanmanager install step for demos)
EXTRACTDense/overlapping somas, more robust to neuropil contaminationMATLAB-based; use when Suite2p/CaImAn ROI shapes look implausible

Both Suite2p and CaImAn implement motion correction, cell/ROI detection, and trace extraction; the choice usually comes down to imaging modality (CaImAn's CNMF-E is the standard choice for one-photon miniscope data with large out-of-focus background) and whether interactive GUI curation (Suite2p) is wanted.

3. Motion correction

  • Rigid correction first (whole-frame x/y shift) against a reference image built from a clean, low-motion subset of frames.
  • Non-rigid correction (Suite2p's built-in non-rigid registration, or CaImAn's MotionCorrect with pw_rigid=True) when the FOV is large enough that different parts of the tissue move independently (brain warping, especially in awake, behaving animals).
  • For volumetric/multi-plane data, correct each plane independently, then check for z-drift (focus plane drift) separately — x/y registration cannot fix out-of-plane motion.
  • Always inspect the registered movie (or at minimum a mean/max-projection before vs. after, and a line profile over time) before trusting downstream ROI detection. Residual motion after correction propagates directly into spurious "activity".
# Suite2p: minimal end-to-end run
import suite2p

ops = suite2p.default_ops()
ops.update({
    "fs": 30.0,           # imaging frame rate (Hz)
    "nplanes": 1,
    "nchannels": 1,
    "tau": 1.0,           # indicator decay time constant (s); ~1.0 for GCaMP6s, ~0.7 for 6f
    "nonrigid": True,
})
db = {"data_path": ["/path/to/tiffs"], "save_path0": "/path/to/output"}
output_ops = suite2p.run_s2p(ops=ops, db=db)
# CaImAn: CNMF-E for one-photon miniscope data
import caiman as cm
from caiman.source_extraction.cnmf import cnmf, params

fnames = ["/path/to/miniscope_movie.tif"]
opts = params.CNMFParams(params_dict={
    "fnames": fnames,
    "fr": 20,                # frame rate
    "decay_time": 0.4,       # indicator decay (s)
    "pw_rigid": True,        # non-rigid motion correction
    "gSig": (3, 3),          # expected (half-)cell radius in pixels
    "center_psf": True,      # required for CNMF-E (1p data)
    "method_init": "corr_pnr",
})

4. ROI / source extraction

  • Suite2p's detection (based on sparse PCA / clustering of correlated pixels) and CaImAn's CNMF/CNMF-E (a constrained matrix-factorization model that jointly estimates spatial footprints and temporal traces, explicitly separating cells from background/neuropil) both need the expected cell diameter in pixels as a key parameter — get this from the microscope's pixel size and typical soma diameter (~10-20 µm for cortical neurons) rather than a default.
  • Inspect ROI shapes after detection: implausibly large, donut-shaped, or dendrite-shaped "cells" usually indicate the diameter parameter is mis-set or that the movie still has residual motion.
  • Manually curate (Suite2p's GUI, or CaImAn's component_evaluation with SNR/rvalue/CNN thresholds) rather than trusting automatic classification alone, especially near the edges of the field of view.

5. Neuropil correction and dF/F

Raw somatic fluorescence is contaminated by out-of-focus neuropil signal. Standard correction (Suite2p default, and the classic approach, Chen et al. 2013; Kerlin et al. 2010):

F_corrected(t) = F_soma(t) - r * F_neuropil(t)      # r is typically 0.7
dF/F(t) = (F_corrected(t) - F0) / F0

F0 is a slow baseline, commonly the 8th-percentile of F_corrected in a sliding window (e.g. 30-60 s) to track slow drift (bleaching, focus) while not being pulled up by transients. Report the neuropil coefficient r and the baseline window used — both materially change dF/F magnitude and are rarely reported but change results.

6. Deconvolution to spike estimates

Both toolkits ship a deconvolution step (Suite2p: OASIS; CaImAn: OASIS or constrained-foopsi) that estimates a denoised calcium trace and a spike-rate proxy from dF/F, given the indicator's decay time constant.

  • Deconvolved "spikes" are relative spike-rate estimates, not validated spike counts, unless calibrated against simultaneous electrophysiology for that exact indicator/cell-type/frame-rate combination (e.g. the ground-truth datasets from the Allen Institute or Svoboda lab spikefinder benchmarks).
  • Report the indicator decay constant (tau) used, since it strongly affects deconvolution output and is often left at a tool's default rather than set from the actual indicator in use.
  • For slow indicators (GCaMP6s) at typical two-photon frame rates (~5-30 Hz), do not interpret deconvolved output as single-spike-resolved; treat it as a smoothed estimate of firing rate.

7. Cross-session / cross-day registration

When tracking the same cells across sessions or days (chronic imaging through a cranial window), register mean/max-projection images across sessions (e.g. with suite2p's cross-session matching, or CaImAn's register_multisession) before assuming an ROI index means the same cell on different days. FOV rotation, z-drift, and tissue growth/scarring over weeks all degrade naive ROI-index matching.

8. Quality checks before trusting the output

  • SNR per ROI (peak dF/F vs. baseline noise) — drop or flag low-SNR ROIs rather than including them unweighted in population analyses.
  • Fraction of frames flagged as high-motion (from the registration shift trace) — exclude or flag epochs with motion beyond a few pixels.
  • Photobleaching: check whether the baseline F0 trends downward over the session; correct or regress it out before comparing early vs. late trials.
  • Visual spot-check: overlay a sample of accepted ROI contours on the mean/max-projection image. Misshapen or background-only "cells" indicate detection parameters need retuning.

Output

A short processing report: indicator and frame rate, motion-correction method and residual-motion check, detection tool and cell-diameter parameter, number of ROIs before/after curation with the curation criteria, neuropil coefficient and dF/F baseline window, deconvolution tau, and per-ROI SNR distribution.

Prerequisites

  • Python 3.9+ with suite2p and/or caiman installed (CaImAn is best installed via conda due to compiled dependencies); a GPU is not required but speeds up Suite2p registration on large movies.
  • Enough disk/RAM to hold at least one copy of the raw movie plus a registered copy; multi-plane or long sessions can be tens of GB.
  • Known imaging frame rate, pixel size and indicator identity — without these, default parameters (cell diameter, decay tau) are likely wrong.

Limitations

  • This skill covers single-photon and two-photon somatic calcium imaging analysis; it does not cover voltage imaging, fiber photometry (a single-ROI, non-cellular-resolution technique with its own skill needs), or electrophysiology spike sorting (see neuro-spike-sorting-qc and neuropixels-analysis for that).
  • Deconvolved spike estimates are not a substitute for simultaneous electrophysiological validation when precise spike timing or counts are required.
  • Cross-session cell registration is never perfect; always report the fraction of cells successfully matched and treat unmatched ROIs as missing data, not as absent cells.

示例提示词

帮我用Suite2p处理这段双光子钙成像视频,提取细胞ROI和dF/F曲线。

所属插件

神经科学面向神经科学研究:EEG/MEG、fMRI、BIDS、spike sorting、连接组、脑机接口解码评估、神经刺激安全与公开神经数据检索。

安装该插件会一并获得同领域的 45 个 Skill / MCP。

同插件的其他科研 Skill

常见问题

钙成像数据分析能做什么?

Processes two-photon or widefield calcium imaging with Suite2p or CaImAn, from motion correction through ROI extraction to dF/F and spike deconvolution. Use for calcium imaging movies。

如何安装钙成像数据分析?

在科搭 Codar 左侧点击「插件」,在「组件」页签搜索「钙成像数据分析」并安装;在 Claude Code 或 Codex 中可以发送本页的安装提示词,或下载 Skill 包后解压到 ~/.claude/skills 或 ~/.codex/skills。

钙成像数据分析需要哪些权限?

该科研 Skill没有声明额外权限;执行具体操作时仍由 Agent 按自身规则请求确认。

钙成像数据分析经过官方审核吗?

是。SpeedSkills 收录的每个版本都会记录内容摘要与权限声明,当前版本已通过安全审核。