Skip to main content

A package for reconstructing pupil size and handling eye-tracker blinks.

Project description

prpip

Reconstruct pupil size during blinks in eye-tracking data with a physiologically inspired approach.

Features

  • Automatically detects blink intervals in eye-tracking data.
  • Reconstructs pupil size during blinks using:
    • Logarithmic recovery for long blinks (>50 ms).
    • Linear blending for short blinks (<50 ms).
    • Adds stochastic variability to mimic natural pupil fluctuations.
  • Processes individual trials or entire datasets.
  • Flexible output:
    • Add a new column for reconstructed data.
    • Replace the original pupil size column with reconstructed values.

Changelog

See the Changes in versions

Version 0.0.post1

  • Initial release of prpip.
  • Implemented logarithmic recovery for long blinks and linear blending for short blinks.
  • Added stochastic variability to mimic natural pupil fluctuations.
  • Supported batch processing of datasets and individual trials.

Version 1.1.0dev1 - Pre-Release

  • Enhanced noise scaling for long-blink reconstructions.
  • Added advanced parameter customization (tau, noise_scale).
  • Improved boundary smoothing for blink transitions.

Version 1.2.1

  • Introduced additional output format options.
  • Optimized performance for large datasets.

Version 1.2.3

  • Added a check in detect_blinks to print a message when no blinks are detected in the trial data.
  • Improved handling of floating-point time indices during pupil reconstruction, ensuring compatibility with non-integer time formats.
  • Fixed minor bugs related to batch processing of trials.
  • Improved error messages for invalid inputs, making debugging easier for users.

Installation

Install the latest version of prpip from PyPI:

pip install prpip

Quick Start

1. Import the Package

from prpip import process_pupil

2. Process an Entire Dataset

import pandas as pd

# Load the dataset
data = pd.read_csv("input.csv")

# Process all trials in the dataset
processed_data = process_pupil(data)

# Save the processed data
processed_data.to_csv("reconstructed.csv", index=False)

3. Process a Specific Trial

# Process only Trial 88
processed_trial = process_pupil(data, trial=88)

# Save the reconstructed trial
processed_trial.to_csv("trial_88_reconstructed.csv", index=False)

4. Plot the Results

import matplotlib.pyplot as plt

plt.figure(figsize=(14, 7))
plt.plot(processed_trial['Timestamp'], processed_trial['Pupil Size'], label='Original Pupil Size', alpha=0.7)
plt.plot(processed_trial['Timestamp'], processed_trial['Reconstructed Pupil Size'], label='Reconstructed Pupil Size', linestyle='--')
plt.xlabel('Timestamp', fontsize=14)
plt.ylabel('Pupil Size', fontsize=14)
plt.title('Original vs Reconstructed Pupil Size (Trial 88)', fontsize=16)
plt.legend(fontsize=12)
plt.grid(True)
plt.show()

Input Requirements

The input data must be a Pandas DataFrame or CSV file with the following columns:

  • Trial: Identifies the trial number.
  • Pupil Size: The measured pupil size.

Output

The output DataFrame includes a new column:

  • Reconstructed Pupil Size: Contains the reconstructed values during blinks.

Alternatively, you can replace the original Pupil Size column with the reconstructed values.


Advanced Parameters

You can customize reconstruction behavior by adjusting the following optional parameters:

  • trial: Specify a trial number to process. If None, all trials are processed.

  • blink_threshold: Threshold for detecting blinks. Default is 0 (blinks occur when Pupil Size is 0).

  • tau: Recovery time constant for logarithmic reconstruction. Default is 50.

  • noise_scale: Scale of Gaussian noise added to long-blink reconstructions. Default is 0.05.

Example:

processed_data = process_pupil(
    data,
    trial=88,
    blink_threshold=0,
    tau=60,
    noise_scale=0.1
)

License

This project is licensed under the MIT License.


Contributing

We welcome contributions! To contribute:

  1. Fork the repository on GitHub.
  2. Create a new branch for your feature or bugfix.
  3. Submit a pull request.

Author


Example Input and Output

Input:

Trial Timestamp Pupil Size
1 0 4500
1 10 0
1 20 0
1 30 4800

Output:

Trial Timestamp Pupil Size Reconstructed Pupil Size
1 0 4500 4500
1 10 0 4600
1 20 0 4700
1 30 4800 4800

Project details


Download files

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

Source Distribution

prpip-1.2.3.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

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

prpip-1.2.3-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file prpip-1.2.3.tar.gz.

File metadata

  • Download URL: prpip-1.2.3.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for prpip-1.2.3.tar.gz
Algorithm Hash digest
SHA256 fec30cf40753bbfe63c903efafd786b11a1ff493926f07084b50b1ab78ea0e44
MD5 dc96d0a7e66c3586ed430cb8e8d7bb9a
BLAKE2b-256 5644e1c52e6915b92050f71952fbb1744461dfbff57968c3dac90420ac22ee4b

See more details on using hashes here.

File details

Details for the file prpip-1.2.3-py3-none-any.whl.

File metadata

  • Download URL: prpip-1.2.3-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for prpip-1.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 cefbaec49888f563a5bee94fe8c6ea29c2b2f58c014208d0bf9ca20bb362826e
MD5 465e8cf4d753b28c3c983ac004fd8d43
BLAKE2b-256 7138834ebde0a3ee192b2f42f79aba7809c056bbd76eeebeaf3c139cf587e1fd

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