Skip to main content

A Python package for pupil feature decomposition.

Project description

๐Ÿง  pupildecompose

Python Status Scientific Platform

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

This version

1.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pupildecompose-1.0.tar.gz (18.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pupildecompose-1.0-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

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

Hashes for pupildecompose-1.0.tar.gz
Algorithm Hash digest
SHA256 39c02b8516d1e8fe9c4e52e83402a315b066125084c871462884d65b07686448
MD5 78c8f697279b15403fa6ad00c558ad01
BLAKE2b-256 11e599228916517fe93dc1e92cdacfcf93f238dbb1c7cd5362214a0507f187bf

See more details on using hashes here.

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

Hashes for pupildecompose-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cb6000c8f66725e8912f9c1bb316ce2317918a8967a78c05af4e2956d120f5e1
MD5 b9a1dcaa8f9cef8e99fecc5560142995
BLAKE2b-256 f371788ade4edb7def7e762072116c2d4865569d5944b01d9d6230c6f2a6a7a4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page