neuroaihub/brainpilot/calcium-imaging-analysis-guide
Claude Code and agent skill by neuroaihub/brainpilot
- community
Checking that the SKILL.md file is still in the repository.
Domain-validated pipeline guidance for calcium imaging data analysis: motion correction, ROI extraction, neuropil correction, spike inference, and quality control
Install
npx vskill@latest install neuroaihub/brainpilot/calcium-imaging-analysis-guideSKILL.md
The same SKILL.md was published earlier as neuroaihub/brainpilot/calcium-imaging-analysis-guide.
Calcium Imaging Analysis Guide
Purpose
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.
When to Use This Skill
- Designing an analysis pipeline for two-photon, one-photon/miniscope, or fiber photometry data
- Choosing motion correction strategy for awake behaving animal recordings
- Selecting ROI detection method for your preparation density and imaging modality
- Setting deconvolution parameters matched to your calcium indicator
- Evaluating whether extracted signals reflect genuine single-neuron activity
- Troubleshooting common artifacts: photobleaching, neuropil contamination, motion
Research Planning Protocol
Before executing the domain-specific steps below, you MUST:
- State the research question — What neural activity question is this calcium imaging analysis addressing?
- Justify the method choice — Why calcium imaging (not electrophysiology, fMRI, etc.)? What alternatives were considered?
- Declare expected outcomes — What activity patterns would support vs. refute the hypothesis?
- Note assumptions and limitations — What does this method assume? Where could it mislead (e.g., indicator kinetics, neuropil)?
- Present the plan to the user and WAIT for confirmation before proceeding.
For detailed methodology guidance, see the research-literacy skill.
⚠️ Verification Notice
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.
Decision Tree: Which Pipeline for Your Modality
Core Pipeline Steps
Step 1: Motion Correction
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:
- Always use non-rigid registration for awake behaving animals. Brain tissue deforms non-uniformly due to heartbeat, respiration, and locomotion (Dombeck et al., 2007).
- For 1P/miniscope data, apply spatial high-pass filtering before estimating motion vectors, because the large fluctuating background confounds rigid correlation-based registration (Giovannucci et al., 2019).
- Inspect registration quality by computing the correlation of each frame to the reference. Frames with correlation below 0.5 indicate severe motion and should be flagged or excluded (expert consensus).
- Edge pixels that shift out of the FOV during registration should be cropped; ROIs near edges may have unreliable signals.
Step 2: ROI Detection
| 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:
- Set expected cell diameter to match your preparation. Cortical pyramidal somata are ~10-15 um; Purkinje cells are ~25 um; granule cells are ~5 um. Converting to pixels depends on your magnification and pixel size.
- For dense labeling, increase
max_overlapto 0.75-1.0 (Suite2P) or adjust merge thresholds (CaImAn). Default overlap rejection discards valid overlapping neurons. - Set
connected=Falsewhen detecting dendrites or axonal boutons, which are not spatially contiguous in 2D projections. - Always manually curate detected ROIs. Automated classifiers achieve near-human performance (Giovannucci et al., 2019) but are not perfect, especially for non-standard preparations.
Step 3: Neuropil Contamination Correction
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:
| 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:
- The coefficient r = 0.7 is an empirically derived average for 2P cortical imaging. It was estimated by measuring fluorescence in blood vessels (which should have zero true signal) relative to surrounding neuropil (Chen et al., 2013).
- Suite2P estimates r iteratively together with spike deconvolution, minimizing the deconvolution residual. This data-driven approach is preferred over a fixed coefficient.
- For 1P data, neuropil correction is handled differently: CNMF-E models the background as a low-rank spatiotemporal component rather than a per-ROI annulus (Zhou et al., 2018).
- Over-subtraction (r too high) produces negative fluorescence values. If you see many negative dF/F values, reduce r.
- For soma-targeted indicators (e.g., soma-GCaMP6f; Chen et al., 2020), neuropil contamination is reduced but not eliminated.
Step 4: dF/F Computation
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:
Domain judgment:
- The sliding window for rolling percentile should be 30-60 seconds to capture slow baseline fluctuations without tracking fast transients (expert consensus).
- Using the mean as baseline inflates dF/F for highly active neurons. Use a low percentile (8th-10th) or the mode instead (Dombeck et al., 2007).
- Photobleaching causes an exponential decay in baseline fluorescence. If uncorrected, early time points will have artificially low dF/F and late time points artificially high dF/F. Fit and subtract an exponential before computing dF/F (Giovannucci et al., 2019).
Step 5: Deconvolution / Spike Inference
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:
- If tau is wrong, deconvolution is systematically biased. Too long produces sluggish traces; too short produces overshoot artifacts.
- The kernel is fixed to tau in Suite2P; it is not fit to the data. Always verify your indicator and set tau explicitly.
- Do NOT threshold deconvolved events to create binary spike trains. This discards magnitude information: a 1-spike event and a 10-spike burst become identical (Pachitariu et al., 2017).
- Deconvolved amplitudes are in arbitrary units. There is an unknown scaling factor between fluorescence and spike count. Do not interpret amplitudes as absolute firing rates.
- CASCADE (Rupprecht et al., 2021) can produce calibrated spike rate estimates by resampling ground truth data to match your recording's noise level, but still has systematic errors at low SNR.
Step 6: Quality Metrics for ROI Acceptance
| 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:
- SNR varies dramatically with indicator brightness, expression level, and imaging depth. An SNR of 3 is a minimum; SNR > 5 is preferred for reliable spike inference.
- Skewness exploits the biophysics: calcium transients have fast rise and slow decay, producing a positively skewed fluorescence distribution. Gaussian noise has skewness near zero.
- Always examine the spatial footprint. A valid somatic ROI should be roughly circular (10-20 um diameter in cortex). Elongated or multi-lobed footprints often indicate dendrites, overlapping cells, or motion artifacts.
Common Pitfalls
- Wrong tau for your indicator: Using GCaMP6s parameters for GCaMP6f data (or vice versa) produces incorrect deconvolution. Always check which indicator was used.
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingpackages/skills/skills/09_Cellular_Molecular_Neuroscience/calcium-imaging-analysis-guide/SKILL.md
Popularity
- Repository stars
- 884
- Repository forks
- 61
- 7-day trend score
- 34
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/neuroaihub/brainpilot/calcium-imaging-analysis-guide)