A Python package for pupil feature decomposition.
Project description
๐ง pupildecompose
A Python package for physiological pupil-feature decomposition
โจ Overview
pupildecompose is a Python package designed for extracting physiologically meaningful features from pupil responses.
The package provides:
- Automated pupil decomposition
- Physiological feature extraction
- Trial-wise and participant-wise analysis
- Multiple constriction-onset detection methods
- Visualization
- CSV export utilities
The package is suitable for:
- Pupillometry
- Cognitive Neuroscience
- Attention Research
- Eye Tracking
- PLR Analysis
- Cognitive Psychophysiology
- Computational Neuroscience
๐งฉ Extracted Features
The package decomposes pupil traces into the following features:
| Feature | Description |
|---|---|
| ๐น Constriction Onset | Estimated PLR onset time |
| ๐น Pre-PLR Dilation | Early transient dilation before constriction |
| ๐น Constriction Rate | Slope of constriction phase |
| ๐น Constriction Amplitude | Peak constriction magnitude |
| ๐น Constriction Latency | Time to minimum pupil size |
| ๐น Dilation Rate | Recovery slope after constriction |
๐ฆ Installation
Clone Repository
git clone https://github.com/yourusername/pupildecompose.git
cd pupildecompose
Install Package
pip install -e .
๐ Expected DataFrame Structure
The package accepts a pandas DataFrame.
Required Structure
| Column | Content |
|---|---|
| Column 1 | Participant ID |
| Column 2 | Condition (optional) |
| Remaining Columns | Pupil time-series samples |
Example DataFrame
| Participant | Condition | T1 | T2 | T3 | T4 | ... |
|---|---|---|---|---|---|---|
| P1 | Happy | 1.02 | 1.03 | 1.01 | 0.99 | ... |
| P1 | Happy | 1.01 | 1.02 | 1.00 | 0.98 | ... |
| P2 | Neutral | 1.00 | 1.01 | 0.99 | 0.97 | ... |
Notes
- Each row represents one trial.
- Pupil samples must be arranged horizontally.
- Different trial lengths are allowed.
- Shorter trials are automatically padded using
NaN. - Excessive NaNs trigger warnings during decomposition.
โ ๏ธ Data Assumptions
The package assumes users already performed:
- Blink reconstruction
- Basic artifact correction
- Initial preprocessing
- Missing-value handling
Optional smoothing can still be applied within the package.
๐ Quick Example
import pandas as pd
from pupildecompose import run_decompose
# -------------------------------------------------
# Load dataframe
# -------------------------------------------------
df = pd.read_csv(
"pupil_dataset.csv"
)
# -------------------------------------------------
# Run decomposition
# -------------------------------------------------
results = run_decompose(
df,
participant_col=0,
condition_col=1,
pupil_start_col=2,
mode="trial",
preprocess=True,
preprocess_method="gaussian",
sigma=1,
sample_interval_ms=8.33,
baseline_window=(0, 20),
stim_onset_idx=0,
dilation_window_ms=300,
onset_method="wilcoxon",
plot=True,
save_csv=True
)
โ๏ธ Main Parameters
| Parameter | Description |
|---|---|
participant_col |
Participant column index |
condition_col |
Condition column index |
pupil_start_col |
First pupil-data column |
mode |
"trial" or "participant" |
sample_interval_ms |
Sampling interval in milliseconds |
baseline_window |
Baseline indices |
stim_onset_idx |
Stimulus onset index |
dilation_window_ms |
Dilation-rate fitting window |
onset_method |
"wilcoxon" or "slope" |
๐ง Constriction Onset Detection
Two onset-detection methods are currently available.
1๏ธโฃ Wilcoxon Method
Uses:
- Sliding 100 ms windows
- Physiological latency constraints
- Wilcoxon signed-rank testing
Recommended for cleaner datasets.
onset_method="wilcoxon"
2๏ธโฃ Slope Method
Uses:
- Sustained negative slopes
- Local trend consistency
More robust for noisy pupil traces.
onset_method="slope"
๐งช Analysis Modes
๐น Trial Mode
Each trial is decomposed independently.
Useful for:
- Single-trial analysis
- Computational modeling
- Trial-level statistics
mode="trial"
๐น Participant Mode
Trials are averaged within participant and condition before decomposition.
Useful for:
- Participant-level analysis
- ERP-style averaging
- Cleaner PLR estimation
mode="participant"
๐ Optional Preprocessing
Currently supported:
โ Gaussian smoothing
preprocess=True
preprocess_method="gaussian"
๐ Output
The package automatically generates:
- Feature dataframe
- Decomposition summary
- Trial-success report
- CSV output
- Pupil-response plots
- Feature comparison plots
๐ Visualization
The package generates:
Pupil Time Course
- Mean pupil traces
- Confidence intervals
- Multi-condition overlays
Feature Subplots
Separate subplots for:
- Constriction Onset
- Pre-PLR Dilation
- Constriction Rate
- Constriction Amplitude
- Constriction Latency
- Dilation Rate
with:
- SEM bars
- Multi-condition comparisons
๐งช Testing
Run tests using:
pytest -v
The repository includes:
- API tests
- Smoke tests
- Functional pipeline tests
๐ Repository Structure
pupildecompose/
โ
โโโ pupildecompose/
โ โโโ dataframe.py
โ โโโ preprocess.py
โ โโโ features.py
โ โโโ plotting.py
โ โโโ pipeline.py
โ โโโ utils.py
โ
โโโ tests/
โโโ example/
โโโ README.md
โโโ setup.py
โโโ pyproject.toml
๐ง Scientific Applications
The package can be used for:
- Attention Research
- Pupillometry Studies
- Cognitive Load Analysis
- Eye Tracking Experiments
- Computational Neuroscience
๐ Version
v1.0
๐ค Contributions
Bug reports, feature requests, and scientific collaborations are welcome.
๐จโ๐ฌ Author
Sangramjit Maity
โญ If this package helps your research, consider starring the repository and cite the author โญ
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pupildecompose-1.0.tar.gz.
File metadata
- Download URL: pupildecompose-1.0.tar.gz
- Upload date:
- Size: 18.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
39c02b8516d1e8fe9c4e52e83402a315b066125084c871462884d65b07686448
|
|
| MD5 |
78c8f697279b15403fa6ad00c558ad01
|
|
| BLAKE2b-256 |
11e599228916517fe93dc1e92cdacfcf93f238dbb1c7cd5362214a0507f187bf
|
File details
Details for the file pupildecompose-1.0-py3-none-any.whl.
File metadata
- Download URL: pupildecompose-1.0-py3-none-any.whl
- Upload date:
- Size: 16.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cb6000c8f66725e8912f9c1bb316ce2317918a8967a78c05af4e2956d120f5e1
|
|
| MD5 |
b9a1dcaa8f9cef8e99fecc5560142995
|
|
| BLAKE2b-256 |
f371788ade4edb7def7e762072116c2d4865569d5944b01d9d6230c6f2a6a7a4
|