skills/calcium-imaging-analysis-guide/SKILL.md
Domain-validated pipeline guidance for calcium imaging data analysis: motion correction, ROI extraction, neuropil correction, spike inference, and quality control
npx skillsauth add haoxuanlithuai/awesome_cognitive_and_neuroscience_skills calcium-imaging-analysis-guideInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
This skill encodes expert methodological knowledge for analyzing calcium imaging data from fluorescent genetically encoded calcium indicators (GECIs). It covers the domain-specific decisions that a general-purpose programmer or data scientist would get wrong without specialized training in optical neurophysiology: choosing deconvolution parameters based on indicator kinetics, correcting neuropil contamination, handling modality-specific preprocessing, and interpreting fluorescence signals as neural activity.
Before executing the domain-specific steps below, you MUST:
For detailed methodology guidance, see the research-literacy skill.
This skill was generated by AI from academic literature. All parameters, thresholds, and citations require independent verification before use in research. If you find errors, please open an issue.
What is your imaging modality?
|
+-- Two-photon (2P) microscopy
| |
| +-- Sparse labeling (Cre-dependent, cell-type specific)?
| | --> Suite2P or CaImAn with standard CNMF
| | Neuropil coefficient ~0.7 (Chen et al., 2013)
| |
| +-- Dense labeling (pan-neuronal)?
| --> Suite2P with increased max_overlap (>=0.75)
| or CaImAn CNMF with careful merge parameters
| Consider soma-targeted indicators (Chen et al., 2020)
|
+-- One-photon (1P) / miniscope
| |
| --> CNMF-E (Zhou et al., 2018) or MIN1PIPE (Lu et al., 2018)
| Standard CNMF will FAIL: 1P has large structured background
| that requires explicit background modeling
| CaImAn supports 1P via CNMF-E mode
|
+-- Fiber photometry (population-level)
|
--> No single-cell extraction needed
Use isosbestic channel (405-415 nm) for motion/bleaching correction
IRLS regression preferred over OLS (Lerner et al., 2015)
Compute dF/F or z-scored signal
Motion correction must precede all other analysis. Uncorrected motion creates false transients and blurs cellular signals.
| Parameter | Rigid | Non-Rigid | Source | |-----------|-------|-----------|--------| | Use case | Anesthetized or head-fixed, stable | Awake behaving, brain pulsation | Pnevmatikakis & Giovannucci, 2017 | | Max shift | 10% of FOV (default) | 10% of FOV per patch | Suite2P default | | Reference frame | Iterative: top 20 of 300 random frames | Same, per-patch | Pachitariu et al., 2017 |
Domain judgment:
| Method | Best For | Tool | Source | |--------|----------|------|--------| | CNMF / sparse NMF | 2P, moderate density | CaImAn | Pnevmatikakis et al., 2016 | | Clustering + PCA | 2P, large FOV | Suite2P | Pachitariu et al., 2017 | | CNMF-E | 1P / miniscope | CaImAn (1P mode) | Zhou et al., 2018 | | Cellpose (anatomical) | Weak functional signal, good morphology | Suite2P + Cellpose | Stringer et al., 2021 | | PCA/ICA | Legacy, not recommended for dense data | Various | Mukamel et al., 2009 |
Domain judgment:
max_overlap to 0.75-1.0 (Suite2P) or adjust merge thresholds (CaImAn). Default overlap rejection discards valid overlapping neurons.connected=False when detecting dendrites or axonal boutons, which are not spatially contiguous in 2D projections.Why this matters: In 2P imaging, each ROI's fluorescence contains signal from the surrounding neuropil (dense mesh of dendrites and axons). Without correction, you will observe artificial correlations between neurons, inflated response amplitudes, and obscured cell-specific tuning (Chen et al., 2013).
Correction formula:
F_corrected = F_raw - r * F_neuropil
| Parameter | Typical Value | Source | |-----------|---------------|--------| | Neuropil coefficient (r) | 0.7 (range: 0.5-0.8) | Chen et al., 2013 | | Neuropil annulus inner gap | 2 pixels from ROI border | Suite2P default | | Minimum neuropil pixels | 350 | Suite2P default |
Domain judgment:
Baseline estimation methods:
| Method | Description | Best For | Source | |--------|-------------|----------|--------| | Rolling percentile (8th) | 8th percentile over sliding window | Continuous recordings, moderate activity | Dombeck et al., 2007 | | Rolling percentile (10th-20th) | Higher percentile over sliding window | Lower activity preparations | Expert consensus | | Exponential fit | Fit decaying exponential to session | Strong photobleaching | Giovannucci et al., 2019 | | Mode of distribution | Histogram mode of fluorescence | Stable baseline, high frame rate | Peron et al., 2015 |
Formula:
dF/F = (F(t) - F0) / F0
Domain judgment:
Deconvolution estimates the underlying spike train from the slow calcium fluorescence signal.
| Algorithm | Type | Speed | Strengths | Source | |-----------|------|-------|-----------|--------| | OASIS | Model-based (AR) | Very fast (1 us/frame) | Online, warm-startable, scalable | Friedrich et al., 2017 | | FOOPSI | Model-based (L1) | Fast | Sparse, non-negative | Vogelstein et al., 2010 | | CASCADE | Deep learning | Moderate | Noise-adaptive, calibrated rates | Rupprecht et al., 2021 | | MLSpike | Bayesian | Slow | Principled uncertainty | Deneux et al., 2016 |
Critical: The deconvolution kernel decay constant (tau) must match your calcium indicator. See references/indicator-parameters.md for the full table.
| Indicator | tau (decay time) for deconvolution | Source | |-----------|------------------------------------|--------| | GCaMP6s | ~1.0-1.5 s | Chen et al., 2013 | | GCaMP6f | ~0.4 s | Chen et al., 2013 | | jGCaMP7f | ~0.3 s | Dana et al., 2019 | | jGCaMP8f | ~0.2 s | Zhang et al., 2023 | | jGCaMP8m | ~0.14 s | Zhang et al., 2023 | | jGCaMP8s | ~0.2 s | Zhang et al., 2023 |
Domain judgment:
| Metric | Criterion | Rationale | Source | |--------|-----------|-----------|--------| | SNR (peak transient / noise SD) | > 3 | Below this, transients are indistinguishable from noise | Giovannucci et al., 2019 | | Skewness of dF/F trace | > 0.5 | Real calcium transients produce right-skewed distributions; noise is symmetric | Suite2P classifier | | Spatial footprint compactness | Compact, soma-shaped | Diffuse or fragmented footprints indicate neuropil or artifacts | Giovannucci et al., 2019 | | Spatial-temporal CNN score | > 0.5 (CaImAn) | Learned classifier combining shape and activity | Giovannucci et al., 2019 |
Domain judgment:
Wrong tau for your indicator: Using GCaMP6s parameters for GCaMP6f data (or vice versa) produces incorrect deconvolution. Always check which indicator was used.
Skipping neuropil correction: Without subtracting r * F_neuropil, apparent correlations between nearby neurons will be inflated by shared neuropil signal. This is the most common error in published calcium imaging analyses.
Using standard CNMF for 1P data: One-photon microscopy has large, spatially structured background fluorescence from out-of-focus tissue. Standard CNMF assumes a sparse background and will fail. Use CNMF-E or MIN1PIPE.
Ignoring photobleaching: GECIs photobleach over minutes to hours. Uncorrected bleaching creates a downward trend that biases dF/F computation and can mask late-session activity.
Motion artifacts in awake animals: Residual motion after correction creates false transients synchronized across neurons (they all move together). Check for correlated artifacts by examining the relationship between motion metrics and neural activity.
Indicator saturation at high firing rates: GECIs have a limited dynamic range. At high firing rates (> 10-20 Hz for GCaMP6s, > 50 Hz for GCaMP8f), the fluorescence signal saturates and underestimates true activity (Chen et al., 2013). Faster indicators saturate at higher rates.
Over-aggressive neuropil subtraction: Setting r too high produces negative fluorescence, especially with bright indicators. Negative dF/F values that exceed noise levels indicate over-subtraction.
Interpreting deconvolved amplitudes as spike counts: The mapping from fluorescence to spike number is nonlinear and depends on indicator expression level, baseline calcium, and imaging conditions. Treat deconvolved traces as relative activity measures.
Based on community standards (Giovannucci et al., 2019; Pachitariu et al., 2017):
See references/pipeline-details.md for tool comparisons and references/indicator-parameters.md for indicator kinetics tables.
tools
Convert a GitHub repository or local codebase into a well-structured Claude Code skill with progressive disclosure. Use this skill whenever the user provides a GitHub URL or local repo path and asks to turn it into a skill, create a skill from a repo, or convert a library/tool/framework into reusable skill documentation. Also trigger when users say things like 'make a skill from this repo', 'turn this codebase into a skill', or 'I want a skill for [library name]'.
development
Domain-validated guidance for cortical surface visualization and brain surface rendering of fMRI data using pycortex: data types (Volume, Vertex, Dataset), 2D cortical flatmaps, 3D WebGL brain viewers, volume-to-surface mapping, FreeSurfer/fMRIPrep integration, ROI management, and surface analysis. Use this skill whenever the user mentions pycortex, `import cortex`, cortical surfaces, brain flatmaps, WebGL brain viewers, cortical surface mapping, or wants to visualize neuroimaging data on the cortex, even if they don't explicitly name pycortex.
development
Domain-validated pipeline guidance for EEG/MEG data analysis using MNE-Python: data loading, preprocessing (filtering, ICA, re-referencing), epoching, ERP/ERF computation, time-frequency decomposition, source localization, decoding/MVPA, statistical testing, simulation, and visualization. Use this skill whenever the user works with EEG/MEG/sEEG/ECoG/NIRS/eye-tracking data in Python, mentions MNE, or needs neurophysiological analysis guidance.
development
Step-by-step guidance for contributing a new skill to the NeuroAIHub/awesome_cognitive_and_neuroscience_skills repository via GitHub Pull Request, including SKILL.md format requirements, quality rules, and PR checklist