How mouseland/suite2p works
1. What this repository is
- suite2p is a Python package for two-photon calcium-imaging analysis.
- The core architecture is a staged pipeline: input movie loading → motion registration → ROI detection → signal extraction / deconvolution → ROI classification → saved outputs and optional GUI review.
2. Primary entry points
- suite2p/__main__.py exposes the command-line entrypoint.
- suite2p/run_s2p.py is the main Python API used by notebooks and scripts.
- suite2p/pipeline_s2p.py is the orchestration layer that connects the major stages and manages run state.
- The README also documents a CLI mode driven by settings.npy and db.npy, which matches the repo’s “configuration + runtime database” pattern.
3. Configuration and runtime state
- suite2p/default_ops.py, suite2p/parameters.py, and the preset files in suite2p/ops/*.npy define the analysis options.
- The pipeline keeps a separation between static options/presets and per-run metadata/state.
- A typical run writes settings.npy and intermediate outputs alongside final results so later stages and the GUI can reload them.
4. Input boundary: file-format abstraction
- The suite2p/io package is the ingestion boundary for many acquisition formats: TIFF, H5, ND2, NWB, SBX, DCAM/raw, and binary/memory-mapped movie handling.
- This layer normalizes heterogeneous microscope data into a movie-like stream the pipeline can process.
- suite2p/io/save.py and suite2p/io/binary.py are especially important because downstream stages consume registered binary data rather than original source files.
5. Registration subsystem
- suite2p/registration handles frame alignment and motion correction.
- It includes rigid and nonrigid correction, bidirectional phase correction, and z-alignment utilities.
- This stage is a major compute boundary: it transforms raw movie frames into stabilized data and typically writes a fast-disk binary cache for subsequent analysis.
6. Detection subsystem
- suite2p/detection is responsible for finding candidate ROIs from the registered data.
- The package is split into algorithmic pieces such as sparse detection, anatomical cues, denoising, second-channel detection support, statistics, and metrics.
- This stage produces spatial ROI definitions and quality metrics that feed extraction and classification.
7. Extraction and deconvolution
- suite2p/extraction turns ROI masks into time-series outputs.
- extract.py and masks.py manage fluorescence and neuropil signal computation, while dcnv.py handles spike deconvolution.
- The main data products here are F.npy, Fneu.npy, and spks.npy, which are the analytical outputs most downstream users care about.
8. ROI classification
- suite2p/classification determines whether candidate ROIs are cells.
- classifier.npy in suite2p/classifiers/ is the bundled default model used by the pipeline and GUI.
- This is a separable machine-learning boundary: detected ROIs are scored into iscell.npy, with a probability-like confidence value used for curation and downstream filtering.
9. Interactive GUI boundary
- suite2p/gui is a full review-and-curation layer over pipeline results.
- It supports visual inspection, mask editing, trace views, merge/swap actions, and manual cell classification.
- The GUI is not the analysis pipeline itself; it is a consumer of pipeline outputs and a writer of curated results back to disk.
10. Persisted outputs and run artifacts
- The standard output set is F.npy, Fneu.npy, spks.npy, stat.npy, iscell.npy, plus settings/intermediate files.
- Results are stored in a suite2p/ folder under the chosen save path, making the data directory the main persistence boundary.
- The pipeline also relies on temporary fast-disk artifacts during registration, which is a performance-oriented separation from long-term storage.
11. Optional external capabilities
- The package is built on numpy, scipy, scikit-learn, and torch; GPU acceleration is relevant for long recordings.
- The GUI uses pyqtgraph with PyQt6/PySide, and optional integrations include Cellpose and Rastermap.
- These dependencies materially shape the architecture because they separate compute-heavy numerical code from interactive visualization and optional model-based segmentation.
12. Quality, reproducibility, and support structure
- tests/regression mirrors the major pipeline stages, which implies the architecture is organized around stable stage outputs and end-to-end reproducibility.
- docs, notebooks, and paper/ are supporting layers for usage, validation, and presentation rather than runtime components.
- The repo structure strongly suggests a modular pipeline with clear boundaries between input decoding, analysis stages, GUI review, and disk-based artifacts.
Main entry points: pipeline_s2p.py Pipeline core · detection Detection · extraction Extraction · save.py Save outputs
Components 18
Entry & config
Command-line and API entry points, plus run configuration.
- CLI entry · Package command-line entry for running Suite2p.
suite2p/__main__.py - Python API · Main programmatic interface used by scripts and notebooks.
suite2p/run_s2p.py - Pipeline core · Coordinates staged analysis, run state, and stage handoff.
suite2p/pipeline_s2p.py - Parameters · Analysis options and presets used to build run configuration.
suite2p/parameters.py - Default ops · Default option values for analysis runs.
suite2p/default_ops.py
Input boundary
Movie loading, format normalization, and persisted data I/O.
- Movie I/O · Format-specific loading and normalization for microscopy data.
suite2p/io - Binary cache · Registered binary movie storage and memory-mapped access.
suite2p/io/binary.py - Save outputs · Writes analysis artifacts and run products to disk.
suite2p/io/save.py
Analysis pipeline
Core staged processing from registration through extraction and classification.
- Registration · Aligns frames and handles motion correction and alignment utilities.
suite2p/registration - Detection · Finds candidate ROIs and computes detection metrics.
suite2p/detection - Extraction · Builds fluorescence, neuropil, and trace outputs from ROI masks.
suite2p/extraction - Deconvolution · Converts fluorescence traces into spike estimates.
suite2p/extraction/dcnv.py - Classification · Scores candidate ROIs and produces iscell decisions.
suite2p/classification - Default model · Bundled classifier used by the pipeline and GUI.
suite2p/classifiers/classifier.npy
Interactive review
GUI layers for inspecting, editing, and curating results.
- GUI shell · Interactive review application over pipeline outputs.
suite2p/gui/gui2p.py - Cell review · Manual cell classification and curation workflow.
suite2p/gui/classgui.py - Reg review · Registration visualization and inspection tools.
suite2p/gui/reggui.py
Support
Documentation, examples, and validation around the core package.
- Docs & guides · Documentation, notebooks, and paper assets explaining usage and validation.
docs
Connections 23
- CLI entry → Pipeline core: launches · CLI hands off execution to the pipeline orchestrator.
- Python API → Pipeline core: calls · Programmatic API delegates to the same staged pipeline.
- Parameters → Pipeline core: configures · Analysis parameters shape the run plan and stage settings.
- Default ops → Parameters: defaults · Default ops seed the parameter set.
- Pipeline core → Movie I/O: loads movies · Pipeline starts from normalized input movie streams.
- Movie I/O → Binary cache: materializes · Input data are written or accessed through binary/memmapped storage.
- Pipeline core → Registration: registers · Motion correction is the first major compute stage.
- Registration → Binary cache: writes cache · Registration typically produces the fast-disk binary cache.
- Registration → Detection: feeds · Stabilized frames become input to ROI detection.
- Pipeline core → Detection: detects ROIs · Detection stage finds candidate spatial masks and metrics.
- Detection → Extraction: passes masks · Detected ROIs are consumed by extraction.
- Pipeline core → Extraction: extracts signals · Extraction computes fluorescence and neuropil traces.
- Extraction → Deconvolution: deconvolves · Extracted traces are converted to spike estimates.
- Detection → Classification: scores · Detected candidates are classified as cell or not-cell.
- Default model → Classification: provides model · Bundled classifier supplies the default scoring model.
- Pipeline core → Save outputs: persists · Outputs and run artifacts are written to the data directory.
- Extraction → Save outputs: writes traces · Extraction outputs are saved as standard result arrays.
- Classification → Save outputs: writes labels · Classification produces iscell results for persistence.
- Save outputs → GUI shell: opens results · GUI consumes saved outputs for review and curation.
- GUI shell → Cell review: curates · Cell classification UI edits labels and merges/splits ROIs.
- GUI shell → Reg review: inspects · Registration UI visualizes alignment and motion correction.
- Docs & guides → Python API: documents · Docs and notebooks explain usage of the Python API and pipeline.
- Docs & guides → CLI entry: documents · Documentation also covers CLI execution and run setup.