# raphaelvallat/yasa architecture

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

- Interactive diagram: https://gitdiagram.com/raphaelvallat/yasa
- Repository: https://github.com/raphaelvallat/yasa

## Overview

YASA is a Python toolbox for analyzing polysomnography and sleep data. A user supplies EEG or other physiological data and calls the relevant public API; capabilities include automatic sleep staging, event and artifact detection, spectral and cardiac analysis, hypnogram manipulation, sleep statistics, visualization, and scorer evaluation. These are primarily independent analysis paths rather than a single orchestrated pipeline. The graph reflects documented capabilities and source-index references; unsampled implementations are not assumed to call one another.

Main entry points: [`src/yasa/__init__.py`](https://github.com/raphaelvallat/yasa/blob/master/src/yasa/__init__.py) (YASA API), [`src/yasa/hypno.py`](https://github.com/raphaelvallat/yasa/blob/master/src/yasa/hypno.py) (Hypnogram Tools), [`src/yasa/detection.py`](https://github.com/raphaelvallat/yasa/blob/master/src/yasa/detection.py) (Event Detection), [`src/yasa/spectral.py`](https://github.com/raphaelvallat/yasa/blob/master/src/yasa/spectral.py) (Spectral Analysis)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Public API"]
  node_api["YASA API<br/>[__init__.py]"]
end

subgraph group_signals["Signal Analysis"]
  node_detection["Event Detection<br/>[detection.py]"]
  node_spectral["Spectral Analysis<br/>[spectral.py]"]
  node_heart["Cardiac Analysis<br/>[heart.py]"]
end

subgraph group_sleep["Sleep Analysis"]
  node_staging["Sleep Staging<br/>[staging.py]"]
  node_hypno["Hypnogram Tools<br/>[hypno.py]"]
  node_sleepstats["Sleep Statistics<br/>[sleepstats.py]"]
  node_evaluation["Scorer Evaluation<br/>[evaluation.py]"]
end

subgraph group_support["Analysis Support"]
  node_validation["Data Validation<br/>[_validation.py]"]
  node_plotting["Visualization<br/>[plotting.py]"]
  node_others["Signal Utilities<br/>[others.py]"]
  node_io["Logging Utilities<br/>[io.py]"]
  node_fetchers["Sample Data Fetching<br/>[fetchers.py]"]
end

node_user(("Analyst"))

node_user -->|"uses"| node_api
node_api -->|"exports"| node_detection
node_api -->|"exports"| node_evaluation
node_api -->|"exports"| node_fetchers
node_api -->|"exports"| node_heart
node_api -->|"exports"| node_hypno
node_api -->|"exports"| node_plotting
node_api -->|"exports"| node_sleepstats
node_api -->|"exports"| node_spectral
node_api -->|"exports"| node_staging
node_detection -->|"validates data"| node_validation
node_detection -->|"uses logging"| node_io
node_detection -->|"uses utilities"| node_others
node_detection -->|"uses spectral tools"| node_spectral
node_spectral -->|"validates data"| node_validation
node_spectral -->|"uses logging"| node_io
node_heart -->|"validates data"| node_validation
node_heart -->|"finds periods"| node_hypno
node_heart -->|"uses logging"| node_io
node_staging -->|"creates hypnograms"| node_hypno
node_staging -->|"uses utilities"| node_others
node_staging -->|"uses spectral tools"| node_spectral
node_sleepstats -->|"analyzes stages"| node_hypno
node_evaluation -->|"uses hypnograms"| node_hypno
node_plotting -->|"plots hypnograms"| node_hypno

click node_api "https://github.com/raphaelvallat/yasa/blob/master/src/yasa/__init__.py"
click node_staging "https://github.com/raphaelvallat/yasa/blob/master/src/yasa/staging.py"
click node_detection "https://github.com/raphaelvallat/yasa/blob/master/src/yasa/detection.py"
click node_spectral "https://github.com/raphaelvallat/yasa/blob/master/src/yasa/spectral.py"
click node_heart "https://github.com/raphaelvallat/yasa/blob/master/src/yasa/heart.py"
click node_validation "https://github.com/raphaelvallat/yasa/blob/master/src/yasa/_validation.py"
click node_hypno "https://github.com/raphaelvallat/yasa/blob/master/src/yasa/hypno.py"
click node_sleepstats "https://github.com/raphaelvallat/yasa/blob/master/src/yasa/sleepstats.py"
click node_evaluation "https://github.com/raphaelvallat/yasa/blob/master/src/yasa/evaluation.py"
click node_plotting "https://github.com/raphaelvallat/yasa/blob/master/src/yasa/plotting.py"
click node_others "https://github.com/raphaelvallat/yasa/blob/master/src/yasa/others.py"
click node_io "https://github.com/raphaelvallat/yasa/blob/master/src/yasa/io.py"
click node_fetchers "https://github.com/raphaelvallat/yasa/blob/master/src/yasa/fetchers.py"

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_api toneBlue
class node_detection,node_spectral,node_heart toneAmber
class node_staging,node_hypno,node_sleepstats,node_evaluation toneMint
class node_validation,node_plotting,node_others,node_io,node_fetchers toneRose
class node_user toneIndigo
```

## Components

### Public API

- [YASA API](https://github.com/raphaelvallat/yasa/blob/master/src/yasa/__init__.py): `src/yasa/__init__.py`

### Signal Analysis

- [Event Detection](https://github.com/raphaelvallat/yasa/blob/master/src/yasa/detection.py): `src/yasa/detection.py`
- [Spectral Analysis](https://github.com/raphaelvallat/yasa/blob/master/src/yasa/spectral.py): `src/yasa/spectral.py`
- [Cardiac Analysis](https://github.com/raphaelvallat/yasa/blob/master/src/yasa/heart.py): `src/yasa/heart.py`

### Sleep Analysis

- [Sleep Staging](https://github.com/raphaelvallat/yasa/blob/master/src/yasa/staging.py): `src/yasa/staging.py`
- [Hypnogram Tools](https://github.com/raphaelvallat/yasa/blob/master/src/yasa/hypno.py): `src/yasa/hypno.py`
- [Sleep Statistics](https://github.com/raphaelvallat/yasa/blob/master/src/yasa/sleepstats.py): `src/yasa/sleepstats.py`
- [Scorer Evaluation](https://github.com/raphaelvallat/yasa/blob/master/src/yasa/evaluation.py): `src/yasa/evaluation.py`

### Analysis Support

- [Data Validation](https://github.com/raphaelvallat/yasa/blob/master/src/yasa/_validation.py): `src/yasa/_validation.py`
- [Visualization](https://github.com/raphaelvallat/yasa/blob/master/src/yasa/plotting.py): `src/yasa/plotting.py`
- [Signal Utilities](https://github.com/raphaelvallat/yasa/blob/master/src/yasa/others.py): `src/yasa/others.py`
- [Logging Utilities](https://github.com/raphaelvallat/yasa/blob/master/src/yasa/io.py): `src/yasa/io.py`
- [Sample Data Fetching](https://github.com/raphaelvallat/yasa/blob/master/src/yasa/fetchers.py): `src/yasa/fetchers.py`

### Other components

- **Analyst**

## Connections

- Analyst → YASA API: uses (evidence: `README.rst`)
- YASA API → Event Detection: exports (evidence: `src/yasa/__init__.py`)
- YASA API → Scorer Evaluation: exports (evidence: `src/yasa/__init__.py`)
- YASA API → Sample Data Fetching: exports (evidence: `src/yasa/__init__.py`)
- YASA API → Cardiac Analysis: exports (evidence: `src/yasa/__init__.py`)
- YASA API → Hypnogram Tools: exports (evidence: `src/yasa/__init__.py`)
- YASA API → Visualization: exports (evidence: `src/yasa/__init__.py`)
- YASA API → Sleep Statistics: exports (evidence: `src/yasa/__init__.py`)
- YASA API → Spectral Analysis: exports (evidence: `src/yasa/__init__.py`)
- YASA API → Sleep Staging: exports (evidence: `src/yasa/__init__.py`)
- Event Detection → Data Validation: validates data (evidence: `src/yasa/detection.py`)
- Event Detection → Logging Utilities: uses logging (evidence: `src/yasa/detection.py`)
- Event Detection → Signal Utilities: uses utilities (evidence: `src/yasa/detection.py`)
- Event Detection → Spectral Analysis: uses spectral tools (evidence: `src/yasa/detection.py`)
- Spectral Analysis → Data Validation: validates data (evidence: `src/yasa/spectral.py`)
- Spectral Analysis → Logging Utilities: uses logging (evidence: `src/yasa/spectral.py`)
- Cardiac Analysis → Data Validation: validates data (evidence: `src/yasa/heart.py`)
- Cardiac Analysis → Hypnogram Tools: finds periods (evidence: `src/yasa/heart.py`)
- Cardiac Analysis → Logging Utilities: uses logging (evidence: `src/yasa/heart.py`)
- Sleep Staging → Hypnogram Tools: creates hypnograms (evidence: `src/yasa/staging.py`)
- Sleep Staging → Signal Utilities: uses utilities (evidence: `src/yasa/staging.py`)
- Sleep Staging → Spectral Analysis: uses spectral tools (evidence: `src/yasa/staging.py`)
- Sleep Statistics → Hypnogram Tools: analyzes stages (evidence: `src/yasa/sleepstats.py`)
- Scorer Evaluation → Hypnogram Tools: uses hypnograms (evidence: `src/yasa/evaluation.py`)
- Visualization → Hypnogram Tools: plots hypnograms (evidence: `src/yasa/plotting.py`)
