# mouseland/suite2p architecture

> Architecture diagram of the GitHub repository mouseland/suite2p, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mouseland/suite2p
- Repository: https://github.com/mouseland/suite2p

## Overview

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: [`suite2p/pipeline_s2p.py`](https://github.com/mouseland/suite2p/blob/main/suite2p/pipeline_s2p.py) (Pipeline core), [`suite2p/detection`](https://github.com/mouseland/suite2p/tree/main/suite2p/detection) (Detection), [`suite2p/extraction`](https://github.com/mouseland/suite2p/tree/main/suite2p/extraction) (Extraction), [`suite2p/io/save.py`](https://github.com/mouseland/suite2p/blob/main/suite2p/io/save.py) (Save outputs)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_entry["Entry & config"]
  node_n_main(("CLI entry<br/>entrypoint<br/>[__main__.py]"))
  node_n_run(("Python API<br/>entrypoint<br/>[run_s2p.py]"))
  node_n_pipe["Pipeline core<br/>orchestrator<br/>[pipeline_s2p.py]"]
  node_n_params["Parameters<br/>config<br/>[parameters.py]"]
  node_n_ops["Default ops<br/>config<br/>[default_ops.py]"]
end

subgraph group_group_io["Input boundary"]
  node_n_io[("Movie I/O<br/>ingest")]
  node_n_binary[("Binary cache<br/>persistence<br/>[binary.py]")]
  node_n_save[("Save outputs<br/>persistence<br/>[save.py]")]
end

subgraph group_group_pipeline["Analysis pipeline"]
  node_n_reg["Registration<br/>motion correction"]
  node_n_det["Detection"]
  node_n_ext["Extraction"]
  node_n_dcnv(("Deconvolution<br/>spike inference<br/>[dcnv.py]"))
  node_n_cls["Classification<br/>roi classifier"]
  node_n_model["Default model<br/>classifier asset<br/>[classifier.npy]"]
end

subgraph group_group_gui["Interactive review"]
  node_n_gui["GUI shell<br/>review ui<br/>[gui2p.py]"]
  node_n_classgui["Cell review<br/>curation ui<br/>[classgui.py]"]
  node_n_reggui["Reg review<br/>visual review<br/>[reggui.py]"]
end

subgraph group_group_support["Support"]
  node_n_docs["Docs & guides<br/>support"]
end

node_n_main -->|"launches"| node_n_pipe
node_n_run -->|"calls"| node_n_pipe
node_n_params -->|"configures"| node_n_pipe
node_n_ops -->|"defaults"| node_n_params
node_n_pipe -->|"loads movies"| node_n_io
node_n_io -->|"materializes"| node_n_binary
node_n_pipe -->|"registers"| node_n_reg
node_n_reg -->|"writes cache"| node_n_binary
node_n_reg -->|"feeds"| node_n_det
node_n_pipe -->|"detects ROIs"| node_n_det
node_n_det -->|"passes masks"| node_n_ext
node_n_pipe -->|"extracts signals"| node_n_ext
node_n_ext -->|"deconvolves"| node_n_dcnv
node_n_det -->|"scores"| node_n_cls
node_n_model -->|"provides model"| node_n_cls
node_n_pipe -->|"persists"| node_n_save
node_n_ext -->|"writes traces"| node_n_save
node_n_cls -->|"writes labels"| node_n_save
node_n_save -->|"opens results"| node_n_gui
node_n_gui -->|"curates"| node_n_classgui
node_n_gui -->|"inspects"| node_n_reggui
node_n_docs -.->|"documents"| node_n_run
node_n_docs -.->|"documents"| node_n_main

click node_n_main "https://github.com/mouseland/suite2p/blob/main/suite2p/__main__.py"
click node_n_run "https://github.com/mouseland/suite2p/blob/main/suite2p/run_s2p.py"
click node_n_pipe "https://github.com/mouseland/suite2p/blob/main/suite2p/pipeline_s2p.py"
click node_n_params "https://github.com/mouseland/suite2p/blob/main/suite2p/parameters.py"
click node_n_ops "https://github.com/mouseland/suite2p/blob/main/suite2p/default_ops.py"
click node_n_io "https://github.com/mouseland/suite2p/tree/main/suite2p/io"
click node_n_binary "https://github.com/mouseland/suite2p/blob/main/suite2p/io/binary.py"
click node_n_save "https://github.com/mouseland/suite2p/blob/main/suite2p/io/save.py"
click node_n_reg "https://github.com/mouseland/suite2p/tree/main/suite2p/registration"
click node_n_det "https://github.com/mouseland/suite2p/tree/main/suite2p/detection"
click node_n_ext "https://github.com/mouseland/suite2p/tree/main/suite2p/extraction"
click node_n_dcnv "https://github.com/mouseland/suite2p/blob/main/suite2p/extraction/dcnv.py"
click node_n_cls "https://github.com/mouseland/suite2p/tree/main/suite2p/classification"
click node_n_model "https://github.com/mouseland/suite2p/blob/main/suite2p/classifiers/classifier.npy"
click node_n_gui "https://github.com/mouseland/suite2p/blob/main/suite2p/gui/gui2p.py"
click node_n_classgui "https://github.com/mouseland/suite2p/blob/main/suite2p/gui/classgui.py"
click node_n_reggui "https://github.com/mouseland/suite2p/blob/main/suite2p/gui/reggui.py"
click node_n_docs "https://github.com/mouseland/suite2p/tree/main/docs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_n_main,node_n_run,node_n_pipe,node_n_params,node_n_ops toneBlue
class node_n_io,node_n_binary,node_n_save toneAmber
class node_n_reg,node_n_det,node_n_ext,node_n_dcnv,node_n_cls,node_n_model toneMint
class node_n_gui,node_n_classgui,node_n_reggui toneRose
class node_n_docs toneIndigo
```

## Components

### Entry & config

Command-line and API entry points, plus run configuration.

- [CLI entry](https://github.com/mouseland/suite2p/blob/main/suite2p/__main__.py): entrypoint · Package command-line entry for running Suite2p. · `suite2p/__main__.py`
- [Python API](https://github.com/mouseland/suite2p/blob/main/suite2p/run_s2p.py): entrypoint · Main programmatic interface used by scripts and notebooks. · `suite2p/run_s2p.py`
- [Pipeline core](https://github.com/mouseland/suite2p/blob/main/suite2p/pipeline_s2p.py): orchestrator · Coordinates staged analysis, run state, and stage handoff. · `suite2p/pipeline_s2p.py`
- [Parameters](https://github.com/mouseland/suite2p/blob/main/suite2p/parameters.py): config · Analysis options and presets used to build run configuration. · `suite2p/parameters.py`
- [Default ops](https://github.com/mouseland/suite2p/blob/main/suite2p/default_ops.py): config · Default option values for analysis runs. · `suite2p/default_ops.py`

### Input boundary

Movie loading, format normalization, and persisted data I/O.

- [Movie I/O](https://github.com/mouseland/suite2p/tree/main/suite2p/io): ingest · Format-specific loading and normalization for microscopy data. · `suite2p/io`
- [Binary cache](https://github.com/mouseland/suite2p/blob/main/suite2p/io/binary.py): persistence · Registered binary movie storage and memory-mapped access. · `suite2p/io/binary.py`
- [Save outputs](https://github.com/mouseland/suite2p/blob/main/suite2p/io/save.py): persistence · Writes analysis artifacts and run products to disk. · `suite2p/io/save.py`

### Analysis pipeline

Core staged processing from registration through extraction and classification.

- [Registration](https://github.com/mouseland/suite2p/tree/main/suite2p/registration): motion correction · Aligns frames and handles motion correction and alignment utilities. · `suite2p/registration`
- [Detection](https://github.com/mouseland/suite2p/tree/main/suite2p/detection): roi detection · Finds candidate ROIs and computes detection metrics. · `suite2p/detection`
- [Extraction](https://github.com/mouseland/suite2p/tree/main/suite2p/extraction): signal extraction · Builds fluorescence, neuropil, and trace outputs from ROI masks. · `suite2p/extraction`
- [Deconvolution](https://github.com/mouseland/suite2p/blob/main/suite2p/extraction/dcnv.py): spike inference · Converts fluorescence traces into spike estimates. · `suite2p/extraction/dcnv.py`
- [Classification](https://github.com/mouseland/suite2p/tree/main/suite2p/classification): roi classifier · Scores candidate ROIs and produces iscell decisions. · `suite2p/classification`
- [Default model](https://github.com/mouseland/suite2p/blob/main/suite2p/classifiers/classifier.npy): classifier asset · Bundled classifier used by the pipeline and GUI. · `suite2p/classifiers/classifier.npy`

### Interactive review

GUI layers for inspecting, editing, and curating results.

- [GUI shell](https://github.com/mouseland/suite2p/blob/main/suite2p/gui/gui2p.py): review ui · Interactive review application over pipeline outputs. · `suite2p/gui/gui2p.py`
- [Cell review](https://github.com/mouseland/suite2p/blob/main/suite2p/gui/classgui.py): curation ui · Manual cell classification and curation workflow. · `suite2p/gui/classgui.py`
- [Reg review](https://github.com/mouseland/suite2p/blob/main/suite2p/gui/reggui.py): visual review · Registration visualization and inspection tools. · `suite2p/gui/reggui.py`

### Support

Documentation, examples, and validation around the core package.

- [Docs & guides](https://github.com/mouseland/suite2p/tree/main/docs): support · Documentation, notebooks, and paper assets explaining usage and validation. · `docs`

## Connections

- 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.
