Skip to content

Commit ae8fe0d

Browse files
committed
Merge branch 'master' of github.com:mvdoc/hyperface-data-paper
* 'master' of github.com:mvdoc/hyperface-data-paper: Prepare repository for public release (#1)
2 parents c60a54d + 8224b53 commit ae8fe0d

20 files changed

Lines changed: 106 additions & 2425 deletions

CLAUDE.md

Lines changed: 53 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -1,173 +1,98 @@
11
# CLAUDE.md
22

3-
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
3+
This file provides guidance to Claude Code when working with this repository.
44

55
## Essential Commands
66

77
### Environment Setup
88
```bash
9-
# Create virtual environment and install package
109
uv venv
11-
source .venv/bin/activate # On Windows: .venv\Scripts\activate
12-
uv pip install -e .
13-
14-
# Install development dependencies
15-
uv pip install -e ".[dev]"
16-
17-
# Install documentation dependencies
18-
uv pip install -e ".[docs]"
10+
source .venv/bin/activate
11+
uv sync
1912
```
2013

21-
**Important:** Always activate the virtual environment before running any Python scripts:
14+
Always activate the virtual environment before running scripts:
2215
```bash
2316
source .venv/bin/activate && python scripts/qa/...
2417
```
2518

26-
### Quality Assurance Pipeline
19+
### QA Pipeline
2720

28-
#### tSNR Analysis
2921
```bash
30-
# Generate tSNR plots and HTML reports (volume space)
31-
python scripts/qa/qa-plot-tsnr.py # All subjects
32-
python scripts/qa/qa-plot-tsnr.py --subjects sub-001 # Specific subjects
33-
python scripts/qa/qa-generate-html-reports-tsnr.py # Generate HTML reports
34-
35-
# Example scripts for reference (from Budapest dataset)
36-
python scripts/examples/compute-tsnr-volume.py sub-001
37-
python scripts/examples/compute-tsnr-fsaverage.py sub-001
38-
python scripts/examples/compute-isc-fsaverage.py
39-
python scripts/examples/plot-tsnr-fsaverage.py
40-
python scripts/examples/plot-isc-fsaverage.py
41-
```
22+
# tSNR analysis
23+
python scripts/qa/qa-save-tsnr-volume.py # Compute tSNR maps
24+
python scripts/qa/qa-plot-tsnr.py # Generate plots
25+
python scripts/qa/qa-generate-html-reports-tsnr.py # HTML reports
4226

43-
#### Motion Analysis
44-
```bash
45-
# Generate motion QA plots and HTML reports
46-
python scripts/qa/qa-plot-motion.py # All subjects
47-
python scripts/qa/qa-plot-motion.py --subjects sub-001 # Specific subjects
48-
python scripts/qa/qa-generate-html-reports-motion.py # Generate HTML reports
49-
50-
# Outputs:
51-
# - Motion parameter traces (translation/rotation) per run
52-
# - Framewise displacement (FD) traces per run
53-
# - FD violin plots across runs and subjects
54-
# - Interactive HTML reports with session navigation
55-
# - Files saved to: data/derivatives/qa/motion/
56-
```
27+
# Motion analysis
28+
python scripts/qa/qa-plot-motion.py # Generate plots
29+
python scripts/qa/qa-generate-html-reports-motion.py # HTML reports
5730

58-
### Documentation
59-
```bash
60-
# Build Jupyter Book documentation
61-
jupyter-book build docs/
31+
# ISC analysis
32+
python scripts/qa/qa-save-isc.py # Compute ISC
33+
python scripts/qa/qa-plot-isc.py # Surface plots
6234

63-
# Clean previous builds
64-
jupyter-book clean docs/
35+
# Process specific subjects
36+
python scripts/qa/qa-plot-tsnr.py --subjects sub-sid000005
6537
```
6638

6739
### Code Quality
6840
```bash
69-
# Format code with Black
70-
black src/ scripts/qa/ notebooks/
71-
72-
# Sort imports
73-
isort src/ scripts/qa/
74-
75-
# Type checking
76-
mypy src/
77-
78-
# Linting
79-
flake8 src/ scripts/qa/
41+
ruff check src/ scripts/qa/
42+
ruff format src/ scripts/qa/
8043
```
8144

8245
## Code Architecture
8346

84-
### Package Structure
85-
- **`src/hyperface/`**: Core analysis package with two main modules:
86-
- `utils.py`: fMRI data processing utilities including `compute_tsnr()` and `clean_data()` functions
87-
- `viz.py`: Visualization utilities for creating mosaic plots of brain volumes
88-
89-
### Data Organization (BIDS Compliant)
90-
- **`data/`**: Git submodule containing BIDS-formatted dataset (managed separately with datalad)
91-
- `data/derivatives/fmriprep/`: Preprocessed fMRI data from fMRIprep
92-
- `data/derivatives/freesurfer/`: FreeSurfer structural processing outputs
93-
- **`data/derivatives/qa/`**: All QA metrics and figures generated by this pipeline
94-
95-
### Analysis Pipeline Architecture
96-
The QA pipeline follows a structured workflow:
97-
1. **Data cleaning**: Uses fMRIprep confounds (motion, global signal, aCompCor, framewise displacement) + polynomial regressors
98-
2. **tSNR computation**: Temporal signal-to-noise ratio after confound regression
99-
3. **Motion analysis**: Extract and visualize motion parameters and framewise displacement from fMRIprep confounds
100-
4. **Surface mapping**: Projects volume data to fsaverage cortical surface
101-
5. **Inter-subject correlation**: Leave-one-out analysis for stimulus consistency
102-
6. **Visualization**: Volume mosaics, cortical surface plots, motion traces, and interactive HTML reports
103-
104-
### Script Organization
105-
- **`scripts/qa/`**: Quality assurance pipeline scripts that output to `data/derivatives/qa/`
106-
- **`scripts/stimuli/`**: Stimuli analysis and visualization scripts
107-
- **`scripts/presentation/`**: Stimulus presentation code
108-
- **`scripts/examples/`**: Example scripts from Budapest dataset (for reference)
47+
### Package Structure (`src/hyperface/`)
48+
- `utils.py` - fMRI processing (`compute_tsnr()`, `clean_data()`)
49+
- `viz.py` - Visualization (mosaic plots, surface plots)
50+
- `io.py` - Data loading and BIDS I/O
51+
- `isc.py` - Inter-subject correlation
52+
- `qa/` - QA pipeline (config, BIDS utilities, plotting)
53+
54+
### Data Organization (BIDS)
55+
- `data/derivatives/fmriprep/` - Preprocessed fMRI data
56+
- `data/derivatives/freesurfer/` - FreeSurfer outputs
57+
- `data/derivatives/qa/` - QA outputs (generated)
58+
59+
### Scripts
60+
- `scripts/qa/` - Main QA pipeline scripts
61+
- `scripts/presentation/` - Legacy stimulus presentation (do not modify)
10962

11063
### Writing New Scripts
111-
New scripts should use the centralized configuration system for maintainability:
64+
65+
Use the centralized configuration:
11266

11367
```python
11468
from hyperface.qa import create_qa_argument_parser, get_config
11569

11670
def main():
117-
parser = create_qa_argument_parser(
118-
description="Script description here.",
119-
include_subjects=False, # Set True if processing per-subject
120-
)
71+
parser = create_qa_argument_parser(description="Script description.")
12172
args = parser.parse_args()
122-
123-
# Load configuration (handles --config and --data-dir CLI args)
12473
config = get_config(config_path=args.config, data_dir=args.data_dir)
12574

126-
# Use paths from config instead of hardcoding
127-
input_path = config.paths.stimuli_labels_dir / "behavioral-ratings.tsv"
128-
output_dir = config.paths.stimuli_dir / "figures"
75+
# Use config.paths for all paths
76+
output_dir = config.paths.qa_base_dir / "output"
12977
```
13078

131-
**Available config paths** (see `src/hyperface/qa/config.py`):
132-
- `config.paths.data_dir` - Root BIDS dataset directory
133-
- `config.paths.derivatives_dir` - BIDS derivatives directory
134-
- `config.paths.fmriprep_dir` - fMRIprep output directory
135-
- `config.paths.qa_base_dir` - Base QA output directory
136-
- `config.paths.tsnr_dir`, `motion_dir`, `isc_dir`, `stimuli_dir` - QA subdirectories
137-
- `config.paths.stimuli_labels_dir` - Stimuli labels input directory
79+
Config paths available: `data_dir`, `derivatives_dir`, `fmriprep_dir`, `qa_base_dir`, `tsnr_dir`, `motion_dir`, `isc_dir`, `stimuli_dir`
13880

139-
**Config file**: `src/hyperface/assets/qa_config.yaml` - Add new paths here as needed
81+
## Key Details
14082

141-
### Jupyter Book Integration
142-
- **`docs/`**: Jupyter Book configuration for web documentation
143-
- **`notebooks/`**: Analysis notebooks referenced in the book's table of contents
144-
- Notebooks execute with `execute_notebooks: "off"` to avoid re-execution during builds
145-
146-
## Key Implementation Details
147-
148-
### fMRI Data Processing
149-
The `hyperface.utils.compute_tsnr()` function implements a standardized confound regression approach:
150-
- Removes 6 motion parameters + derivatives, global signal, framewise displacement
151-
- Uses 6 aCompCor components for physiological noise
152-
- Adds polynomial regressors (up to 2nd order) for trend removal
153-
- Computes tSNR as mean/std after cleaning
154-
155-
### Surface Data Handling
156-
Scripts distinguish between volume (T1w space) and surface (fsaverage) processing:
157-
- Volume scripts work with NIfTI files and create mosaic visualizations
158-
- Surface scripts work with GIFTI files and create cortical surface plots using pycortex
159-
- Both output standardized BIDS derivative filenames
83+
### fMRI Processing
84+
`compute_tsnr()` uses confound regression:
85+
- 6 motion parameters + derivatives
86+
- Global signal, framewise displacement
87+
- 6 aCompCor components
88+
- Polynomial regressors (2nd order)
16089

16190
### Path Conventions
162-
All scripts assume BIDS derivatives structure:
163-
- Input paths: `data/derivatives/fmriprep/{subject}/func/`
164-
- Output paths: `data/derivatives/qa/{analysis_type}/`
165-
- Figure outputs: `data/derivatives/qa/{analysis_type}/figures/`
166-
167-
## Data Dependencies
91+
- Inputs: `data/derivatives/fmriprep/{subject}/func/`
92+
- Outputs: `data/derivatives/qa/{analysis_type}/`
93+
- Figures: `data/derivatives/qa/{analysis_type}/figures/`
16894

169-
The repository expects preprocessed fMRI data from fMRIprep with specific naming conventions:
170-
- Volume data: `*_space-T1w_desc-preproc_bold.nii.gz`
171-
- Surface data: `*_space-fsaverage_hemi-{L,R}_bold.func.gii`
95+
### Expected File Naming (BIDS)
96+
- Volume: `*_space-T1w_desc-preproc_bold.nii.gz`
97+
- Surface: `*_space-fsaverage_hemi-{L,R}_bold.func.gii`
17298
- Confounds: `*_desc-confounds_timeseries.tsv`
173-
- Brain masks: `*_space-T1w_desc-brain_mask.nii.gz`

README.md

Lines changed: 53 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,90 @@
1-
# Hyperface fMRI Dataset: Quality Assurance & Analysis
1+
# Hyperface fMRI Dataset
22

3-
This repository contains preprocessing scripts, quality assurance analyses, and data visualization tools for the Hyperface functional MRI dataset. The Hyperface dataset consists of fMRI data collected while participants viewed dynamic facial stimuli.
4-
5-
## Repository Structure
6-
7-
```
8-
hyperface-data-paper/
9-
├── data/ # BIDS dataset (git submodule/datalad)
10-
│ ├── [raw BIDS data] # Raw functional and structural data
11-
│ └── derivatives/ # BIDS derivatives
12-
│ ├── fmriprep/ # fMRIprep preprocessed data
13-
│ ├── freesurfer/ # FreeSurfer outputs
14-
│ └── qa/ # Quality assurance metrics & figures
15-
├── src/hyperface/ # Python analysis package
16-
├── notebooks/ # Jupyter notebooks for QA analyses
17-
├── scripts/ # Processing scripts
18-
├── docs/ # Jupyter Book source
19-
└── pyproject.toml # UV dependency management
20-
```
3+
This repository contains analysis code and quality assurance tools for the Hyperface fMRI dataset. The dataset consists of fMRI data collected while participants viewed dynamic face stimuli in a visual memory task.
214

225
## Installation
236

24-
This project uses [uv](https://github.com/astral-sh/uv) for fast, reliable dependency management.
7+
This project uses [uv](https://github.com/astral-sh/uv) for dependency management.
258

26-
### Prerequisites
27-
- Python 3.8+
28-
- uv (install with: `pip install uv`)
29-
30-
### Setup
319
```bash
3210
# Clone the repository
3311
git clone https://github.com/mvdoc/hyperface-data-paper
3412
cd hyperface-data-paper
3513

36-
# Create virtual environment and install dependencies
14+
# Create virtual environment and install
3715
uv venv
38-
source .venv/bin/activate # On Windows: .venv\Scripts\activate
16+
source .venv/bin/activate
3917
uv sync
4018
```
4119

42-
### Data Setup
43-
The dataset will be managed as a git submodule with datalad:
20+
## Data Access
21+
22+
The dataset is managed with [datalad](https://www.datalad.org/) and follows the [BIDS](https://bids.neuroimaging.io/) standard:
23+
4424
```bash
45-
# Add data submodule (when ready)
46-
git submodule add <datalad-dataset-url> data
25+
# Initialize the data submodule
26+
git submodule update --init
4727
cd data && datalad get .
4828
```
4929

50-
## Quality Assurance Pipeline
30+
## Quality Assurance
31+
32+
The repository includes a comprehensive QA pipeline for assessing data quality.
33+
34+
### Motion Analysis
5135

52-
The QA pipeline includes comprehensive analyses:
36+
```bash
37+
# Generate motion parameter plots
38+
python scripts/qa/qa-plot-motion.py
5339

54-
1. **Motion Assessment**: Head motion parameters during scanning
55-
2. **Temporal SNR**: Signal quality after confound regression
56-
3. **Inter-Subject Correlation**: Stimulus-driven response consistency
57-
4. **Surface Visualization**: Cortical surface mapping with pycortex
58-
5. **Outlier Detection**: Identification of problematic scans
40+
# Generate interactive HTML reports
41+
python scripts/qa/qa-generate-html-reports-motion.py
42+
```
5943

60-
### Running QA Scripts
44+
### Temporal SNR Analysis
6145

62-
Scripts are organized by analysis type:
6346
```bash
64-
# Compute tSNR for volume data
65-
python scripts/quality-assurance/compute-tsnr-volume.py sub-001
47+
# Compute tSNR maps
48+
python scripts/qa/qa-save-tsnr-volume.py
6649

67-
# Compute tSNR for surface data
68-
python scripts/quality-assurance/compute-tsnr-fsaverage.py sub-001
50+
# Generate visualizations
51+
python scripts/qa/qa-plot-tsnr.py
6952

70-
# Compute inter-subject correlation
71-
python scripts/quality-assurance/compute-isc-fsaverage.py
53+
# Generate HTML reports
54+
python scripts/qa/qa-generate-html-reports-tsnr.py
7255
```
7356

74-
All outputs are saved to `data/derivatives/qa/` following BIDS conventions.
57+
### Inter-Subject Correlation
7558

76-
## Documentation Website
59+
```bash
60+
# Compute ISC
61+
python scripts/qa/qa-save-isc.py
7762

78-
This repository generates a Jupyter Book website with QA results:
63+
# Generate surface visualizations
64+
python scripts/qa/qa-plot-isc.py
65+
```
7966

80-
```bash
81-
# Install docs dependencies
82-
uv sync --extra docs
67+
All outputs are saved to `data/derivatives/qa/` following BIDS conventions.
8368

84-
# Build the book
85-
jupyter-book build docs/
69+
## Repository Structure
8670

87-
# Serve locally
88-
jupyter-book build docs/ --builder=html
8971
```
72+
hyperface-data-paper/
73+
├── data/ # BIDS dataset (datalad)
74+
│ └── derivatives/
75+
│ ├── fmriprep/ # Preprocessed fMRI data
76+
│ ├── freesurfer/ # FreeSurfer outputs
77+
│ └── qa/ # QA outputs
78+
├── src/hyperface/ # Python analysis package
79+
└── scripts/qa/ # QA pipeline scripts
80+
```
81+
82+
## Citation
9083

91-
## Key Features
84+
If you use this dataset, please cite:
9285

93-
- **BIDS Compliance**: Follows neuroimaging data standards
94-
- **Modern Dependency Management**: Uses uv for fast, reproducible environments
95-
- **Comprehensive QA**: Motion, tSNR, ISC, outlier detection
96-
- **Web Documentation**: Interactive Jupyter Book with all analyses
97-
- **Surface Visualization**: High-quality cortical surface plots
98-
- **Automated Pipeline**: Scripts for reproducible QA workflow
86+
> [Citation information to be added]
9987
100-
## Contributing
88+
## License
10189

102-
See `TODO.md` for current development tasks and contribution opportunities.
90+
BSD 2-Clause License. See [LICENSE](LICENSE) for details.

0 commit comments

Comments
 (0)