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 with dynamic adjustment of the recovery time constant ((\tau)).
- Incorporates Gaussian noise to mimic natural variability in pupil size measurements.
- Validates input data to ensure compatibility and provides clear error messages for invalid inputs.
- Supports multiple input formats: CSV, Excel, JSON, Parquet, and TXT.
- 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_blinksto 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.
Version 1.3.0
- Unified reconstruction method: removed distinctions between short and long blinks.
- Added support for multiple file formats: CSV, Excel, JSON, TXT, and Parquet.
- Incorporated comprehensive input validation to ensure consistent and robust data processing.
- Enhanced the Gaussian noise model for more realistic reconstruction.
- Optimized compatibility with
pandasand modern data workflows.
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
data = pd.read_csv("input.csv")
processed_data = process_pupil(data)
processed_data.to_csv("reconstructed.csv", index=False)
3. Process Data from Other Formats
processed_data = process_pupil("input.parquet")
processed_data.to_excel("reconstructed.xlsx", index=False)
4. Plot the Results
import matplotlib.pyplot as plt
plt.figure(figsize=(14, 7))
plt.plot(processed_data['Trial Time'], processed_data['Pupil Size'], label='Original Pupil Size (with Blinks)', alpha=0.6)
plt.plot(processed_data['Trial Time'], processed_data['Reconstructed Pupil Size'], label='Reconstructed Pupil Size', linestyle='--')
plt.xlabel('Time (ms)', fontsize=14)
plt.ylabel('Pupil Size (AU)', fontsize=14)
plt.title('Original vs Reconstructed Pupil Size', fontsize=16)
plt.legend(fontsize=12)
plt.grid(True)
plt.show()
Input Requirements
The input data must be in one of the following formats: CSV, Excel, JSON, TXT, or Parquet. It should contain 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:
-
blink_threshold: Threshold for detecting blinks. Default is1000. -
tau_base: Base recovery time constant for logarithmic reconstruction. Default is50. -
noise_scale: Scale of Gaussian noise added to reconstructions. Default is0.05.
Example:
processed_data = process_pupil(
"input.json",
blink_threshold=1200,
tau_base=60,
noise_scale=0.1
)
License
This project is licensed under the MIT License.
Contributing
We welcome contributions! To contribute:
- Fork the repository on GitHub.
- Create a new branch for your feature or bugfix.
- Submit a pull request.
Author
- Mohammad Ahsan Khodami
- Email: ahsan.khodami@gmail.com
- GitHub: AhsanKhodami
Example Input and Output
Input:
| Trial | Trial Time | Pupil Size |
|---|---|---|
| 1 | 0 | 4500 |
| 1 | 10 | 0 |
| 1 | 20 | 0 |
| 1 | 30 | 4800 |
Output:
| Trial | Trial Time | Pupil Size | Reconstructed Pupil Size |
|---|---|---|---|
| 1 | 0 | 4500 | 4500 |
| 1 | 10 | 0 | 4600 |
| 1 | 20 | 0 | 4700 |
| 1 | 30 | 4800 | 4800 |
### Key Updates:
1. **Unified Methodology**: Removed references to distinct handling of short and long blinks.
2. **File Format Support**: Added examples and documentation for processing multiple file formats.
3. **Gaussian Noise Model**: Clarified the enhanced noise integration process.
4. **Updated Changelog**: Documented the new features added in version `1.3.0`.
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 prpip-1.3.0.tar.gz.
File metadata
- Download URL: prpip-1.3.0.tar.gz
- Upload date:
- Size: 9.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
edeb852ef5292cb41e486ebd2c33bbddae2d87e7e9ae54ec14239e29ee238c56
|
|
| MD5 |
bcc086f905b5dd6be767c47f4ba4d4ee
|
|
| BLAKE2b-256 |
3acf1e8dc757dac92bd612ced98ad760698001f96bb3e158851a0ace0cea9bf9
|
File details
Details for the file prpip-1.3.0-py3-none-any.whl.
File metadata
- Download URL: prpip-1.3.0-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a218ed4a4a7fca983204f78624b6b6e9f486aa53feee20ffe0a3a91d9abd01b5
|
|
| MD5 |
00def773729ef2aa5107ed3a2ec76972
|
|
| BLAKE2b-256 |
953f231350dda258cce467e5a6f7e30fd63112b1dc9c7f0c1a0764acad0f3f46
|